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

Post Reply
User avatar
dale_coop
Posts: 3491
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: 316
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.
Post Reply