Monster collision hurting player in hurt state MAZE [4.5.9]

d_krops

Member
I notice certain collisions with monsters, they'll take all the players lives. it seems to ignore the players hurt state. 9/10 times when I collide with a monster the player object will flash orange, which is my action state 07. then the screen will reset. The odd time I collide with a monster they wipe out all my lives. In the video this is a spot I can sometimes reproduce this happening. You can see that I do flash orange very quickly showing it did go to my hurt state but continued hurting the player anyways. My Player hurt code below.

Code:
    TXA
    PHA
    LDA gameHandler
    AND #%10000000
    BEQ +canHurtPlayer
        JMP +skipHurt
+canHurtPlayer:
    TXA
    STA temp
    GetActionStep temp
    CMP #$07
    BNE +canHurtPlayer
        JMP +skipHurt
    +canHurtPlayer
    
    
    GetActionStep player1_object
    CMP #$06 ;;;victory action state once all prizes collected
    BNE +canHurtPlayer
        JMP +skipHurt
    +canHurtPlayer
    
    DEC myLives
    
    UpdateHudElement #$01
    LDA myLives
    BNE +notZeroLives
        ;;;zero lives
        ;JMP RESET
        WarpToScreen #$00, #$E0, #$01
    ;; arg0 = warp to map.  0= map1.  1= map2.
    ;; arg1 = screen to warp to.
    ;; arg2 = screen transition type - most likely use 1 here.
            ;; 1 = warp, where it observes the warp in position for the player.
    +notZeroLives
        ChangeActionStep player1_object, #$07
            ;; 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
    
    
+skipHurt
    PLA
    TAX

View: https://www.youtube.com/watch?v=vGuO41f3Rc4
 

JamesNES

Well-known member
Looks like you're only checking the player for action step 6 when you should be for 7 as well. That first check for 7 must be checking the enemy's step
 

d_krops

Member
I changed the first part to specify Player1_object and compare to action state 07. I'm still getting the same thing happening. The only thing I added to this default script was include a check for action state 06 and a warp to game over at 0 lives.

Code:
+canHurtPlayer:
    ;TXA
    ;STA temp
    ;GetActionStep temp
    GetActionStep player1_object
    CMP #$07
    BNE +canHurtPlayer
        JMP +skipHurt
    +canHurtPlayer
    
    
    GetActionStep player1_object
    CMP #$06 ;;;victory action state once all prizes collected
    BNE +canHurtPlayer
        JMP +skipHurt
    +canHurtPlayer
 

JamesNES

Well-known member
That's weird, it doesn't make much sense. I'd chuck some JMP RESET lines in there to make sure it's getting to the part where the action step is being changed to 7. The code looks just fine.
 

Peter Schmitz

Active member
How does your doHandleObjectCollisions look like?
I compared your handleHurtPlayer asm with mine and there are only minor differences in usage of the action steps
But will post my script anyway:

Code:
    TXA
    PHA
    LDA gameHandler
    AND #%10000000
    BEQ +canHurtPlayer
        JMP +skipHurt
        
+canHurtPlayer:
    TXA
    STA temp
    GetActionStep temp
    CMP #$06 ; death state - check if player is already dead and in death animation
    
    BNE +notAlreadyinDeathState
        JMP +skipHurt
    
    +notAlreadyinDeathState
    
        TXA
        STA temp
        GetActionStep temp
        CMP #$07 ;hurt - check if player is in hurt state - did he already got hit
        BNE +canHurtPlayer
            JMP +skipHurt
        
    +canHurtPlayer
        
        PlaySound #sfx_damage
        DEC myLives
        UpdateHudElement #$04 ;see Hud which element is var myLives
        
        LDA myLives
        BNE +notZeroLives  ;;;zero lives
            ChangeActionStep player1_object, #$06
            ;StopMoving temp, #$FF, #$00
            ;StopSound ;--stop all music before
            PlaySound #sfx_dead
            DestroyObject
            jmp +skipHurt
            ;JMP RESET
        
        +notZeroLives
            ChangeActionStep player1_object, #$07
            ;; 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

+skipHurt
    PLA
    TAX

But in my object collision script I had to add this to ignore collision checks while being in action step 6 and 7

Code:
;;STEP 2: Check for hurt state.
    ;;; In this module, monsters and player will use action step 7 for their hurt state.and 6 for death state
    TXA
    STA selfObject
    STA temp
    GetActionStep temp
    
    CMP #$06
    BNE +notDead
        JMP +skipObjectCollisionCheck
    
    +notDead
    GetActionStep temp
    CMP #$07
    BNE +notHurt
        JMP +skipObjectCollisionCheck
    +notHurt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;STEP 3: Set up bounds for self collision.
 

Peter Schmitz

Active member
when my player dies - I also added a "jmp +skipHurt" after DestroyObject
You have a warptoScreen macro there - and then the code proceeds to changing the actionstep to 7 - I would add a "jmp +skipHurt" just in case - maybe not that necessary
 

d_krops

Member
How does your doHandleObjectCollisions look like?
I compared your handleHurtPlayer asm with mine and there are only minor differences in usage of the action steps
But will post my script anyway:

Code:
    TXA
    PHA
    LDA gameHandler
    AND #%10000000
    BEQ +canHurtPlayer
        JMP +skipHurt
       
