PowerUp Increase Health Not Working

Winterbeast3

New member
I am currently making a scrolling game and created a power up item. I have assigned the Powerup_IncreaseHealth script to PowerUp 00. If I'm hurt and collect the powerup I hear the sound but there is no change to my health. If I have full health and collect the power up I lose all my health but 1. Can someone let me know what I'm doing wrong?

Code:
;;; Increase Health code for player.
;;; works with variable myHealth
;;; works with HUD variable HUD_myHealth.
    LDA myHealth
    CLC
    ADC #$01
    CMP #$04
    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
    
    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
 

dale_coop

Moderator
Staff member
What is your default health value? ("3"?)
Check your HUD variables, make sure the myHealth initial value is "3".
Check your "Player" object's details and make sure his Health is "3".
The script should work with those default values.

IF your default health max is not "3", for example, if it's "6", you'll have to modifiy the script, line 7... currenlty, the health is compared to 4 ("CMP $04") because the health max is "3". If your max ir 6, that line should be "CMP #$07".

I hope it will healp.
 

Winterbeast3

New member
Thank you for the response.
The change on line 7 fixed my getting health problem however when my health is full it still goes to 1. I looked and tried so many different things and understand what the beginning of the script is saying, but it never skips the getting health section like it should.

I think I'm onto something when I turn on the game I tried getting hit by a monster then continued collecting hearts and it works perfect. As long as I lose 1 health I can keep collecting and it will never go over.

So why if I collect a heath after starting the game before I'm hurt does it go over and back to 1?

Player object health 5
Hudvar max 5
Hud initial 5
CMP #$06
 

dale_coop

Moderator
Staff member
Oh I see, ...
In the default "BASE_something" modules, there is a "bug" with the health when starting the game. The health hud is incorrect in the first screen loaded (when your player moves to another screen, the health displayes correctly).

To fix that issue:
1/ modify the "HandleUpdateObjects.asm" script (in the "Basic\System\" folder), around line 193, locate those lines:
Code:
			LDA #HUD_LOAD	
			AND #%01000000
			BEQ +
			STA hudElementTilesToLoad
And modify like this (adding a line of code):
Code:
			LDA #HUD_LOAD	
			AND #%01000000
			BEQ +
			LDA myHealth	;;HERE <-------- fix to start with the correct hud health
			STA hudElementTilesToLoad

2/ Modify the script assigned to the "Hud Element 0" element in your "Project Settings > Script Settings" (it should be the HUD_Element_Var_Image.asm script), around line 12, locate those this block of code:
Code:
DoScreenOffHudUpdate:
	LDX player1_object
	LDA Object_health,x
	STA myHealth
And modify to be like this :
Code:
DoScreenOffHudUpdate:
	; LDX player1_object 	;; commented out !
	; LDA Object_health,x	;; commented out !
  	; STA myHealth	;; commented out !
	LDA myHealth	;;dale_coop: fix to start with the correct hud health

This should fix your issue.
 
Top Bottom