Sword/Item Display in HUD asm

Timwind

New member
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


Where'd I screw up?
 

MistSonata

Moderator
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".
 
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:
;; 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:
;;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:
 

clay

New member
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?
 
Top Bottom