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?
My health works in increments of 10, so its very possible I'm adding 10 wrong, but the fact its unreliably working is strange.
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:
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
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: