Metrovania- Player Recoil, glitching between screens when collides with monsters

StarlettaMusic

New member
Hello! I am new to coding and game development and have run into a few issues with a scroll platform style game when the player interacts with certain tiles. I have hurt tiles on the road and when the player walks into them, the hurt animation plays but the player gets stuck and sinks into the tile until all the health goes away?? I want the player to bounce away from the tile when it interacts

I also have an issue where when the player gets hurt while scrolling (im assuming when the animation is in between slides) it glitches out side screen and resets the game.

Any help is appreciated!

code:
;;;;;;;;;;;;;;;;;; Presumes there is a variable called myLives defined in user variables.
;;;;;;;;;;;;;;;;;; You could also create your own variable for this.
hurtPlayer:
LDA gameHandler
AND #%10000000
BEQ +canHurtPlayer
JMP +skipHurt
+canHurtPlayer:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;; is the monster below our feet?
;;;;;;;;;; and are we moving downward?

+doHurtPlayer
TXA
STA temp
GetActionStep temp
CMP #$06
BNE +canHurtPlayer
JMP +skipHurt
+canHurtPlayer
CMP #$07
BNE +canHurtPlayer
JMP +skipHurt
+canHurtPlayer

; Also check for non-lethality.
TYA ;; Store Y in accumulator.
PHA
LDY otherObject
LDA Object_vulnerability,y
BEQ +yesIsLethal
;; Nope, not lethal.
PLA
TAY
JMP +skipHurt
+yesIsLethal
PLA ;; Restore Y value.
TAY
;;; 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 +recoilUp
LDA Object_direction,x
AND #%00001111
ORA #%10000000
STA Object_direction,x
JMP +skipHurt

+recoilUp
LDA Object_direction,x
AND #%00001111
ORA #%11000000
STA Object_direction,x
JMP +skipHurt

+playerHealthIsZero:

DEC myLives
BEQ +playerLivesIsZero
JMP +playerLivesIsZero

+playerLivesIsZero:

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
 

smilehero65

Active member
Hello! I am new to coding and game development and have run into a few issues with a scroll platform style game when the player interacts with certain tiles. I have hurt tiles on the road and when the player walks into them, the hurt animation plays but the player gets stuck and sinks into the tile until all the health goes away?? I want the player to bounce away from the tile when it interacts

I also have an issue where when the player gets hurt while scrolling (im assuming when the animation is in between slides) it glitches out side screen and resets the game.

Any help is appreciated!

code:
;;;;;;;;;;;;;;;;;; Presumes there is a variable called myLives defined in user variables.
;;;;;;;;;;;;;;;;;; You could also create your own variable for this.
hurtPlayer:
LDA gameHandler
AND #%10000000
BEQ +canHurtPlayer
JMP +skipHurt
+canHurtPlayer:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;; is the monster below our feet?
;;;;;;;;;; and are we moving downward?

+doHurtPlayer
TXA
STA temp
GetActionStep temp
CMP #$06
BNE +canHurtPlayer
JMP +skipHurt
+canHurtPlayer
CMP #$07
BNE +canHurtPlayer
JMP +skipHurt
+canHurtPlayer

; Also check for non-lethality.
TYA ;; Store Y in accumulator.
PHA
LDY otherObject
LDA Object_vulnerability,y
BEQ +yesIsLethal
;; Nope, not lethal.
PLA
TAY
JMP +skipHurt
+yesIsLethal
PLA ;; Restore Y value.
TAY
;;; 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 +recoilUp
LDA Object_direction,x
AND #%00001111
ORA #%10000000
STA Object_direction,x
JMP +skipHurt

+recoilUp
LDA Object_direction,x
AND #%00001111
ORA #%11000000
STA Object_direction,x
JMP +skipHurt

+playerHealthIsZero:

DEC myLives
BEQ +playerLivesIsZero
JMP +playerLivesIsZero

+playerLivesIsZero:

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
Replace the Hurt Tile code with this:


Code:
;;; Simple Reset
    ;; check to see if object colliding is a player.
    ;; if not, do not reset.
    CPX player1_object
    BNE dontDoTileReset
        LDA Object_direction,x
        AND #%00001111
        STA Object_direction,x

    ;; stop the scrolling :
        LDA scrollByte
        AND #%00111110
        ORA #%00000010
        STA scrollByte
        ;; and disables the inputs:
        LDA #$FF
        STA gameState

    LDA continueMap
    STA warpMap
   
    LDA continueX
    STA newX
    LDA continueY
    STA newY
   
    LDA continueScreen
    STA warpToScreen
    STA camScreen
   
   
    WarpToScreen warpToMap, warpToScreen, #$02
    dontDoTileReset:
 
Top Bottom