offparkway
Active member
I'm using the code that JFranco posted for health and lives. It runs great, and I wanted to add the code to warp to a game over screen. I added the warp code, but now I get an error when compiling on line 21 (BEQ +skiphurt) saying it's out of range. What did I miss?
Code:
;;;;;;;;;;;;;;;;;; Presumes there is a variable called myLives defined in user variables.
;;;;;;;;;;;;;;;;;; You could also create your own variable for this.
LDA gameHandler
AND #%10000000
BEQ +canHurtPlayer
JMP +skipHurt
+canHurtPlayer:
PlaySound #sfx_damage
;;;;;;;;;;;;;;;;;;;;;
;;;; Player takes health damage - custom code
;;;;;;;;;;;;;;;;;;;;;
LDX player1_object ; load player1 object into x
TXA ; transfer x to accumulator
STA temp ; store accumulator value into 'temp' variable
GetActionStep temp ; run GetActionStep macro, 'temp' contains player1 object (aka "what is player 1's current Action state?")
CMP #$07 ; are we in ActionState #7 (aka: 'Hurt' mode). My hurt ActionState might be different than yours. adjust accordingly.
BEQ +skipHurt ; yes? then exit this script
ChangeActionStep temp, #$07 ; no? then change action state to 'hurt'
LDA #$70 ; I'm not sure why this is important -- i think it's the amount of time to stay hurt?
STA Object_action_timer,x ; stay hurt for this amount of time
DEC playerHealth ;decrease player health by one
UpdateHudElement #$07 ;update HUD -- myHealth is assigned to HUD element 7 in my game. it may be different in yours. adjust accordingly
LDA playerHealth ;load player health into accumulator
BEQ +loseLife ;if player health equals zero, lose a life
JMP +skipHurt ;else, exit this script
+loseLife:
;;;;;;;;;;;;;;;;;;;;;
;;;;; End of custom code
;;;;;;;;;;;;;;;;;;;;;
Dec myLives
LDA myLives
BNE myLivesNotZero
;;JMP RESET ;; game over.
;;;; also could warp to game over screen here instead.
WarpToScreen #$00, #GAME_OVER_SCREEN, #$01
;;arg0 = warp to map. 0-map1. 1=map2.
;;arg1 = screen to warp to.
;;arg2 = screen transition type - usually use 1 here as 1=warp
JMP +skipHurt
myLivesNotZero:
;;;;;;;;;;;;;;;;;;;;;;;;;
;;; When Player begins new life, refresh health back to 9 - custom code
;;;;;;;;;;;;;;;;;;;;;;;;;
LDA #$09 ;load '9' into accumulator
STA playerHealth ;update playerHealth to 9
UpdateHudElement #$07 ;update HUD -- myHealth is assigned to HUD element 7 in my game. it may be different in yours. adjust accordingly
;;;;;;;;;;;;;;;;;;;;;;;;;
;;; End of custom code
;;;;;;;;;;;;;;;;;;;;;;;;;