A Selection Menu on the Start Screen [4.1.X Basic module]

User avatar
dale_coop
Posts: 3954
Joined: Fri Feb 16, 2018 7:05 am
Location: France

A Selection Menu on the Start Screen [4.1.X Basic module]

Post by dale_coop » Wed May 15, 2019 10:41 pm

I will share here how I made a small selection menu, on the Start Screen.
For this demo, I will just make a "NORMAL" or "HARD" selection mode. Use a sprite to display the selection. This menu will allow you to start the game with 3 lives (normal mode) or 1 life only (hard mode).

Image

When you'll understand how it works, you can add your own thing (add more health, start on different screens, ... etc).


How to do...

0/ Prepare your Start Screen, drawing some choices to select.

Image
Here, I wrote two items for my selection menu: "NORMAL" and "HARD".

1/ In "Project Settings > User Variables", we will add new ones used for the selection script:
"curSelection" with an initial value of "0" (this variable will be the value of the selection:"0" for the first item selected, "1" if the second item is selected, ...)

2/ In "Project Settings > User Constants", we will add new ones used for the selection script:
"STARTSCREEN_CURSOR_TILE" with a value of "127" (in fact, the tile index --from your gameObjectTiles-- you want to use as the selector).
"SELECTION_POS_X"with a value of "98" (for the horizontal position of the first item, in pixels)
"SELECTION_POS_Y" with a value of "150" (for the vertical position of the first item, in pixels)
"SELECTION_STEP_X" with a value of "0" (the horizontal distance between items, in pixels)
"SELECTION_STEP_Y" with a value of "16" (the vertical distance between items, in pixels)
"SELECTION_MAX_VALUE" with a value of "1" (the max value for the "curSelection" variable. Starting from "0" if only one item/choice... if "1" it means you want to have 2 items on your screen. "2" means you want to have 3 items, ...).

As you can guess here, you would have to adapt some of those constants values to your start screen layout (positions and maybe distance between items) or maybe the number of items you want.


3/ Now, modify the "PreDraw" script (assigned to the "Handle Sprite Pre-Draw" element in the "Project Settings > Script Settings"), around line 51 (after all the sprite 0 drawing), add those lines:

Code: Select all

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
checkStartScreenSelector:
	LDA update_screen_details
	BNE endCheckingStartScreenSelector 
	;; is special screen:
	LDA newScreen
	CMP #$01
	BEQ endCheckingStartScreenSelector
	;; is START SCREEN:

	;; positions selection: 
	LDA #SELECTION_POS_Y  	;; coord Y position when selection mode is 0
	STA temp1
	LDA #SELECTION_POS_X
	STA temp2  				;; coord X position of all selections

	LDX #$00
startScreenSelectorLoop:
	CPX curSelection
	BCS +
	LDA temp1
	CLC
	ADC #SELECTION_STEP_Y
	STA temp1
	LDA temp2
	CLC
	ADC #SELECTION_STEP_X
	STA temp2
	INX
	JMP startScreenSelectorLoop
+
	DrawSprite temp2, temp1, #STARTSCREEN_CURSOR_TILE, #%00000000, #$00	
	UpdateSpritePointer
	;JMP endCheckingStartScreenSelector
	
endCheckingStartScreenSelector:
This script will draw the selector sprite on the start screen.


4/ Make a new script "SelectionStartScreen.asm" in your "GameEngineData\Routines\Basic\ModuleScripts\InputScripts" folder, with this code:

Code: Select all

checkSelection:
	TXA
	STA tempx
	LDA gamepad
	AND #%00110100
	BNE continueCheckingSelection
	JMP endCheckingSelection

continueCheckingSelection:
	LDA gamepad
	AND #%00010000
	BNE selectionUp
	LDA gamepad
	AND #%00100000
	BNE selectionDown
	LDA gamepad
	AND #%00000100
	BNE selectionSelect
	JMP endCheckingSelection

selectionUp:
	LDA curSelection
	BNE + 
	LDA #SELECTION_MAX_VALUE	;; <-- the max value of curSelection
	STA curSelection
	JMP ++
	+
	DEC curSelection
	++
	JMP endCheckingSelection
	
