[4.5.9] Player's Death Animation, Checkpoints and Game Over screen (metroVania module)

offparkway

Active member
Can you share that script?
was already grabbing it for you!
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;SWAP PLAYER
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

canSwitchPlayer:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LDA haveDill ;;did you unlock Dill?
BNE +
  RTS
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TXA
PHA
;; first, we will store every placement informations about the player

LDX player1_object
LDA Object_x_hi,x ;; the current horizontal position
    ; CLC
    ; ADC #$04
STA tempA
LDA Object_y_hi,x ;; the current vertical position
    ; CLC
    ; ADC #$04
STA tempB
     LDA Object_direction,x ;; the current facing and movements
    ; AND #%00000111
     STA tempC

;; now, depending of the current object used by the player:
;; we can switch to the new object, or switch back the normal one

LDA Object_type,x
BNE changeIntoNormal
    LDA #15 ;; <-- HERE ! the new player object to transform into - DILL
    STA tempPlayer
        LDA #$03 ;; Frisbee
        STA currentWeapon
        WEAPON_SPRITE_0 = #$75
    JMP continueChangePlayerInto
changeIntoNormal:
    LDA #00 ;; the normal player object - JIM
    STA tempPlayer
        LDA #$01 ;; Rock
        STA currentWeapon
        WEAPON_SPRITE_0 = #$75
continueChangePlayerInto:

DestroyObject ;; we destroy the current object
CreateObject tempA, tempB, tempPlayer, #$00 ;; and create the new one


TXA
STA player1_object ;; store that new created object in the Player 1 var
STA camObject
    ; LDA tempC ;; set back the player directions
    ; STA Object_direction,x
PLA
TAX


doneSwitchingPlayer2:   
    RTS
 

dale_coop

Moderator
Staff member
I haven’t tested it but the script looks correct 👍

What happens if you use that character switch script before touching the checkpoint tile…?
Does the checkpoint work ?
 

AntwonVinnie

New member
Hey Dale, great tutorial! Was wondering if you knew anything about this issue I’m having with the check point tiles and game over screen. I’m working in Metroidvania 4.5.9 and the instant my player collides with a checkpoint tile, it turns that space into a tile from my background tile sheets. The checkpoint works as normal gladly but it’s just a visual glitch. I was also wondering why my character isn’t warping to game over after losing all their lives. It just restarts at the beginning of the game, which is also a good sign, so I must just be missing something small. Your tutorial helped me learn a bit more about assembly language so thanks for that. Looking forward to hearing back and thanks for all the help. I’ll provide pics and code if you need more info
 

dale_coop

Moderator
Staff member
@AntwonVinnie About the checkpoint tile, modify the checkpoint tile script, around the end you should see:
Code:
ChangeTileAtCollision #$00, #$00
Remove or comment out that line (adding ";" at the begining of the line)
Now your checkpoint tile should not be replaced by a background tile.

For your restart game when you die... maybe it's your Handle Player Death tha tis incorrect.
Are you diying from a collision with a monster or with a hurt/death tile ?
 

AntwonVinnie

New member
@AntwonVinnie About the checkpoint tile, modify the checkpoint tile script, around the end you should see:
Code:
ChangeTileAtCollision #$00, #$00
Remove or comment out that line (adding ";" at the begining of the line)
Now your checkpoint tile should not be replaced by a background tile.

For your restart game when you die... maybe it's your Handle Player Death tha tis incorrect.
Are you diying from a collision with a monster or with a hurt/death tile ?
Ok that checkpoint fix makes sense to me! I’ll try it out and let you know. And with the restart, I’m currently testing it with hurt tiles. I set up a couple monsters but haven’t tested them yet but I’ll do that too. Is there any code I should send your way?
 

AntwonVinnie

New member
Ok cool so I got the check point tiles to work, very easy and I see how the code works for that now. So I put a monster on my start screen and the death animation works perfectly, and after losing 3 lives I get sent to game over screen. No problem, but the problem is if my player hits a hurt tile (ex: spikes, drop) It never sends me to the game over screen, even if I lose all 3 lives. (Also, no death animation plays after hitting hurt tile, hmmm) Where can I modify handle player death?
 

AntwonVinnie

New member
@AntwonVinnie Oh sure. I see.. Can you share your hurt tile script ?
here is the script

;;; Simple Reset
;; check to see if object colliding is a player.
;; if not, do not reset.
CPX player1_object
BNE dontDoTileReset
LDA Object_direction,x
AND #%00001111
STA Object_direction,x

Dec myLives
LDA myLives
BNE +myLivesNotZero
JMP RESET ;; game over.
;;;; also could warp to game over screen here instead.
+myLivesNotZero:

LDA continueMap
STA warpMap

LDA continueX
STA newX
LDA continueY
STA newY

LDA continueScreen
STA warpToScreen
STA camScreen


ok! I see the JMP RESET with the comment about the game over screen, but not knowing what to write in ASM language is keeping me from making those tiles go to the game over screen. so not sure what to write.
 

dale_coop

Moderator
Staff member
here is the script

