Pickups

Pwnu2noob

New member
I guess I need to go back through the tutorials but, how do I define what happens with a pickup?

For example, my player picks up a heart to increase health.

Currently I have my hud showing hearts that indicate my health and it goes down when colliding with an enemy. I've also created a pickup in the shape of a heart that I would like to increase my health by 1.

I was skimming through the HandleObjectCollisions script and found a section about pickups and there's JSR HandlePickupPowerup on line 234 but, I'm not finding this routine. Am I overlooking something or even on the right track?

Thanks!
 
I'm having general issues with pickups as well.

I could swear last night when I tried, I could pick up my key monsters, and this morning I can't. I was going to write a post about how picking up the key wasn't triggering my screen, but maybe I imagined the whole thing!

I'm still uncertain if it's better to use the Key pickup, or to set up a Monster group with a Key on it. I'll just keep working on graphics till a solution comes along, I guess!
 

dale_coop

Moderator
Staff member
I am not home today but...
You can assign script to Pickups game objects. In te projects settings, in scripts settings. Just assign a script to the power up lines. (There is a bunch of scripts for power ups in the folder)
 

Pwnu2noob

New member
Thanks Dale! That did the trick.

It doesn't update the HUD unless I switch screens. I'll have to play around with it a little bit and see if I can figure out why.

Thanks again! :)
 

dale_coop

Moderator
Staff member
For the HUD, you need to add a update HUD codes at the end of your PowerUp script :

Code:
;;; 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  ;;  <<--- HERE Your Pickup-related Variable
	STA DrawHudBytes
 

Pwnu2noob

New member
Got it!

I guess I need to spend a little time learning asm LOL! I noticed there was a commented out section about comparing the increase in health against a max health. I'm going to try and figure this out. I know the Game Object/Object Details/Details tab allows me to set an initial health amount which is great but, it doesn't seem to limit the amount of health (max health). However, I should be able to create a MaxHealth tag and possibly a currentMaxHealth tag. MaxHealth would be the overall maximum amount of health achievable in the game. currentMaxHealth could be a varying amount based on either the experience of the player or if certain items are found (think heart containers in the Legend of Zelda). Again, i'll have to learn some asm but, I would imagine the single health pickup-code would look something similar to:

IF myHealth < currentMaxHealth
inc myHealth
ELSE myHealth == currentMaxHealth ;;I was thinking this might prevent the game from ever surpassing the currentMaxHealth of the game?


I'm not really that great at code :lol:

Thoughts?
 

Pwnu2noob

New member
After a bit of reading up on asm I managed to get it working. Not sure if this is the correct way to do this but, I modified the Powerup_IncreaseHealth.asm file like this:

Code:
;;; Increase Health code for player.
;;; works with variable myHealth
;;; works with HUD variable HUD_myHealth.
	TXA
	STA tempx
	LDA myHealth
	CMP #05
	BCC notFull
	RTS
	;;;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.
	notFull:
	TXA
	STA tempx
	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
	
	LDX tempx

This way it checks against a set amount of 5 before increasing health. I figure the hardcoded value of 5 could be replaced with maxHealth or something like that. Thoughts?
 

dale_coop

Moderator
Staff member
Great! Thanks Pwnu2noob
It will be useful for sure.
Ue you could use a constant for the MaxHealth, or maybe use the one from the HUD variables...?
 

Pwnu2noob

New member
dale_coop said:
Great! Thanks Pwnu2noob
It will be useful for sure.
Ue you could use a constant for the MaxHealth, or maybe use the one from the HUD variables...?

That's what I was thinking! Maybe set a constant for MaxHealth say 16. Then I could set a variable called currentMaxHealth that can be changed depending on experience or some sort of item pickup. myHealth could be checked against currentMaxHealth and currentMaxHealth could be checked against MaxHealth.

I'll see what I can put together. :)
 
Top Bottom