selectionDown:
	LDA curSelection
	CMP #SELECTION_MAX_VALUE	;; <-- the max value of curSelection
	BNE + 
	LDA #$00
	STA curSelection
	JMP ++
	+
	INC curSelection
	++
	JMP endCheckingSelection
	
selectionSelect:
	JMP selectionDown

endCheckingSelection:
	LDX tempx
	RTS
This script will change the value of the "curSelection" variable, when you press a button (but need to assign it, to inputs, first).


5/ Add the "SelectionStartMenu.asm" script in your project, under "Scripts >Input Scripts". And assign the script to a press button, for the Start Screen:

Image
I'd suggest "PRESS" on the SELECT button.


6/ Lastly, modify the "StartGame.asm" script (located in your "GameEngineData\Routines\Basic\ModuleScripts\InputScripts" folder), at the beginning (1st line), adding this code:

Code: Select all

	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;; SELECTION  MODE : 
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;; curSelection is 0 (normal) or curSelection is 1 (hard):
	LDA curSelection
	CMP #$01
	BNE +
	;; Start in HARD mode:
	LDA #$01
	STA myLives
	JMP ++
	+
	;; ELSE:
	;; Start in NORMAL mode :
	;LDA #$03		;; commented out, here, in order to use the value specified in the NESMaker tool itself
	;STA myLives	;; commented out, here, in order to use the value specified in the NESMaker tool itself
	++
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Here if curSelection value is "1" (it means the second item was selected) then I modify the lives value to "1" before the game starts. Else it will remains to "3" (I commented out those lines to keep the values set by default by the NESmaker tool).
Don't forget to assign the GameStart script to your press start button, if not already did.

Voilà, this should work as shown in the gif.



Notes: if you want to add more choices... just modify the constant "SELECTION_MAX_VALUE" and modify the "StartGame.asm" to do more actions depending of the value of the curSelection variable.
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
User avatar
Bucket Mouse
Posts: 323
Joined: Wed Mar 07, 2018 2:25 am

Re: A Selection Menu on the Start Screen [4.1.X Basic module]

Post by Bucket Mouse » Fri May 17, 2019 8:09 am

Fantastic! Thanks.
User avatar
crazygrouptrio
Posts: 53
Joined: Fri Jan 11, 2019 2:22 pm
Location: United States
Contact:

Re: A Selection Menu on the Start Screen [4.1.X Basic module]

Post by crazygrouptrio » Thu Jun 13, 2019 2:18 pm

Is there way to make it so that Normal and Hard would start on different screens?
User avatar
dale_coop
Posts: 3954
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: A Selection Menu on the Start Screen [4.1.X Basic module]

Post by dale_coop » Thu Jun 13, 2019 2:33 pm

Yes I think it could be doable...
Modifying the "StartGame.asm" script (this script is "what I do when I start my game" after having press on the START button... so as I modified it already, it checks the value of the "curSelection" variable to do different things), so in HARD mode you could also maybe force a JUMP to a specific screen (instead of letting the game start to the overworld defined "starting screen").
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
User avatar
dale_coop
Posts: 3954
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: A Selection Menu on the Start Screen [4.1.X Basic module]

Post by dale_coop » Thu Jun 13, 2019 2:56 pm

For example, in the "StartGame.asm" script, just before the "JMP ++" line, add this portion of code to WARP to a specific screen instead of the normal starting screen:

Code: Select all

    ;; WARP to the HARD_START_LEVEL screen (in overworld) 
    LDA #$00
    STA newGameState
    STA change_state

    GoToScreen #HARD_START_LEVEL, #$01, #$02

    JSR DeactivateAllObjects  
    LDA #$01
    STA loadObjectFlag    
    ;; from here the rest of the code:
    
    JMP ++
