A tile that deals damage? - for: 4.5.9. Metroidvania (SOLVED)

tbizzle

Well-known member
The current hurt tile kills you with one hit, would be cool to have a tile that will deal a HP of damage instead of an insta-kill. Any help would be appreciated! Thank you.
 
Here's the code from the hurtplayer script. you should be able to stick it to a tile. Depending on how you plan to use the tile, you may want to comment out the "recoil" paragraphs.

Code:
    TXA
    STA temp
    GetActionStep temp
    CMP #$07
    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 #$07 ;; hurt state.
    BEQ +notAlreadyInHurtState
        DEC myHealth
        
        BMI +healthBelowZero
        BEQ +healthBelowZero
            JMP +notDeadYet
        +healthBelowZero
            
            JMP +playerHealthIsZero
        +notDeadYet
        UpdateHudElement #$02
        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
    +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 L/R
            ;+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
    
+playerHealthIsZero:

    LDA continueMap
    STA warpMap
    
    LDA continueX
    STA newX
    LDA continueY
    STA newY
    
    LDA continueScreen
    STA warpToScreen
    STA camScreen
    
    LDA myMaxHealth
    STA myHealth
    
    WarpToScreen warpToMap, warpToScreen, #$02
        ;; 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.

    
+skipHurt

That script doesn't mention anything about player lives, so you'll probably want to add this bit of code from the HurtTile script right after that +playerHealthIsZero: line at the end there:
Code:
        Dec myLives
        LDA myLives
        BNE +myLivesNotZero
            JMP RESET ;; game over.
            ;;;; also could warp to game over screen here instead.
    +myLivesNotZero:

I'll leave the testing to you.
 

tbizzle

Well-known member
Thank you so much @saturdayxiii !!!! Works like a charm! Here is the script I'm using:

TXA
STA temp
GetActionStep temp
CMP #$07
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 #$07 ;; hurt state.
BEQ +notAlreadyInHurtState
DEC myHealth

BMI +healthBelowZero
BEQ +healthBelowZero
JMP +notDeadYet
+healthBelowZero

JMP +playerHealthIsZero
+notDeadYet
UpdateHudElement #$02
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
+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 L/R
;+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

+playerHealthIsZero:

LDA continueMap
STA warpMap

LDA continueX
STA newX
LDA continueY
STA newY

LDA continueScreen
STA warpToScreen
STA camScreen

LDA myMaxHealth
STA myHealth

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

WarpToScreen warpToMap, warpToScreen, #$02
;; 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.


+skipHurt
 
Top Bottom