HUD doesn't update health upon death

CutterCross

Active member
I've been at this for a couple hours and I can't seem to find a solution...

Whenever the player dies and his health is supposed to be 0, his health stays at 1 and doesn't decrease. This is the only instance of this issue happening.

2vkNb4i.png


I've tried manually setting the myHealth variable to 0 in HandlePlayerDeath.asm, but it instead gets set to 0 AFTER the game restarts again.

Code:
HandlePlayerDeath:

	LDA #$00		;Trying to set myHealth to 0
	STA myHealth		;

	TXA
	STA tempx
	TYA 
	STA tempy
	
	;;;;;;;;;;;;;;;;;;;
	LDX player1_object
	LDA Object_x_hi,x
	STA temp
	LDA Object_y_hi,x
	STA temp1
	CreateObject temp, temp1, #$08, #$00
	;; need to do this redundantly, otherwise, the death object will be in same slot as player
	LDA #$00
	SEC
	SBC #$05
	STA Object_v_speed_hi,x
	LDX player1_object
	DeactivateCurrentObject
	;;;;;;;;;;;;;;;;;;;
	;StopSound
	
	PlaySound #SFX_PLAYER_LOSE
	
	LDA #$FF
	STA player1_object
	
	
	LDX tempx
	LDY tempy
	
	RTS

I've also tried manually setting it to 0 in HandlePlayerHurt.asm, but that did nothing.

Code:
;;; assumes myHealth variable
;;; if a different variable should handle health
;;; change thename of myHealth.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; uses timers set in GameData\Constants:
;;OBJECT TIMERS
;HURT_TIMER = #$08
;INVINCIBILITY_TIMER = #$08
;RECOIL_SPEED_HI = #$06
;RECOIL_SPEED_LO = #$00

;;;; To change invincibility time, knock back speed, or hurt duration
;;;; updating the above values in constants


	LDA Object_status,x
	ORA #%00000001
	STA Object_status,x
	LDA #HURT_TIMER
	STA Object_timer_0,x
	ChangeObjectState #$05,#$02 ;;hurt state.
	
	LDA selfCenterX
	STA recoil_selfX
	LDA selfCenterY
	STA recoil_selfY
	LDA otherCenterX
	STA recoil_otherX
	LDA otherCenterY
	STA recoil_otherY
	
	JSR DetermineRecoilDirection
	LDA Object_health,x
	SEC
	SBC #$01 ;; subtract other's strength
	CMP #$01
	BCS notPlayerDeath
	
	LDA #$00		;Trying to set myHealth to 0 when player dies.
	STA myHealth		;
	
	JSR HandlePlayerDeath 
	JMP doneWithPlayerHurt
notPlayerDeath:

	STA Object_health,x
	STA myHealth

	STA hudElementTilesToLoad
		LDA #$00
		STA hudElementTilesMax
		LDA DrawHudBytes
		ora #HUD_myHealth
		STA DrawHudBytes
    ;; TURN ON handling the hud
	
	PlaySound #SFX_PLAYER_DAMAGE
	
doneWithPlayerHurt:

I'm kind of at a loss here...
 

dale_coop

Moderator
Staff member
You could try this script (HandlePlayerHurt.asm):
Code:
;;; assumes myHealth variable
;;; if a different variable should handle health
;;; change thename of myHealth.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; uses timers set in GameData\Constants:
;;OBJECT TIMERS
;HURT_TIMER = #$08
;INVINCIBILITY_TIMER = #$08
;RECOIL_SPEED_HI = #$06
;RECOIL_SPEED_LO = #$00

;;;; To change invincibility time, knock back speed, or hurt duration
;;;; updating the above values in constants
	TXA
	STA tempx
	TYA 
	STA tempy

	LDA Object_status,x
	ORA #%00000001
	STA Object_status,x
	LDA #HURT_TIMER
	STA Object_timer_0,x
	ChangeObjectState #$05,#$02 ;;hurt state.
	
	LDA selfCenterX
	STA recoil_selfX
	LDA selfCenterY
	STA recoil_selfY
	LDA otherCenterX
	STA recoil_otherX
	LDA otherCenterY
	STA recoil_otherY
	
	JSR DetermineRecoilDirection
	LDA Object_health,x
	SEC
	SBC #$01 ;; subtract other's strength
	CMP #$01
	
	;Trying to set myHealth to 0 when player dies:
	STA Object_health,x
	STA myHealth
	STA hudElementTilesToLoad
		LDA #$00
		STA hudElementTilesMax
		LDA DrawHudBytes
		ora #HUD_myHealth
		STA DrawHudBytes
    ;; TURN ON handling the hud
	
	BCS notPlayerDeath	
	JSR HandlePlayerDeath 
	JMP doneWithPlayerHurt
