Page 1 of 2

HUD doesn't update health upon death

Posted: Fri Oct 19, 2018 10:33 pm
by CutterCross
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.

Image

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

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

;;; 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...

Re: HUD doesn't update health upon death

Posted: Sat Oct 20, 2018 6:01 am
by dale_coop
You could try this script (HandlePlayerHurt.asm):

Code: Select all

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

Re: HUD doesn't update health upon death

Posted: Sat Oct 20, 2018 4:49 pm
by CutterCross
OH MY GOD IT WORKS! Thanks a lot Dale!

Re: HUD doesn't update health upon death

Posted: Sat Oct 20, 2018 4:55 pm
by dale_coop
You’re welcome. Glad if I could help you! <3

Re: HUD doesn't update health upon death

Posted: Wed Nov 07, 2018 3:19 am
by Redherring32
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.

Re: HUD doesn't update health upon death

Posted: Wed Nov 07, 2018 7:10 am
by dale_coop
You need to set back your myHealth variable to its max/initiale value at the player death (for example in xxx_HandlePlayerDeath.asm )

Re: HUD doesn't update health upon death

Posted: Wed Nov 07, 2018 4:53 pm
by Redherring32
dale_coop wrote:
Wed Nov 07, 2018 7:10 am
You need to set back your myHealth variable to its max/initiale value at the player death (for example in xxx_HandlePlayerDeath.asm )
K thanks I'll try it tonight.

Re: HUD doesn't update health upon death

Posted: Thu Nov 08, 2018 2:15 am
by Redherring32
So, I'm supposed to edit "HandlePlayerDeath.asm"?
Also what value am I changing?

Re: HUD doesn't update health upon death

Posted: Thu Nov 08, 2018 8:10 am
by dale_coop
Redherring32 wrote:
Thu Nov 08, 2018 2:15 am
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 wrote:
Thu Nov 08, 2018 2:15 am
So, I'm sAlso what value am I changing?
Around line 26 :

Code: Select all

	LDA #$FF
	STA player1_object
	
	LDA #$03  ;; <---- the player's health value
	STA myHealth

Re: HUD doesn't update health upon death

Posted: Thu Nov 08, 2018 4:39 pm
by Redherring32
Thanks a bunch for the anwser,
I was about to have a total meltdown last night over the dumb health not working,.. :?