Collecting x amount of keys leads to win?

anomoly40

New member
How would i be able to modify the code in the 4.0.6 when the player finds 8 keys it jumps to the win screen? I know it's probably simple but I'm stumped.
 

dale_coop

Moderator
Staff member
You could try something llike that:
Code:
;;; key powerup code

	LDA myKeys
	CLC
	ADC #$01
	CMP #$08  ;;<<-- the limit (when the player gets the 8th he wins)
	BCS playerWinGame
	STA myKeys

	
;;;;;;;;;;;;; UPDATE HUD

		LDA #$01 ;; amount of score places?
		STA hudElementTilesToLoad
		LDA DrawHudBytes
		ORA #HUD_myKeys
		STA DrawHudBytes
		
;;; trigger screen so it enteres triggered mode
;; and you can't continue to get the key again
	
	TriggerScreen screenType
	
	JMP continueWithKeys

playerWinGame:
	LDA #STATE_WIN_GAME
	STA change_state
	LDA #$01
	STA newScreen
	
continueWithKeys:
	PlaySound #SFX_GET_KEY

Sorry I can't test the script, I am not at home, now.
 

dale_coop

Moderator
Staff member
With a small modification, it should work also for 4.1.X versions:
Code:
;;; key powerup code

	LDA myKeys
	CLC
	ADC #$01
	CMP #$08  ;;<<-- the limit (when the player gets the 8th he wins)
	BCS playerWinGame
	STA myKeys

	
;;;;;;;;;;;;; UPDATE HUD

		LDA #$01 ;; amount of score places?
		STA hudElementTilesToLoad
		UpdateHud HUD_myKeys
		
;;; trigger screen so it enteres triggered mode
;; and you can't continue to get the key again
	
	TriggerScreen screenType
	
	JMP continueWithKeys

playerWinGame:
	LDA #STATE_WIN_GAME
	STA change_state
	LDA #$01
	STA newScreen
	
continueWithKeys:
	PlaySound #SND_GET
 

dale_coop

Moderator
Staff member
100 will be be different, if you actually display this variable in your HUD (because myKeys will be split into "myKeys", "myKeys+1" and "myKeys+2" memory addresses... for the 3 numbers)
 

jcramer

New member
So if i did 99 it would take up one extra HUD variable? Do I put the same code in the other variable with both set to 08
 

dale_coop

Moderator
Staff member
No the code is kinda different...
If you display your myKeys hud variable as a number 2 digits in your HUD...
I can adapt the script. No problem
;)
 

dale_coop

Moderator
Staff member
It should be something like that:
Code:
;;; key powerup code

	LDA myKeys+1
	CMP #$09
	BCC +
	LDA myKeys
	CMP #$09
	BCC +
	JMP playerWinGame
+

		 AddValue #$02, myKeys, #$01, #$00
	
;;;;;;;;;;;;; UPDATE HUD


		LDA #$01 ;; amount of score places?
		STA hudElementTilesToLoad
		UpdateHud HUD_myKeys
		
;;; trigger screen so it enteres triggered mode
;; and you can't continue to get the key again
	
	TriggerScreen screenType
	
	JMP continueWithKeys

playerWinGame:
	LDA #STATE_WIN_GAME
	STA change_state
	LDA #$01
	STA newScreen
	
continueWithKeys:
	PlaySound #SND_GET
 
Top Bottom