Mega Man-style Sprite HUD

User avatar
Mugi
Posts: 771
Joined: Thu Dec 27, 2018 8:30 pm

Re: Mega Man-style Sprite HUD

Post by Mugi » Mon Dec 31, 2018 12:53 am

i instantly got a "PC out of range" with this on routines/system/valuecounters.asm
is there other code you cleaned up to free space aside the hud code you linked at the beginning ?
what i have on my game is quite barebones atm, and can't really imagine i already ran out of space.

at any rate, i tried getting this to work with no luck, and same with the icarus hud that was posted here, that just made the game go full gray screen and print tons of garbage for almost a minute before showing up a corrupt game screen. not good.
i think i pretty much destroyed my codebase already by messing with the huds, time to clean up and restart. ^^;
"what are you up to?" "Oh, not much... just... Parallaxing"
- Raftronaut
User avatar
jorotroid
Posts: 234
Joined: Wed Aug 08, 2018 7:48 pm
Location: California
Contact:

Re: Mega Man-style Sprite HUD

Post by jorotroid » Mon Dec 31, 2018 2:43 am

Huh. I don't think I have seen "PC out of range" before. Usually it's "Value out of range" that I see when a bank is maxed out in memory. I'm not sure what the distinction is. What have you done so far with your game? Also what line does it say the error is on?
User avatar
cargo
Posts: 131
Joined: Mon Sep 03, 2018 4:34 am

Re: Mega Man-style Sprite HUD

Post by cargo » Mon Dec 31, 2018 7:32 am

Hello. Can you post a photo of the screen with this error you see?
User avatar
MistSonata
Posts: 315
Joined: Fri Feb 16, 2018 7:10 am

Re: Mega Man-style Sprite HUD

Post by MistSonata » Mon Dec 31, 2018 8:41 am

If you're getting "PC out of range" errors at valuecounters, then something has gone terribly wrong, because from what I understand that means that one of the scripts that's being included before valuecounters is so big that it's knocking several hundreds of lines of code out of the limits of what a bank can hold. You're not going to be able to remove enough stuff to fit whatever got added to your code without breaking the functionality of your game.

My recommendation would be to go back and try to find what you did before getting the error, you might've placed a chunk of code in the wrong place or maybe an error with the tool is causing a bunch of garbage code to be created. If you need further help, it might help us a lot if you put the demo.txt from your attempted export into a zip file and post it here so we can better see what might've happened.
User avatar
Mugi
Posts: 771
Joined: Thu Dec 27, 2018 8:30 pm

Re: Mega Man-style Sprite HUD

Post by Mugi » Mon Dec 31, 2018 9:46 am

edit: im sorry, im an idiot. I left the original post i wrote below, but here's what was wrong;
in my modified code i removed the quarter checks, but i didn't patch out the checkForHalf to move into drawHealthBar, instead it was still looking for "checkfor quarter"

Code: Select all

checkForHalf:
	LDA arg2
	AND #%10000000
	BEQ drawHealthBar ; <---- this was originally checkForQuarter
		;;;  Half Full
		LDA #$04
		STA temp2

now it does things, and drew lots of heads of my sprite to the screen. There is still the mystery of why the vanilla code doesnt fit into my rom, but i will deal with that if i ever need to. For now it appears to function.

-----------------------------------------------------------------------------------



I followed the instructions here to the spot for installing this, and tested it multiple times.

that said, i was able to get it to load and behave by removing the original hud code as was indicated on the opening post,
combined with toning this HUD code down to my own use (i removed the draw caps for bars, and checks for everything except full, half and empty bar.) I made it draw sideways and only display 2 bars of HP per sprite (as it was on shatterhand)
now it compiles just fine, aside that it's giving me a "unknown label" for DrawStatusBar now. but i dont really have hurt mechanics or player HP set up, yet so maybe it's that ?

the game was functioning as normally before i attempted to install this code, and reverting the changes described to install this will result in the game working again, so there is that.
i also tested both ways of installing this, by setting the macro in macros.asm, and by making my own macro, both ways function identically and do indicate that the macro is found and acnowledged (nothing of this works if the macro is not there.)

i can try and revert this back to the state of vanilla install to see if i can still reproduce the error at hand, or if you'd like jorotroid, i could send you the whole project base so you could see for yourself, if you're interested of seeing what broke.
i honest to god can't see any any error in backtracking my install steps here, and i did attempt it multiple times, always with identical results.

for reference, here's my modified macro, and predraw code:

Code: Select all

checkForSpriteHUDDraw:
LDA gameState				; We want only want to make the HUD in the main gameState
BNE drawingSpriteHud
RTS

drawingSpriteHud:
	LDX player1_object			; When the player is alive, player1_object == #$00, but 
	BEQ thePlayerIsAlive			; when dead, player1_object == #$FF, so we need to ensure
	LDA #$00				; #$00 gets passed in for the health value when the player	
	STA temp3				; when the player is dead.
	JMP letsGetThisHUDStarted

thePlayerIsAlive:
	LDA Object_health,x
	STA temp3
		
letsGetThisHUDStarted:
	;; Draw the Health Bar
	;DrawStatusBar #$08, #$18, temp3, #$2F, #$3F, #$4F, #$5F, #$6F, #%00000001

	RTS
the "DrawStatusBar" is commented out here for the health bar because like i said, now it compiles and works as it was, but uncommenting it will give me an "unknown label" error, so that's not good.

Code: Select all

MACRO DrawStatusBar arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8
	;; arg0 x position of bottom bar segment
	;; arg1 y position of bottom bar segment
	;; arg2 value bar is displaying
	;; arg3 location of empty graphic
	;; arg4 location of 1/4 graphic
	;; arg5 location of 1/2 graphic
	;; arg6 location of 3/4 graphic
	;; arg7 location of full graphic
	;; arg8 attribute data (bits 0 and 1 determine which palette is used)
	
		
	LDA #$00		
	STA temp2		;Number of full sprites
	STA temp1		;if there is a partial sprite and what is it
	LDA #$08		
	STA temp		;Number of empty sprites
		
		
	LDA arg2
	BEQ readyToDrawHealthBar
	AND #%11111000
	CMP #%11111000
	BNE checkForHalf
		;; Full
		LDA #$08
		STA temp2
		JMP drawHealthBar
		
checkForHalf:
	LDA arg2
	AND #%10000000
	BEQ checkForQuarter
		;;;  Half Full
		LDA #$04
		STA temp2
			

drawHealthBar:

		
	LDA temp		
	SEC
	SBC temp2		;Number of full sprites
	STA temp		;Number of empty sprites
	BEQ readyToDrawHealthBar	;If we only have full sprites, then we can go ahead and draw
	LDA temp1
	BEQ readyToDrawHealthBar	;Does an empty sprite need to be replaced with a partial sprite?
		DEC temp
			
readyToDrawHealthBar:
	LDX temp
	LDA arg0
	STA temp	;Now temp is the x position of drawing from bottom up
emptySpritesLoop:
	TXA
	BEQ partialSpriteDraw
	DrawSprite arg0, temp, arg3, arg8, spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset
		
	LDA temp
	CLC
	ADC #$08
	STA temp

	DEX
	JMP emptySpritesLoop
		
partialSpriteDraw:

	LDA temp1
	BEQ readyToDrawEmptyBars
	DrawSprite arg0, temp, temp1, arg8, spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset
		
	LDA temp
	CLC
	ADC #$08
	STA temp
		
		
		
readyToDrawEmptyBars:
	
	LDX temp2		;Loaded into X for iteration
		
		
fullSpritesLoop:
	TXA				;8
	BEQ doneWithHealthBar
	DrawSprite arg0, temp, arg7, arg8, spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset
		
	LDA temp
	CLC
	ADC #$08
	STA temp
		
	DEX
	JMP fullSpritesLoop
		
doneWithHealthBar:

ENDM
"what are you up to?" "Oh, not much... just... Parallaxing"
- Raftronaut
User avatar
MistSonata
Posts: 315
Joined: Fri Feb 16, 2018 7:10 am

Re: Mega Man-style Sprite HUD

Post by MistSonata » Mon Dec 31, 2018 8:39 pm

I'm not sure I understand how that put so much stuff out of range, but I'm glad you got it fixed. :)
User avatar
Mugi
Posts: 771
Joined: Thu Dec 27, 2018 8:30 pm

Re: Mega Man-style Sprite HUD

Post by Mugi » Mon Dec 31, 2018 9:28 pm

im not really sure either, but with a tiny bit of external help, i made everything work, and finished up the modifications.
i wont spam the thread any further with this, but i'll just throw a mention here if someone is interested of a variation.

what i created is a variation of this hud, that;

1) draws horizontally
2) counts up to 8 HP (first 4bits) instead of 256 HP by holding 2 HP per sprite and will draw full and half sprites accordingly (i made it after shatterhand, where you have 8 HP, and everything does 1 damage.)

the code is slightly more compact than jorotroids original, so if you dont have a need for a 256 HP and such, the variation consumes slightly less program space.

Image
"what are you up to?" "Oh, not much... just... Parallaxing"
- Raftronaut
User avatar
dale_coop
Posts: 4476
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Mega Man-style Sprite HUD

Post by dale_coop » Mon Dec 31, 2018 11:31 pm

