Have a score in the sprite HUD 4.5.9 (metroVania, shooter, platform)

baardbi

Well-known member
If you want to have a score in your sprite HUD then there are a few steps we need to do before it can be displayed.

1. Create the following User Variables (make sure you create them in this order):

score000001
score000010
score000100
score001000
score010000
score100000

This will give you a score that can have a max value of 999999. Technically you can have two more values, but then you use all the sprite slots for that scan line, so if any sprite is on the same scan line they will disappear.

2. Copy these tiles from the HUD graphics (in the tutorial graphics folder), or make your own number graphics. Make sure the numbers are the first tiles in your GameObjectTiles.bmp file.
numbers.png

3. Put this code in your doDrawSpriteHud file:
;; Draw score

DrawSprite #16, #8, score100000, #%00000000
DrawSprite #24, #8, score010000, #%00000000
DrawSprite #32, #8, score001000, #%00000000
DrawSprite #40, #8, score000100, #%00000000
DrawSprite #48, #8, score000010, #%00000000
DrawSprite #56, #8, score000001, #%00000000
Your can adjust the position of the score by changing the first two numbers after DrawSprite. The first number is the X position and the second number is the Y position. The last part of the DrawSprite macro decides what palette to use:
%00000000: Sprite palette 0
%00000001: Sprite palette 1
%00000010: Sprite palette 2
%00000011: Sprite palette 3

4. Now your score will be displayed in the sprite HUD. To add a value to the score just use the AddValue macro:

AddValue arg0, arg1, arg2, arg3
;arg0 = how many places this value has.
;arg1 = home variable
;arg2 = amount to add
;arg3 = what place value is receiving the addition?

;;; 0 = ones place, 1 = tens place, 2 = hundreds place, etc.

This can be a little tricky at first, but here's an example of adding 100 to the score:

AddValue #6, score000001, #1, #2

You can put this code wherever you want. For example you could add it in the pickup script when you pick up a certain pickup object, or you could use it in the monsterHurt code (when a monster is killed).

5. Remember to reset the score when it's game over (or whenever you want to reset the score). You do this simply by adding this to (for example) your hurtPlayer file after +playerHealthIsZero:

;; Reset score

LDA #0
STA score000001
STA score000010
STA score000100
STA score001000
STA score010000
STA score100000

6. That's it.
 

latetera

Member
Thank you so much for your help @baardbi ! Your tutorials on the YouTube channel are very helpful. I also bought your game Nosey Joe a month ago or so, and it was a great time to play it. Thank you for all your help and dedication. Feels very warm to have a reply. My gratitude to you is enormous <3
 

baardbi

Well-known member
Thank you so much for your help @baardbi ! Your tutorials on the YouTube channel are very helpful. I also bought your game Nosey Joe a month ago or so, and it was a great time to play it. Thank you for all your help and dedication. Feels very warm to have a reply. My gratitude to you is enormous <3
That's great. You're very welcome. I'm happy that my tutorials are so helpful to you. I do a lot of experimenting with NESmaker, so I'll keep posting more videos whenever I get the time. And thank you for buying Nosey Joe :)
 

3DPLABox

Member
This works fantastically! I've put off doing my HUD forever because I couldn't get it working correctly, but this made it super easy. I modified this method a little bit to display the number of lives in my HUD too. Thanks for posting this!
 
Top Bottom