Health Pickups with Sprite HUD Issue? (4.15)

crazygrouptrio

Active member
I used this script to make a health sprite http://nesmakers.com/viewtopic.php?f=3&t=941&hilit=sprite+hud+drawing and I've modified that code so that it can be increased with a max health upgrade pickup. Which at least SEEMS to be working fine. Below you can see that getting the upgrade does increase the health bar, but picking up health afterwards does nothing. After experimentation I've noticed that picking up health from being hit does work a FEW times, but after picking up so many they stop healing the player. The health bar and the pickups use the same HealthMax variable to check what the player's max health is, so I'm at a loss. I'm assuming its my pickup script, but as a lot of things are being checking and "working" together I'm not really sure?
oRxcf3d.gif

Code:
;;; Increase Health code for player.
;;; works with variable myHealth
;;; works with HUD variable HUD_myHealth.
	LDA myHealth
	CLC
	;ADC #$01
	;CMP #$04
	CMP HealthMax
	BCS skipGettingHealth
	
	TXA
	STA tempx
	;;;you may want to test against a MAX HEALTH.
	;;; this could be a static number in which case you could just check against that number
	;;; or it could be a variable you set up which may change as you go through the game.
	;inc myHealth
	
	LDA myHealth
	ADC #$0A
	
	LDX player1_object
	STA Object_health,x
	
	;;; we also need to set up the routine to update the HUD
	;; for this to work right, health must be a "blank-then-draw" type element.
	;STA hudElementTilesToLoad
		;LDA #$00
		;STA hudElementTilesMax
		; LDA DrawHudBytes
		; ORA #HUD_myHealth
		; STA DrawHudBytes
	;UpdateHud HUD_myHealth
	;LDX tempx
	
skipGettingHealth:
	;PlaySound #SFX_INCREASE_HEALTH
My health works in increments of 10, so its very possible I'm adding 10 wrong, but the fact its unreliably working is strange.

Code:
LDA #$00		
		STA temp2		;Number of full sprites
		STA temp1		;if there is a partial sprite and what is it
		LDA HealthMax
		CMP #$5A ; 90 
		BEQ +do90health
CMP #$3C ;60
BEQ +do60health 
;; other increments here;;
	LDA #$08		;; at full
		STA temp
JMP continueHealthBar
+do90health
LDA #$04		
		STA temp		;Number of empty sprites
		JMP continueHealthBar
+do60health:
		LDA #$02		
		STA temp		;Number of empty sprites
		JMP continueHealthBar
		
		continueHealthBar:
This is how I edited the DrawStatusBar macro from the tutorial above to work with health upgrades. The Predraw script was similarly edited but that only really determines the size of the health bar image-wise, which is increasing correctly, and the whether the health increases or not seems to be accurate with what the health bar indicates. If health pickups stop working the player will still die when the health bar indicates they will. If that makes sense :lol:
 

dale_coop

Moderator
Staff member
hmm... You use joro's hud code... it's very specific, if I understand it well, the code uses each bit of the health variable to draw each segment of the health bar.
But it means you can only have 8 health max...? in fact it's 0 from 255, but incrementing by 8 each time (you get hurt: -8, you collect a heart item +8... for a total of 32 increments).
His code is a little difficult for me to understand without doing experiments myself. But I don't think it's designed to allow the health max to be changed.
 

crazygrouptrio

Active member
dale_coop said:
hmm... You use joro's hud code... it's very specific, if I understand it well, the code uses each bit of the health variable to draw each segment of the health bar.
But it means you can only have 8 health max...? in fact it's 0 from 255, but incrementing by 8 each time (you get hurt: -8, you collect a heart item +8... for a total of 32 increments).
His code is a little difficult for me to understand without doing experiments myself. But I don't think it's designed to allow the health max to be changed.

Very true, this is my attempt to force it to work :? The player starts with 60 health and the pickup increases it to 90. I don't intend to use the full health of 255 and have been doing it in increments of 10 (both in player damage and increasing health), the damage works fine and health works... sometimes. Basically I try to make the macro work by checking what the max health is first before drawing the bar at all in both the macro and in predraw. It checks if the max is 60 then draws that, but if the max is 90 it draws that instead. The max health pickup checks in the same way (if max is 60 then make the max 90) Everything checks what the HealthMax variable is, and in Predraw there is this:
Code:
thePlayerIsAlive:
	LDA Object_health,x
	STA temp3
		
letsGetThisHUDStarted:
	
	;; Draw the Health Bar
	DrawStatusBar #$08, #$18, temp3, #$2F, #$3F, #$4F, #$5F, #$6F, #%00000001
Which I ASSUME just checks what the player's health is and draws that, but the player isn't getting the health at all, which is why I think it's the health pickup? When the health max is raised the current amount of health moves down with it to the bottom of the bar, which makes me assume its working in that regard but maybe it isn't? I agree it's extremely convoluted and I could be missing something, but like I said I can't find a reason why it wouldn't just draw what the player's health is as the max is expanded, or why the Health pickups only work a few times with the original health bar then stop working at all even after the player has taken damage. So maybe I'm close? :lol:
 

dale_coop

Moderator
Staff member
My guess it the macro that draws hud that doesn't support your max health. But again, the code is too convoluted for me.
 

dale_coop

Moderator
Staff member
Oh, but I see a mistake in your increase health pickup script...
You wrote :
Code:
	LDA myHealth
	ADC #$0A
but forgot the:
Code:
	STA myHealth


So, the correct code should be:
Code:
	LDA myHealth
	CLC
	ADC #$0A
	STA myHealth

Could it be the issue? Not, really sure...
 

crazygrouptrio

Active member
dale_coop said:
Oh, but I see a mistake in your increase health pickup script...
You wrote :
Code:
	LDA myHealth
	ADC #$0A
but forgot the:
Code:
	STA myHealth


So, the correct code should be:
Code:
	LDA myHealth
	CLC
	ADC #$0A
	STA myHealth

Could it be the issue? Not, really sure...

Oh no a code thats too convoluted for Dale Coop that doesn't bode well for me :lol: but thank you for the health pickup fix! Whether it fixes it or not it was needed anyway. It it doesn't work I'll just move to my backup plan ;)
 

dale_coop

Moderator
Staff member
It's always difficult to work with someone else code... I'd need to spend hours on it, experiment how it works, and more important its limitations/issues.
Just by reading the code and joro's explanations, I already know it's hi level and has some issues.
I prefer use a simpler code for the sprite hud (coded by myself for the needs of the project I am working on). A small loop from 0 to maxhealth, and drawSprite a full tile or an empty tile when needed :p
 

crazygrouptrio

Active member
Oh for sure. What drew me to this method was how it works like an actual gauge rather than "pegs" of health.. even tho that's kind of how I'm using it :lol: but I also like how it handles smaller fractions of health by using less sprites on screen. But that's another option I could use in the future. :D
 

crazygrouptrio

Active member
dale_coop said:
So, the correct code should be:
Code:
	LDA myHealth
	CLC
	ADC #$0A
	STA myHealth

Could it be the issue? Not, really sure...

Yep this actually fixed it! It will take some trial and error to get the drawn life bar to match the actual amount of total life (it wouldnt go up all the way) but after picking up the max health upgrade it does heal to the new max amount. Can you believe I made it this far only to make that stupid of a mistake? :lol: The only bug I'm noticing is it won't heal to the new max until the player takes damage, which isn't really a problem since I really doubt the player will make it to this power up without having taking damage at least once... :lol: Thanks again!
 
Top Bottom