PowerUp Increase Health Not Working

Post Reply
User avatar
Winterbeast3
Posts: 7
Joined: Tue Jan 28, 2020 12:13 am
Location: York, PA

PowerUp Increase Health Not Working

Post by Winterbeast3 » Tue Feb 04, 2020 10:07 pm

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

;;; 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
User avatar
dale_coop
Posts: 4706
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: PowerUp Increase Health Not Working

Post by dale_coop » Wed Feb 05, 2020 9:19 am

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.
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
User avatar
Winterbeast3
Posts: 7
Joined: Tue Jan 28, 2020 12:13 am
Location: York, PA

Re: PowerUp Increase Health Not Working

Post by Winterbeast3 » Thu Feb 06, 2020 1:39 am

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
User avatar
dale_coop
Posts: 4706
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: PowerUp Increase Health Not Working

Post by dale_coop » Thu Feb 06, 2020 2:43 pm

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

			LDA #HUD_LOAD	
			AND #%01000000
			BEQ +
			STA hudElementTilesToLoad
And modify like this (adding a line of code):

Code: Select all

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

DoScreenOffHudUpdate:
	LDX player1_object
	LDA Object_health,x
	STA myHealth
And modify to be like this :

Code: Select all

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.
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
User avatar
Winterbeast3
Posts: 7
Joined: Tue Jan 28, 2020 12:13 am
Location: York, PA

Re: PowerUp Increase Health Not Working

Post by Winterbeast3 » Thu Feb 06, 2020 11:20 pm

Awesome it worked perfectly thanks again
User avatar
dale_coop
Posts: 4706
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: PowerUp Increase Health Not Working

Post by dale_coop » Fri Feb 07, 2020 7:28 am

Glad it worked :)
-----
Sorry about my poor english
All I need: A Damn Fine Cup of Coffee
My games: PRESS START GAME / UNDERGROUND ADVENTURE / UNDERGROUND ADVENTURE (Arcade version - Byte-Off-2019)
Post Reply