Try to replace all the code with that one:
Code:
;;; Simple Death Tile
;; check to see if object colliding is a player.
CPX player1_object
BEQ +canHurtPlayer
    ;; make it solid for the other objects:
    LDA ObjectUpdateByte
    ORA #%00000001
    STA ObjectUpdateByte ;; makes solid 
    JMP +endScript
+canHurtPlayer:
    LDA gameState
    CMP #$FF
    BNE +continue
        JMP +endScript
    +continue:
    ;; 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
    LDA Object_direction,x
    AND #%00001111
    STA Object_direction,x
    ;; player is dead, we play the death state:
    ChangeActionStep player1_object, #$06
    
    ;; stop the scrolling :
    LDA scrollByte
    AND #%00111110
    ORA #%00000010
    STA scrollByte
    ;; and disables the inputs:
    LDA #$FF
    STA gameState
+endScript:
RTS
 

AntwonVinnie

New member
Try to replace all the code with that one:
Code:
;;; Simple Death Tile
;; check to see if object colliding is a player.
CPX player1_object
BEQ +canHurtPlayer
    ;; make it solid for the other objects:
    LDA ObjectUpdateByte
    ORA #%00000001
    STA ObjectUpdateByte ;; makes solid
    JMP +endScript
+canHurtPlayer:
    LDA gameState
    CMP #$FF
    BNE +continue
        JMP +endScript
    +continue:
    ;; 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
    LDA Object_direction,x
    AND #%00001111
    STA Object_direction,x
    ;; player is dead, we play the death state:
    ChangeActionStep player1_object, #$06
   
    ;; stop the scrolling :
    LDA scrollByte
    AND #%00111110
    ORA #%00000010
    STA scrollByte
    ;; and disables the inputs:
    LDA #$FF
    STA gameState
+endScript:
RTS
AWESOME! That did the trick :) death animation plays and 3 lives lost goes to game over! many thanks!!!
 

mileco

New member
4) GAME OVER SCREEN

In your Overworld, create a screen that will be your Game Over.
For example here, I chose the last screen of my Overworld (Y:15, X:15):
View attachment 7463

And I design a very simple "GAME OVER" with tiles, and I don't forget to set a Game State that will be specific to my game over screen (a special screen):

View attachment 7464
(I set a different game state, because all the input scripts are assigned per game state, and don't want any inputs for that sceeen, except a RESET when I will press the Start button maybe)

In the screen Info, I set the "Hide sprites", "Hide HUD" and also the "Edge for scroll" flags (I don't want scrolling or see any sprites or hud on my Game Over screen). And I also set the "Warp in Screen Location (X,Y)" coords:

View attachment 7465
(I choose anywhere around the center of the screen).

And I place SOLID collisions all around the screen, to avoid my (invisible) Player object to escape from that screen.

View attachment 7466



5) NO MORE LIVES WARP TO GAME OVER

The last step will be to modify the "GoToContinue" to take in consideration the lives.
Edit the "EndTimerScripts.asm" script that is located in your "GameEngineData\Routines\BASE_4_5\Game\Subroutines\" folder.

View attachment 7467

In the "EndTimerScripts.asm", search for the "goToContinue_action:" section (around line 160).
Between that line and the "RTS" line 181 (before the ";;; 10 = Restart Screen"), replace with that piece of code:
Code:
    ;; if no more lives, warp to GAME OVER:
    LDA myLives
    BEQ +notMoreLives
        DEC myLives
        BEQ +notMoreLives
        BMI +notMoreLives
            ;; player still have lives, warp to last checkpoint:
            LDA continueMap
            STA warpToMap
         
            LDA continueScreen
            STA warpToScreen
            LDA #$02
            STA screenTransitionType
            JMP +doWarpToContinue
    +notMoreLives:
            ;; no more lives:
            LDA #$00              ;; 00: Overworld, 01: Underworld
            STA warpToMap

            LDA #$FF              ;; screen Y:15, X:15 (our GAME OVER screen)
            STA warpToScreen        
            LDA #$01
            STA screenTransitionType

    +doWarpToContinue:
        LDA myMaxHealth
        STA myHealth
        WarpToScreen warpToMap, warpToScreen, screenTransitionType
        ChangeActionStep player1_object, #$00
        LDX player1_object
        LDA #$00000000
        STA Object_direction,x
Your code should now look like:

View attachment 7468



6) RESET ON GAME OVER SCREEN

Last thing, when the GAME OVER is displayed, we need a way to reset the game.

In your Scripts > Input Scripts, adds the "SimpleReset.asm" script (from the "BASE_4_5\Game\inputScripts" folder):
View attachment 7469

And in the Input Editor, Assign that "SimpleReset.asm" script to the press START button for the "GameState-3" target (the same game state we assigned our Game Over to):
View attachment 7470



Voilà, now you should be able to respawn to the checkpoint and if no more lives be warped to the Game Over screen.
I've tried to keep it simple with minimal alterations of the stock code. Let me know if you encounter any diffculties.
Awesome and useful tutorial. Can I use it in the arcade module? If so, do I have to do anything differently?
 
Top Bottom