Cant die MetroVaina 4.5.9 [Solved]

Barry2

Member
So im not sure what i have done with the code but, when i get hit from my monster it will take a life away (my health is set 3 hit), it will take the 2nd health away, but when i get hit for my final health it gives me all my life back instead of killing my player. Here is my code that im using for my hurt player.

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 
  
    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:

    DEC myHealth
    LDA myHealth
    BNE myLivesNotZero
        ;JMP RESET ;; game over.
        ;;;; also could warp to game over screen here instead.
        
        WarpToScreen #$01, #$255, #$01  ;;This is warp to UNDERWORLD, LAST SCREEN this is for me because 8x8 , #$01 is normal warp;;

    ;; arg0 = warp to map.  0= map1.  1= map2.
    ;; arg1 = screen to warp to. use mouse to find coordinates = #$yx use hex convertor.
    ;; arg2 = screen transition type - most likely use 1 here.
        ;; 1 = warp, where it observes the warp in position for the player.
    ;;Don't Forget to set WARP IN COORDINATES ON YOUR MAP!;;

    JMP +skipHurt

myLivesNotZero:

    LDA continueMap
    STA warpMap
    
    LDA continueX
    STA newX
    LDA continueY
    STA newY
    
    LDA continueScreen
    STA warpToScreen
    STA camScreen
    
    LDA myMaxHealth
    STA myHealth
    
    
 
+skipHurt
 
Last edited:

dale_coop

Moderator
Staff member
When you paste code in your posts, I'd suggest to use the "CODE" button... it will make the code way easier to read:

Capture d’écran 2021-12-08 à 11.47.16.png
 

dale_coop

Moderator
Staff member
Looks like your script does twice the :
Code:
DEC myHealth
I think you should remove (or just comment out) the one that is after the "+playerHealthIsZero:" line, you don't need it.
 

dale_coop

Moderator
Staff member
Also, in order to not have strange issues with the hurt/death state...
I would add a small piece of code to check if the player object is still available before executing that script.
At the beginning, add:
Code:
    ;; we check if the object is still active (not destroyed or in the process of being destroyed...)
    LDA Object_status,x
    AND #OBJECT_IS_ACTIVE
    BNE +continue
        JMP +skipHurt
    +continue:
 

Barry2

Member
THANK YOU! That did, So i was missing something the entire time but after carefully going over your code and instructions i notice that in my warp screen i had it as a 01 with is map 2, i changed it to 00 and it put me right to my death screen! I have to remember that it 1 in the number line is 0 first. That is why i was falling in a bunch of black screens because was warping to screen 01 which in my underworld screen which was not set. Thank you @dale_coop for for your time!!!!
Now that the last code im glad that you gave it to me. My next thing that i was going to work on was a player death. With the script that you gave me on you last post, to make sure that im putting it in the right place, would i be putting the code right after +playerHealthIsZero: , in the begainning of the entire code?

Again you have been a HUGE HELP on explaining code and im starting to understand it better! I do now that placement of code in important
 
Top Bottom