[Solved] Death Animations (4.5)

ronin1011

Member
I mean new game object. You get the players X&Y position and then spawn in the death VFX game object using those X&Y values. You could combine several different deathVFX into a single game object (so long as they all fit into the same size rectangle), by putting a different deathVFX into each action slot of one game object, set the end action as "destroy me" and after spawning in that new game object use ChangActionState to set the specific the deathVFX you want by forcing it into that action state.
Thanks. I was able to get monster death animation working with this code
Code:
        ;;;; play vfx
        ;;;; destroy this object
        TXA ;; Store X in stack
        PHA
        TAX
        LDA Object_x_hi,x ;; Get this object's origin location
        CLC
        ADC self_center_x
        STA tempA
        LDA Object_y_hi,x ;; Get this object's origin location
        CLC
        ADC self_center_y
        STA tempB
        LDA Object_screen,x
        CLC
        ADC #$00
        STA tempD
        DestroyObject       
        CreateObjectOnScreen tempA, tempB, #$08, #$00, tempD
        PLA    ;; Restore X from stack
        TAX
        
        RTS

Then setting the game object in 08 like this:

1624284037728.png
 

ronin1011

Member
I mean new game object. You get the players X&Y position and then spawn in the death VFX game object using those X&Y values. You could combine several different deathVFX into a single game object (so long as they all fit into the same size rectangle), by putting a different deathVFX into each action slot of one game object, set the end action as "destroy me" and after spawning in that new game object use ChangActionState to set the specific the deathVFX you want by forcing it into that action state.
Any ideas as to why the death animation won't play when hitting a hurt tile or when the game resets on the last death?
 

AllDarnDavey

Active member
For the hurt tile you might want to check the hurt tile script, is it a one hit death like for spikes? It probably skips over all the hurt player script stuff and just reloads and subtracts 1 from your lives. You could probably make a copy of the hurt tile script that also plays the death VFX, but you'd probably only see it for a few frames before the game resets.

The last death is probably a similar issue, the hurtplayer script probably just skips everything and resets the game, you could make it play the death VFX, but it would probably only see a frame before the reset.

If you want the game to wait to reset until after the death VFX plays you have to get more creative and move some of the reset code from the player hurt script to somewhere that the death VFX triggers it once it's done.

You can follow this post:

Follow it as is to just add in the player death as an animation on the player that will reset and subtract a life when finished playing. You could also keep the separate deathVFX you have now, and have that VFX trigger the "GoToContinue" instead, (just make sure you only use that deathVFX with the player or killing enemies will reset and subtract a life).
 

ronin1011

Member
For the hurt tile you might want to check the hurt tile script, is it a one hit death like for spikes? It probably skips over all the hurt player script stuff and just reloads and subtracts 1 from your lives. You could probably make a copy of the hurt tile script that also plays the death VFX, but you'd probably only see it for a few frames before the game resets.

The last death is probably a similar issue, the hurtplayer script probably just skips everything and resets the game, you could make it play the death VFX, but it would probably only see a frame before the reset.

If you want the game to wait to reset until after the death VFX plays you have to get more creative and move some of the reset code from the player hurt script to somewhere that the death VFX triggers it once it's done.

You can follow this post:

Follow it as is to just add in the player death as an animation on the player that will reset and subtract a life when finished playing. You could also keep the separate deathVFX you have now, and have that VFX trigger the "GoToContinue" instead, (just make sure you only use that deathVFX with the player or killing enemies will reset and subtract a life).
Ok yeah I'll mess with those scripts. I did use your code for the player death anim as a hurt state so that is working for me.
Thanks so much. I really do appreciate all the help you guys give us newbies. I'm no stranger to code but I haven't worked in this language so its basically piecing together and modifying code.
And of course I'm impatient so I choose this way instead of learning the language fully lol. But I'm learning as I go thanks to you awesome folks!
 

Matsuura77

New member
View attachment 3524
Okay, for Passe's shooter we setup a generic death VFX because that made more sense for that type of game. But it'sa death VFX not custom death animation, but we can do that too, just need to tweak the hurtMonster script a bit.
Make and assign a new hurtMonster, give it a new name like hurtMonster_DieAnimation.asm and give it this code:
Code:
    TXA
    STA temp
    GetActionStep temp
    CMP #$07 ;; we will use action step 7 for hurt.
    BNE +
        JMP +doSkipHurtingThisObject ;; if he is hurt, he can't be hurt again until the timer wears off.
    +
    CMP #$06 ;; we will use action step 6 for die.
    BNE +
        JMP +doSkipHurtingThisObject ;; if he is dying, he can't be hurt again.
    +
        StopMoving temp, #$FF, #$00 ;;stop it from moving
        DEC Object_health,x    ;;take off 1 point of health
        LDA Object_health,x    ;;load it's health into accumulator for comparison
        BEQ +die    ;;if zero health die
            ChangeActionStep temp, #$07    ;change to hurt action
            PlaySound #sfx_damage    ;;play hurt sound
            JMP +doSkipHurtingThisObject    ;;skip the rest
        +die
            ChangeActionStep temp, #$06    ;;change to death action
            PlaySound #sfx_dead    ;; play death sound
            CountObjects #%00001000    ;;count enemies onscreen for monster locks
            CMP #$02    ;;because the object kills itself at the end of it's death animation and this script doesn't kill it anymore we check for 1 monster left or 0 using BCC which means less than 02
            BCC +notZeroCount
                LDA scrollByte
                ORA #%00000010
                STA scrollByte
                ;;; if there are no more monsters left, we want to disable
                ;;; the edge check for scrolling.
                LDA ScreenFlags00
                AND #%11101111
                STA ScreenFlags00
            +notZeroCount
    +doSkipHurtingThisObject
Next, make sure your enemy has health more then 1, and make hurt and death animations for it.
Use these settings for action 7 (we're leaving action 7 as hurt because it's a pain to change)
View attachment 3525

Also, we need to set up action 6 as our death animation with these settings:
View attachment 3526

The end animation and end action settings as well as animation used are the important bits, tweak the rest to the monster specifics.

If you get the enemy moving crazy when in the hurt state try going into your doHandlePysics script finding the settings for RECOIL_SPEED_HI & RECOIL_SPEED_LO and lower them, or even zero them out. I found my probe enemies did not like recoil one bit.

The player death is a little more tricky as you can see from the solution we use for Passe's shooter game. I'll see about posting on player death when I have more time.
Many thanks.. another useful post with clear instructions of how to implement the changes.
It worked (metroidvania 4.5.9) exactly as described.
All i need to do now is stop the monsters recoilling (but still have the player recoil) when hurt
 

Kanbei85

Member
When trying to implement this code into my HurtMonster script (by using a new HurtMonster script), it causes the game to fail to compile with a lot of "Can't Determine Address" error messages. Why do you think that might be?
 

TheRetroBro

Active member
The easiest way to add death animations for enemies is to make an explosion VFX and change the doHandleHurtMonster script to spawn that in when the object is destroyed. I actually just figured out something very similar for making bullet hit VFX for my game.
You'll want to replace your doHandleHurtMonster shooter script with this. I kept in all the normal stuff allowing for monsters with more than a single hit of health, and the bit about counting monsters to unlock the scroll.
Code:
    DEC Object_health,x
    LDA Object_health,x
    CMP #$00
    BNE +
        ;;;; play vfx
        ;;;; destroy this object
        TXA ;; Store X in stack
        PHA
        TAX
        LDA Object_x_hi,x ;; Get this object's origin location
        CLC
        ADC self_center_x
        STA tempA
        LDA Object_y_hi,x ;; Get this object's origin location
        CLC
        ADC self_center_y
        STA tempB
        LDA Object_screen,x
        CLC
        ADC #$00
        STA tempD
        DestroyObject       
        CreateObjectOnScreen tempA, tempB, #$08, #$00, tempD
        PLA    ;; Restore X from stack
        TAX
    +:
    CountObjects #%00001000
    BNE +notZeroCount
        ;;; if there are no more monsters left, we want to disable
        ;;; the edge check for scrolling.
        LDA ScreenFlags00
        AND #%11101111
        STA ScreenFlags00

+notZeroCount:
Of course this is just a single VFX for all enemies dying, you'll have to get more creative if you want custom death VFX per enemy type.
This works great but gets rid of my player hurt animation. is there a way to work that into this code? I have ZERO programming experience lol
 
Top Bottom