+canHurtPlayer:
    TXA
    STA temp
    GetActionStep temp
    CMP #$06 ; death state - check if player is already dead and in death animation
   
    BNE +notAlreadyinDeathState
        JMP +skipHurt
   
    +notAlreadyinDeathState
   
        TXA
        STA temp
        GetActionStep temp
        CMP #$07 ;hurt - check if player is in hurt state - did he already got hit
        BNE +canHurtPlayer
            JMP +skipHurt
       
    +canHurtPlayer
       
        PlaySound #sfx_damage
        DEC myLives
        UpdateHudElement #$04 ;see Hud which element is var myLives
       
        LDA myLives
        BNE +notZeroLives  ;;;zero lives
            ChangeActionStep player1_object, #$06
            ;StopMoving temp, #$FF, #$00
            ;StopSound ;--stop all music before
            PlaySound #sfx_dead
            DestroyObject
            jmp +skipHurt
            ;JMP RESET
       
        +notZeroLives
            ChangeActionStep player1_object, #$07
            ;; 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

+skipHurt
    PLA
    TAX

But in my object collision script I had to add this to ignore collision checks while being in action step 6 and 7

Code:
;;STEP 2: Check for hurt state.
    ;;; In this module, monsters and player will use action step 7 for their hurt state.and 6 for death state
    TXA
    STA selfObject
    STA temp
    GetActionStep temp
   
    CMP #$06
    BNE +notDead
        JMP +skipObjectCollisionCheck
   
    +notDead
    GetActionStep temp
    CMP #$07
    BNE +notHurt
        JMP +skipObjectCollisionCheck
    +notHurt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;STEP 3: Set up bounds for self collision.
I haven’t touched doHandleObjectCollisions. But putting that check to ignore collisions makes sense to me. Would you happen to know what line # I need to insert this under?

Will also include JMP skiphurt in my playerHurt script
 

Peter Schmitz

Active member
I haven’t touched doHandleObjectCollisions. But putting that check to ignore collisions makes sense to me. Would you happen to know what line # I need to insert this under?

Will also include JMP skiphurt in my playerHurt script
It's quite at the top - if I remember correctly the part with actions 7 is already in there
 

d_krops

Member
Okay I checked doHandleObjectCollisions and it does by default check action step 07, I added a check for 06 anyways. And put a skiphurt after warpToScreen in handlePlayerHurt. Still have the same problem.

I included another video of extended gameplay to show that most collisions work normaly and only take 1 life before restarting the screen. Its the scenario near the end where the monster T-bones me that it wipes all lives.
View: https://www.youtube.com/watch?v=NOi49YoHFts
 

d_krops

Member
I’m wondering if I could just have the monster destroy itself after the hit? As my screen will reset anyways after the player takes the first hit. Or have the monster enter another action state that won’t hurt the player further somehow.
 

d_krops

Member
After watching board-b tutorials on youtube discussing his player death script for Jack The Chick. I borrowed some of his code in his playerDeath script to disable the player and create a player death object that will restart screen on timer end.

Below is my hurt player asm

Code:
TXA
    PHA
    LDA gameHandler
    AND #%10000000
    BEQ +canHurtPlayer
        JMP +skipHurt
+canHurtPlayer:

    GetActionStep player1_object
    CMP #$06 ;;;victory action state once all prizes collected
    BNE +canHurtPlayer
        JMP +skipHurt
    +canHurtPlayer
    
    ; Get position where the player death object should be created (same as player object)
    LDA Object_x_hi,x
    STA tempA
    LDA Object_y_hi,x
    STA tempB
    LDA Object_screen,x
    STA tempD
    
    StopSound
    PlaySound #sfx_dead
    
    ;Disable player sprite
    LDA Object_status,x
    AND #%11000001
    STA Object_status,x
    
    ;Create player death object that goes to restart screen on timer end
    CreateObjectOnScreen tempA, tempB, #15, #0, tempD
    
    DEC myLives
                
    UpdateHudElement #$01
    LDA myLives
    BNE +notZeroLives
        ;;;zero lives
        ;JMP RESET
        WarpToScreen #$00, #$E0, #$01 ;Game Over Screen
        JMP +skipHurt
    ;; arg0 = warp to map.  0= map1.  1= map2.
    ;; arg1 = screen to warp to.
    ;; arg2 = screen transition type - most likely use 1 here.
    +notZeroLives
        
            
+skipHurt
    PLA
    TAX

I then went to my TimerEndScripts, under restart screen to add a section that re-enables the player

Code:
;;; 10 = Restart Screen
restartScreen_action:
    ;;;;if mylives are zero, do not restart screen, player will warp to gameover in player hurt script
    
    LDA myLives
    BNE +restartScreen
    JMP +DontRestartScreen
        +restartScreen

    LDA #$02
    STA screenTransitionType
    LDA gameHandler
    ORA #%10000000
    STA gameHandler ;; this will set the next game loop to update the screen.
    ChangeActionStep player1_object, #$00
    LDX player1_object
    LDA #$00000000
    STA Object_direction,x
            ; Make sure the player starts enabled
        LDA Object_status,x
        ORA #%00111110
        STA Object_status,x

This has now solved my problem of monsters taking all lives on certain collisions
 
Top Bottom