notPlayerDeath:
	PlaySound #SFX_PLAYER_DAMAGE
	
doneWithPlayerHurt:
	LDX tempx
	LDY tempy
 
I don't mean to bump a resolved thread,
but I'm having a similar problem.
Only my health goes down fine for 1 death, then the last heart stays on the second death,
And it stays that way.


Thanks in advance for any help.
 

dale_coop

Moderator
Staff member
You need to set back your myHealth variable to its max/initiale value at the player death (for example in xxx_HandlePlayerDeath.asm )
 

dale_coop

Moderator
Staff member
Redherring32 said:
So, I'm supposed to edit "HandlePlayerDeath.asm"?
Which module are you using? Adventure? Platformer?

if you use the Adventure module, you need to modify the Routines\UserScripts\AdventureGame_Base\HurtWinLoseDeath\Adventure_HandlePlayerDeath.asm script
if Platformer, it's the Routines\UserScripts\PlatformGame_Base\HurtWinLoseDeath\Platform_HandlePlayerDeath.asm script

Redherring32 said:
So, I'm sAlso what value am I changing?

Around line 26 :
Code:
	LDA #$FF
	STA player1_object
	
	LDA #$03  ;; <---- the player's health value
	STA myHealth
 

chronosv2

New member
I think that's because the Hurt code doesn't actually update the myHealth variable if the death condition is true. You could solve it by storing the 0 in myHealth and updating the HUD before handling death.
 
chronosv2 said:
I think that's because the Hurt code doesn't actually update the myHealth variable if the death condition is true. You could solve it by storing the 0 in myHealth and updating the HUD before handling death.

How would I do that?
I know 0 Assembly, so I'm completely clueless.


-Edit To clarify, all 3 hearts go down on the first death, but the rest of the times my player dies the last heart stays.
 

chronosv2

New member
Ah, I didn't realize it worked fine on the first attempt and then not on any others. Hm.

I was originally thinking to move the block of code in Adventure_HandlePlayerHurt.asm or Platform_HandlePlayerHurt.asm
Code:
	STA Object_health,x
	STA myHealth

	STA hudElementTilesToLoad
		LDA #$00
		STA hudElementTilesMax
		LDA DrawHudBytes
		ora #HUD_myHealth
		STA DrawHudBytes
above
Code:
	CMP #$01
	BCS notPlayerDeath
and add
Code:
	LDA myHealth
between them so it ultimately looks like this (Line 36, the line immediately above this is "SBC #$01"):
Code:
	STA Object_health,x
	STA myHealth

	STA hudElementTilesToLoad
		LDA #$00
		STA hudElementTilesMax
		LDA DrawHudBytes
		ora #HUD_myHealth
		STA DrawHudBytes
	LDA myHealth
	CMP #$01
	BCS notPlayerDeath
	.include SCR_HANDLE_PLAYER_DEATH
	JMP doneWithPlayerHurt
notPlayerDeath:
	PlaySound #SFX_PLAYER_HURT  ;; If this is commented out in the script you're editing (starts with ";") you should keep it commented out.
doneWithPlayerHurt:
I think that should do it.
As always, back up the file before you make any changes, just to be safe. I think this should work, but I haven't had any opportunity to test it.
 

chronosv2

New member
I'm glad to be of help. I'm learning ASM myself, and using what I've learned to make tutorials for others to follow. I've made some missteps along the way so far but I'm glad to hear that fix did the trick. I was a little concerned moving the HUD Update code up might cause a conflict, but that's why I suggested backing up.

In my opinion, it's a lot of fun once you really get into it. I've got some scripts in the works for 4.1.0, and I love writing in this old programming language designed for a 1975 processor.
 
Top Bottom