TolerantX
Active member
(4.5.9) Extra Lives Tiles, Game Over and Continues! (oh my!)
Maybe you want a tile that gives an extra life in a game using a lives system, maybe you want a way to continue the game after running out of lives, or maybe you just want the game to warp to a specific screen when you have no lives left. If any of these might be in your game, then you've come to the right place!
Introducing: Extra Life Tiles!
Step 1: Your "myLives" variable is represented in the HUD (*In this script, it will be HUD Element #1*)
(see picture on step #2)
Step 2: Your "myLives" variable is a max value 1 in your HUD. (lives will be 0-9 or you may use a var tile (the max is 8)
The Tile Script:
(also available: https://drive.google.com/file/d/1-nDS5FA00Oo_MlNYFTQrzNZX2HgE_UxW/view?usp=sharing )
I understand that tile could have been a standalone script download, but wanted to make sure it's used properly because the next steps have similar "elements" (I know, it's a bad pun.)
The Game Over System with Continues!
First, ask yourself what you want it to do when you are hurt... do you get stunned and/or lose health or do you die automatically?
In Arcade Platformer Module (I used as a basis on which this system was made, though this is "compatible" with other modules.) you touch an enemy and you lose a life and go to previous checkpoint and when you lose all lives it resets the game.
What if you want the player to, when hurt lose a life (or if adventure module, myHealth)?
Code example would be: DEC myLives (or in adventure module DEC myHealth)
Keep in mind when using Adventure Script or any script that has: GetActionStep temp / CMP #$07 defined already. (example below is a no-no)
In the example above, you would want ideally the CMP to be for #$06 or something other than #$07 because in the Game Over system Action Step 7 is player Death Animation.
In Adventure Module script for hurtPlayer you may see something like "playerHealthIsZero"
The entry for that is where it tells the game to do things when you die (aka game over, because it has 1 life by default).
You there would want to comment out that portion below it before +skipHurt (don't ever mess with the skipHurt)
using PlayerHurtHealth.asm as a base to make this script:
(also available: https://drive.google.com/file/d/1WY8sgAGjeLGp9rqrYqB7b3LW6Ejge8EK/view?usp=sharing )
END OF PART 1...
Maybe you want a tile that gives an extra life in a game using a lives system, maybe you want a way to continue the game after running out of lives, or maybe you just want the game to warp to a specific screen when you have no lives left. If any of these might be in your game, then you've come to the right place!
Introducing: Extra Life Tiles!
Step 1: Your "myLives" variable is represented in the HUD (*In this script, it will be HUD Element #1*)
(see picture on step #2)
Step 2: Your "myLives" variable is a max value 1 in your HUD. (lives will be 0-9 or you may use a var tile (the max is 8)
The Tile Script:
Code:
;;; Extra_Life tile
CPX player1_object ;; checks for player collision, so weapons and monsters, etc don't trigger this tile ;;
BEQ +isPlayer ;; if it's the player object, go to +isPlayer, if not go to next line. ;;
JMP +notPlayer ;; jump to subroutine label +notPlayer ;;
+isPlayer ;; This is what happens if it is a player object collision. ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; BELOW WILL CHANGE TILE AT COLLISION. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ChangeTileAtCollision #$00, #$00 ;; this macro changes the tile to null collision, tile changes to look like location 00. ;;
LDA myLives ;; loads the variable myLives into the accumulator. ;;
CMP #$09 ;; max of 9 for single digit lives. if var_tile in HUD use up to #$08. This depends on what your var_tiles are. ;;
BNE +increaseLives ;; if not 9 lives then increaseLives. if var_tile in HUD use up to #$08. This depends on what your var_tiles are. ;;
JMP +notPlayer ;; instead of picking up the extra life, it will just ignore you ;;
+increaseLives:
INC myLives ;; increase lives by 1 ;;
UpdateHudElement #$01 ;; update the Hud element associated with myLives, which is "Element 1" currently ;;
; PlaySound #sfx_LivesPickup ;;uncomment for sfx to be activated on pickup ;;
JMP +notPlayer
+notPlayer
(also available: https://drive.google.com/file/d/1-nDS5FA00Oo_MlNYFTQrzNZX2HgE_UxW/view?usp=sharing )
I understand that tile could have been a standalone script download, but wanted to make sure it's used properly because the next steps have similar "elements" (I know, it's a bad pun.)
The Game Over System with Continues!
First, ask yourself what you want it to do when you are hurt... do you get stunned and/or lose health or do you die automatically?
In Arcade Platformer Module (I used as a basis on which this system was made, though this is "compatible" with other modules.) you touch an enemy and you lose a life and go to previous checkpoint and when you lose all lives it resets the game.
What if you want the player to, when hurt lose a life (or if adventure module, myHealth)?
Code example would be: DEC myLives (or in adventure module DEC myHealth)
Keep in mind when using Adventure Script or any script that has: GetActionStep temp / CMP #$07 defined already. (example below is a no-no)
In the example above, you would want ideally the CMP to be for #$06 or something other than #$07 because in the Game Over system Action Step 7 is player Death Animation.
In Adventure Module script for hurtPlayer you may see something like "playerHealthIsZero"
The entry for that is where it tells the game to do things when you die (aka game over, because it has 1 life by default).
You there would want to comment out that portion below it before +skipHurt (don't ever mess with the skipHurt)
using PlayerHurtHealth.asm as a base to make this script:
Code:
;; untested by me currently ;;
LDA gameHandler
AND #%10000000
BEQ +canHurtPlayer
JMP +skipHurt
+canHurtPlayer:
TXA
STA temp
GetActionStep temp
CMP #$06 ;; this cannot be #$07 if you use stunned/hurt action step;;
BNE +canHurtPlayer
JMP +skipHurt
+canHurtPlayer
;;; will presume there is a variable myHealth
;;; and that player hurt state is action state 7.
GetActionStep player1_object
CMP #$06 ;; hurt state. ;; this cannot be #$07 if you use stunned/hurt action step;;
BEQ +notAlreadyInHurtState
DEC myHealth
BMI +healthBelowZero
BEQ +healthBelowZero
JMP +notDeadYet
+healthBelowZero
JMP +playerHealthIsZero
+notDeadYet
UpdateHudElement #$02
ChangeActionStep player1_object, #$06 ;; stun / hurt step, not your death step ;;
;; recoil
LDA #$00
STA Object_h_speed_hi,x
STA Object_h_speed_lo,x
STA Object_v_speed_hi,x
STA Object_v_speed_lo,x
LDA xPrev
STA Object_x_hi,x
LDA yPrev
STA Object_y_hi,x
+notAlreadyInHurtState
LDA Object_x_hi,x
CLC
ADC self_center_x
STA tempA
LDA Object_y_hi,x
CLC
ADC self_center_y
STA tempB
TXA
PHA
LDX otherObject
LDA Object_x_hi,x
CLC
ADC other_center_x
STA tempC
LDA Object_y_hi,x
CLC
ADC other_center_y
STA tempD
PLA
TAX
;;; RECOIL
;;; find the center.
LDA tempA
SEC
SBC tempC
bpl +gotAbs ;; if positive, this is abs value
EOR #$FF
CLC
ADC #$01
+gotAbs
STA temp
LDA tempB
SEC
SBC tempD
bpl +gotAbs
EOR #$FF
CLC
ADC #$01
+gotAbs
;;; now abs of y is in A
CMP temp
BCC +recoilHor
;; recoil vert
LDA tempB
CMP tempD
BCS +recoilDown
LDA Object_direction,x
AND #%00001111
ORA #%00100000
STA Object_direction,x
JMP +skipHurt
+recoilDown
LDA Object_direction,x
AND #%00001111
ORA #%00110000
STA Object_direction,x
JMP +skipHurt
+recoilHor
LDA tempA
CMP tempC
BCS +recoilRight
LDA Object_direction,x
AND #%00001111
ORA #%10000000
STA Object_direction,x
JMP +skipHurt
+recoilRight
LDA Object_direction,x
AND #%00001111
ORA #%11000000
STA Object_direction,x
JMP +skipHurt
JMP +skipHurt
+playerHealthIsZero:
ChangeActionStep player1_object, #$07 ;; set the player action in step 7 to "gotoContinue" ;;
LDA #$00
STA Object_h_speed_hi,x
STA Object_h_speed_lo,x
STA Object_v_speed_hi,x
STA Object_v_speed_lo,x
;LDA continueMap
;STA warpMap
;LDA continueScreen
;STA currentNametable
;LDX player1_object
;STA Object_screen,x
;LDA #$02 ;; this is continue type warp.
;STA screenTransitionType ;; is of warp type
;LDA gameHandler
;ORA #%10000000
;STA gameHandler ;; this will set the next game loop to update the screen.
;LDA myMaxHealth
;STA myHealth
+skipHurt
(also available: https://drive.google.com/file/d/1WY8sgAGjeLGp9rqrYqB7b3LW6Ejge8EK/view?usp=sharing )
END OF PART 1...
Last edited: