[4.5.9] doHandleHurtMonster issue with Scrolling Platform

pierski

New member
I believe the problem I am trying to overcome is unique to the Scrolling Platform module.

When jumping on a monster, the following code on line 121 of doHandleObjectCollisions_PlatformerBase.asm is never called, because it is looking for a weapon collision with a monster.
Code:
JSR doHandleHurtMonster

What is called is the code on line 179, which occurs when the player has collided with the monster.
Code:
JSR doHandleHurtPlayer

That in turn calls hurtPlayer_PlatformBase.asm with the following code:
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:
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;; is the monster below our feet?
    ;;;;;;;;;; and are we moving downward?
    
    LDA Object_v_speed_hi,x
    BEQ +doHurtPlayer ;; equal to zero
    BMI +doHurtPlayer ;; or negative
     ;; here we are moving downward.
    TXA
    PHA
        LDX otherObject
        DestroyObject
        
        CountObjects #%00001000
            BNE +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
    PLA
    TAX

     ;; Do a hop
     LDA #$FC
     STA Object_v_speed_hi,x
    

     JMP +skipHurt

    
+doHurtPlayer   

    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
    


    
    
    
    WarpToScreen warpToMap, warpToScreen, #$02
+skipHurt

I am trying to add a death animation for the monster before the "DestroyObject" on line 21 (commenting out this line causes the monster to not be destroy), but I am not having luck. Any attempt to do "StopMoving" is having no affect on the monster and "ChangeActionStep" causes the animation to run at an extremely slow speed, even when the animation speed for that Action Step is set to 0. I can "PlaySound" without any trouble, but that's about it.

As I said before, I believe this situation may be unique to the Scrolling Platform module as it is a Player/Monster collision and not a Weapon/Monster collision. Any help is greatly appreciated.
 

dale_coop

Moderator
Staff member
if you want to use a change action step (7, for example), don't forget to check the current step of the monster before setting it (if already "7" skip the code).
Another possibility would be to create a new objet as your monster death animation (an object you wouldn't set as "monster" type), maybe?
 

pierski

New member
if you want to use a change action step (7, for example), don't forget to check the current step of the monster before setting it (if already "7" skip the code).
Another possibility would be to create a new objet as your monster death animation (an object you wouldn't set as "monster" type), maybe?

Brilliant idea. I actually used a combination of both to complete the task.

First, I replaced line 21 of hurtPlayer_PlatformBase.asm (i.e. DestroyObject) with the following code:
Code:
GetActionStep otherObject
CMP #$00
    BEQ +monsterNotDead
        JMP monsterDead
    +monsterNotDead:
        ChangeActionStep otherObject, #$07
        JMP monsterDead
    monsterDead

Then, I created a new asm file called "killMonster.asm" and assigned it to AI_behavior4. This is the code contained inside that file:
Code:
;;; load death animation
    MY_CORPSE = #$04 ;; change this to the type of object left behind.
    MY_CORPSE_Y_OFFSET = #$06 ;; change this to how far below the monster it should create this object.
    MY_CORPSE_X_OFFSET = #$04 ;; change this to how far to the left of the left side of the monster it should create this object.
    TXA
    STA temp

    LDA Object_x_hi,x
    SBC #MY_CORPSE_X_OFFSET
    STA tempA

    LDA Object_y_hi,x
    ADC #MY_CORPSE_Y_OFFSET
    STA tempB

    LDA Object_screen,x
    STA tempC

    DestroyObject
    CreateObjectOnScreen tempA, tempB, #MY_CORPSE, #$00, tempC
    PlaySound #sfx_dead

After that, I created a new "Game Object" which stores the death animation in the fifth (04) position. Inside that object, I set "Ignore Gravity" and End of Animation to "Destroy Me".

Finally inside the monster's animation info, under action step 7 I set action to AI_behavior4.

And that's it. It now figures out where the monster, leaves a death animation behind and plays a sound effect, as well. Thanks again @dale_coop , for your help.
 
Top Bottom