Add a new user constant named "HARD_START_LEVEL" with the screen index you want to start for your hard mode.
(Note: don't forget to set the Warp in X,Y coords in your screen.)
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
User avatar
crazygrouptrio
Posts: 53
Joined: Fri Jan 11, 2019 2:22 pm
Location: United States
Contact:

Re: A Selection Menu on the Start Screen [4.1.X Basic module]

Post by crazygrouptrio » Thu Jun 13, 2019 9:49 pm

Super awesome as always, thank you! :D
User avatar
crazygrouptrio
Posts: 53
Joined: Fri Jan 11, 2019 2:22 pm
Location: United States
Contact:

Re: A Selection Menu on the Start Screen [4.1.X Basic module]

Post by crazygrouptrio » Fri Jun 14, 2019 3:29 pm

dale_coop wrote:
Thu Jun 13, 2019 2:56 pm
For example, in the "StartGame.asm" script, just before the "JMP ++" line, add this portion of code to WARP to a specific screen instead of the normal starting screen:

Code: Select all

    ;; WARP to the HARD_START_LEVEL screen (in overworld) 
    LDA #$00
    STA newGameState
    STA change_state

    GoToScreen #HARD_START_LEVEL, #$01, #$02

    JSR DeactivateAllObjects  
    LDA #$01
    STA loadObjectFlag    
    ;; from here the rest of the code:
    
    JMP ++
Add a new user constant named "HARD_START_LEVEL" with the screen index you want to start for your hard mode.
(Note: don't forget to set the Warp in X,Y coords in your screen.)
I got a chance to try this and it didn't work... Selecting hard mode doesn't warp to the other screen, and it makes a second player object. :?
User avatar
dale_coop
Posts: 3954
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: A Selection Menu on the Start Screen [4.1.X Basic module]

Post by dale_coop » Fri Jun 14, 2019 3:50 pm

A second player...? cool ;)
Could you share your StartGame script. I will try to fix that.

And, btw, which module are you using?
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
User avatar
crazygrouptrio
Posts: 53
Joined: Fri Jan 11, 2019 2:22 pm
Location: United States
Contact:

Re: A Selection Menu on the Start Screen [4.1.X Basic module]

Post by crazygrouptrio » Fri Jun 14, 2019 4:40 pm

Sure, haven't done anything with the start script except add in your code. Using the Simple Platformer Module.

Code: Select all

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; SELECTION  MODE : 
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; curSelection is 0 (normal) or curSelection is 1 (hard):
    LDA curSelection
    CMP #$01
    BNE +
    ;; Start in HARD mode:
    ;LDA #$01
    ;STA myLives
        ;; WARP to the HARD_START_LEVEL screen (in overworld) 
    LDA #$00
    STA newGameState
    STA change_state

    GoToScreen #HARD_START_LEVEL, #$01, #$02

    JSR DeactivateAllObjects  
    LDA #$01
    STA loadObjectFlag    
    ;; from here the rest of the code:
    
    JMP ++
    +
    ;; ELSE:
    ;; Start in NORMAL mode :
    ;LDA #$03       ;; commented out, here, in order to use the value specified in the NESMaker tool itself
    ;STA myLives    ;; commented out, here, in order to use the value specified in the NESMaker tool itself
    ++
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LDA #STATE_START_GAME
  STA change_state
  
  ;StopSound
  ;PlaySound #$00, $00

  LDA #%10000000
  STA gameHandler ;; turn sprites on
  RTS
User avatar
dale_coop
Posts: 3954
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: A Selection Menu on the Start Screen [4.1.X Basic module]

Post by dale_coop » Fri Jun 14, 2019 6:55 pm

Ok, I see... try this one:

Code: Select all

  LDA #STATE_START_GAME
  STA change_state

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; SELECTION  MODE : 
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; curSelection is 0 (normal) or curSelection is 1 (hard):
    LDA curSelection
    CMP #$01
    BNE +
    ;; Start in HARD mode:
    ;LDA #$01
    ;STA myLives
        ;; WARP to the HARD_START_LEVEL screen (in overworld) 
    LDA #$00
    STA newGameState
    STA change_state

    GoToScreen #HARD_START_LEVEL, #$01, #$02

    JSR DeactivateAllObjects  
    LDA #$01
    STA loadObjectFlag    
    ;; from here the rest of the code:
    
    JMP ++
    +
    ;; ELSE:
    ;; Start in NORMAL mode :
    ;LDA #$03       ;; commented out, here, in order to use the value specified in the NESMaker tool itself
    ;STA myLives    ;; commented out, here, in order to use the value specified in the NESMaker tool itself
    ++
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
  ;StopSound
  ;PlaySound #$00, $00

  LDA #%10000000
  STA gameHandler ;; turn sprites on
  RTS
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
Post Reply