Sounds great Mugi, congrats! I am interested in your version of the code, if you don't mind to share it (or in a new post).
-----
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
Mugi
Posts: 771
Joined: Thu Dec 27, 2018 8:30 pm

Re: Mega Man-style Sprite HUD

Post by Mugi » Tue Jan 01, 2019 9:54 am

sure thing, here you go.

predraw

Code: Select all

checkForSpriteHUDDraw:
LDA gameState				; We want only want to make the HUD in the main gameState
BNE drawingSpriteHud
RTS

drawingSpriteHud:

	;; Draws the health symbol at the left side of the bar
	DrawSprite #$08, #$E0, #$7C, #%00000001, spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset

	LDX player1_object			; When the player is alive, player1_object == #$00, but 
	BEQ thePlayerIsAlive			; when dead, player1_object == #$FF, so we need to ensure
	LDA #$00				; #$00 gets passed in for the health value when the player	
	STA temp3				; when the player is dead.
	JMP letsGetThisHUDStarted

thePlayerIsAlive:
	LDA Object_health,x
	STA temp3
		
letsGetThisHUDStarted:
	;; Draw the Health Bar
	DrawStatusBar #$18, #$E0, temp3, #$7F, #$11, #$7E, #$11, #$7D, #%00000001

	RTS
macro:

Code: Select all

MACRO DrawStatusBar arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8
	;; arg0 x position of bottom bar segment
	;; arg1 y position of bottom bar segment
	;; arg2 value bar is displaying
	;; arg3 location of empty graphic
	;; arg4 location of 1/4 graphic
	;; arg5 location of 1/2 graphic
	;; arg6 location of 3/4 graphic
	;; arg7 location of full graphic
	;; arg8 attribute data (bits 0 and 1 determine which palette is used)

	LDA #$00		
	STA temp2		;Number of full sprites
	STA temp1		;if there is a partial sprite and what is it
	LDA #$04		
	STA temp		;Number of empty sprites

	LDA arg2
	;see if health empty
	AND #%00001111
	BEQ readyToDrawHealthBar
	; store full sprite number
	LSR a
	STA temp2
	; no bit was left over
	BCC drawHealthBar
	; bit left over, our half sprite
	LDA arg5
	STA temp1

drawHealthBar:
	LDA temp		
	SEC
	SBC temp2		;Number of full sprites
	STA temp		;Number of empty sprites
	BEQ readyToDrawHealthBar	;If we only have full sprites, then we can go ahead and draw
	LDA temp1
	BEQ readyToDrawHealthBar	;Does an empty sprite need to be replaced with a partial sprite?
	DEC temp ;remove 1 empty sprite for partial

readyToDrawHealthBar:
	LDX temp2
	LDA arg0
	STA temp2	;Now temp2 is the x position of drawing from left to right

fullSpritesLoop:
	TXA
	BEQ partialSpriteDraw
	DrawSprite temp2, arg1, arg7, arg8, spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset

	LDA temp2
	CLC
	ADC #$08
	STA temp2

	DEX
	JMP fullSpritesLoop

partialSpriteDraw:
	LDA temp1
	BEQ readyToDrawEmptyBars
	DrawSprite temp2, arg1, temp1, arg8, spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset
		
	LDA temp2
	CLC
	ADC #$08
	STA temp2

readyToDrawEmptyBars:
	LDX temp		;Loaded into X for iteration
emptySpritesLoop:
	TXA
	BEQ doneWithHealthBar
	DrawSprite temp2, arg1, arg3, arg8, spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset
	inc spriteOffset
		
	LDA temp2
	CLC
	ADC #$08
	STA temp2

	DEX
	JMP emptySpritesLoop

doneWithHealthBar:

ENDM
how you use them is the same as jorotroid's original, you will have to set the macro as instructed.

it's not really that much different, aside that the predraw has less things as it only draws the life indicator (one sprite) as opposed to the 4 "caps" of the bars.
on the macro, the calculation to determine what to draw is much shorter due to simplified logic.

for tiles, you will need a life indicator sprite (8x8), and full, half and empty life bar tiles, i drew mine as 4x8 so that 2 blibs of HP displays in one sprite. this is what the script expects.


it is recommended to set the bar to the very top or very bottom of the screen due to the fact that it draws 5 sprites horizontally, so if it sits in an area of the screen where other sprites move, it will cause issues.
"what are you up to?" "Oh, not much... just... Parallaxing"
- Raftronaut
User avatar
dale_coop
Posts: 4476
Joined: Fri Feb 16, 2018 7:05 am
Location: France

Re: Mega Man-style Sprite HUD

Post by dale_coop » Tue Jan 01, 2019 11:57 am

Thank you Mugi, nice!
Will try your version too.
-----
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