Sword/Item Display in HUD asm

Here is the link to the wedNESday tutorial for making an Adventure game. Done something cool with it? Modified it in some way? Want to ask the community about creating additional features for it? Post things Adventure Module here!
Post Reply
Timwind
Posts: 4
Joined: Sun Oct 07, 2018 10:06 pm

Sword/Item Display in HUD asm

Post by Timwind » Mon Oct 22, 2018 1:38 am

Hey,

So I'm following through in the adventure tutorial on youtube and it got to the part about putting brackets around the icon of the sword and crystal. The tutorial shows him opening the 'Handle Sprite Pre-Draw' Script, and it looked different than mine. I'm not sure if the code was added pre-video and I just can't see it as a download anywhere. I used the Adventure module that you download with the tutorial.

This is what mine says:

;; sprite pre-draw
;;; this will allow a user to draw sprites
;;; before object sprites are drawn.
;;; keep in mind, there are still only 64 sprites
;;; that can be drawn on a screen,
;;; and still only 8 per scan line!

;;; you can use DrawSprite macro directly using the following scheme:
;DrawSprite arg0, arg1, arg2, arg3, arg4
;arg0 = x
;arg1 = y
;arg2 = chr table value
;arg3 = attribute data
;arg3 = starting ram position

;; x and y are the direct positions on the screen in pixels.
;; chr table value is which sprite you'd like to draw from the ppu table.
;; attribute data is a binary number (starts with #%), and here are how the bits work:
;;; bit 7 - Flip sprite vertically
;;; bit 6 - Flip sprite horizontally
;;; bit 5 - priority (0 in front of background, 1 behind background)
;;; bit 4,3,2 - (null)
;;; bit 1,0 - subpalette used (00, 01, 10, 11)


;;; for starting ram position, use spriteOffset.
;; this is set to 0 just before entering this script (or 4 if sprite 0 hit was used).
;; ***remember to increase spriteOffset by 4 for every sprite that is drawn,
;; including after the last one drawn*****, so that the first object's sprite begins
;; in the next available spot.

This is what I tried to add based on what I could see in the video:

;;EXAMPLE:
;; DrawSprite #$80, #$80, #$10, #%00000000, spriteoffset
;; inc spriteOffset
;; inc spriteOffset
;; inc spriteOffset
;; inc spriteOffset
LDA weaponsunlocked
AND #%00000001
BEQ skipDrawingSwordInHud
;;; now, we would be ready for our next sprite.
DrawSprite #$74, #$14, #$2c, #%00000001, spriteoffset
inc spriteoffset
inc spriteoffset
inc spriteoffset
inc spriteoffset

skipDrawingSwordInHud:
LDA weaponsUnlocked
AND #%00000010
BEQ skipDrawingItemInHud
DrawSprite #$8c, #$14, #$29, #%00000001, spriteoffset
inc spriteoffset
inc spriteoffset
inc spriteoffset
inc spriteoffset
skipDrawingItemInHud:


This is the compiling error i receive:
comperror01.png
comperror01.png (21.34 KiB) Viewed 2561 times

Where'd I screw up?
User avatar
MistSonata
Posts: 315
Joined: Fri Feb 16, 2018 7:10 am

Re: Sword/Item Display in HUD asm

Post by MistSonata » Mon Oct 22, 2018 3:18 am

Variables are case sensitive, and a lot of your code is spelling the "spriteOffset" variable with a lowercase "o". Change them all to "spriteOffset", and that should solve most of those errors.

Edit: Same for "weaponsUnlocked".
throwawayaccount1235
Posts: 32
Joined: Wed Sep 05, 2018 3:05 pm

Re: Sword/Item Display in HUD asm

Post by throwawayaccount1235 » Mon Oct 22, 2018 3:24 pm

Hello timwind!

You can use [­code] your code [­/code] to display code. It makes it a bit easier to read. You'll find the code button above the text field. It's the blue button with </> in it.

Code: Select all

;; sprite pre-draw
;;; this will allow a user to draw sprites
;;; before object sprites are drawn.
;;; keep in mind, there are still only 64 sprites
;;; that can be drawn on a screen, 
;;; and still only 8 per scan line!

;;; you can use DrawSprite macro directly using the following scheme:
;DrawSprite arg0, arg1, arg2, arg3, arg4
;arg0 = x
;arg1 = y
;arg2 = chr table value
;arg3 = attribute data
;arg3 = starting ram position

;; x and y are the direct positions on the screen in pixels.
;; chr table value is which sprite you'd like to draw from the ppu table.
;; attribute data is a binary number (starts with #%), and here are how the bits work:
;;; bit 7 - Flip sprite vertically
;;; bit 6 - Flip sprite horizontally
;;; bit 5 - priority (0 in front of background, 1 behind background)
;;; bit 4,3,2 - (null)
;;; bit 1,0 - subpalette used (00, 01, 10, 11)


;;; for starting ram position, use spriteOffset.
;; this is set to 0 just before entering this script (or 4 if sprite 0 hit was used).
;; ***remember to increase spriteOffset by 4 for every sprite that is drawn,
;; including after the last one drawn*****, so that the first object's sprite begins
;; in the next available spot.
This is what I tried to add based on what I could see in the video:

Code: Select all

;;EXAMPLE:
;; DrawSprite #$80, #$80, #$10, #%00000000, spriteoffset
;; inc spriteOffset
;; inc spriteOffset
;; inc spriteOffset
;; inc spriteOffset
LDA weaponsunlocked
AND #%00000001
BEQ skipDrawingSwordInHud
;;; now, we would be ready for our next sprite. 
DrawSprite #$74, #$14, #$2c, #%00000001, spriteoffset
inc spriteoffset
inc spriteoffset
inc spriteoffset
inc spriteoffset

skipDrawingSwordInHud:
LDA weaponsUnlocked
AND #%00000010
BEQ skipDrawingItemInHud
DrawSprite #$8c, #$14, #$29, #%00000001, spriteoffset
inc spriteoffset
inc spriteoffset
inc spriteoffset
inc spriteoffset
skipDrawingItemInHud:
Timwind
Posts: 4
Joined: Sun Oct 07, 2018 10:06 pm

Re: Sword/Item Display in HUD asm

Post by Timwind » Mon Oct 22, 2018 6:19 pm

Thanks to both of you!! I assumed it must have been something I was just glazing over at 2 am.
clay
Posts: 9
Joined: Wed Aug 14, 2019 4:21 am

Re: Sword/Item Display in HUD asm

Post by clay » Thu Aug 22, 2019 3:00 am

Hi all. I'm using this for my HUD as well. It looks great until I go into the Underworld. Then, the HUD disappears. It reappears again once I'm back in the Overworld. Any ideas on how to improve this?
Post Reply