Vertical Sprite HUD (Health Bar) 4.5.9

baardbi

Well-known member
vertical.png

Here's a modified DrawSpriteHud macro that draws the health bar (or whatever) vertically. This can be very useful to reduce the number of sprites on a scan line.

The Y starting position is at the bottom of the health bar, so the Y coordinate will have to be much further down than usual. In the example above I use the following values:

X: 16
Y: 72

Code:
DrawSpriteHud #16, #72, #125, myMaxHealth, #126, myHealth, #%00000001  ;;;; this draws health

Here is the macro. You can replace the default macro with this:

Code:
MACRO DrawSpriteHud arg1, arg0, arg2, arg3, arg4, arg5, arg6
    ; arg0 = starting position in pixels, x
    ; arg1 = starting position in pixels, y
    ; arg2 = sprite to draw, CONTAINER
    ; arg3 = MAX 
    ; arg4 = sprite to draw, FILLED
    ; arg5 = variable.
    ; arg6 = attribute
  
    TYA
    PHA
    TXA
    PHA
  
    LDA arg5
    BEQ doneWithSpriteDrawElement ;; if the variable was zero, don't draw anything.
  
    LDA arg4
    STA temp ;; full
    LDA arg0
    STA temp2
  
    LDX #$00
    doDrawSpriteHudElementFullLoop:
        LDY spriteRamPointer
        ; LDA arg1
        LDA temp2
        STA SpriteRam,y
        INY
        LDA temp
        STA SpriteRam,y
        INY
        LDA arg6
        STA SpriteRam,y
        INY
        ; LDA temp2
        LDA arg1
        STA SpriteRam,y
        INY
  
        LDA spriteRamPointer
        CLC
        ADC #$04
        STA spriteRamPointer
        LDA temp2
        ; CLC
        ; ADC #$08
        SEC
        SBC #$08
        STA temp2
      
        INX
        CPX arg3 ;; is it to the max?
        BEQ doneWithSpriteDrawElement
            CPX arg5 ;; has it reached the fill point?
            BEQ changeToContainerSprite
                JMP doDrawSpriteHudElementFullLoop
            changeToContainerSprite:
          
                    ;; not done with sprite draw element, but now need to change to container
                    LDA arg2
                    STA temp
                    JMP doDrawSpriteHudElementFullLoop
            doneWithSpriteDrawElement:
      
      
      
      
    PLA
    TAX
    PLA
    TAY
    ENDM
 
Last edited:

mileco

Active member
View attachment 9218

Here's a modified DrawSpriteHud macro that draws the health bar (or whatever) vertically. This can be very useful to reduce the number of sprites on a scan line.

The Y starting position is at the bottom of the health bar, so the Y coordinate will have to be much further down than usual. In the example above I use the following values:

X: 16
Y: 72

Code:
DrawSpriteHud #16, #72, #125, myMaxHealth, #126, myHealth, #%00000001  ;;;; this draws health

Here is the macro. You can replace the default macro with this:

Code:
MACRO DrawSpriteHud arg1, arg0, arg2, arg3, arg4, arg5, arg6
    ; arg0 = starting position in pixels, x
    ; arg1 = starting position in pixels, y
    ; arg2 = sprite to draw, CONTAINER
    ; arg3 = MAX 
    ; arg4 = sprite to draw, FILLED
    ; arg5 = variable.
    ; arg6 = attribute
  
    TYA
    PHA
    TXA
    PHA
  
    LDA arg5
    BEQ doneWithSpriteDrawElement ;; if the variable was zero, don't draw anything.
  
    LDA arg4
    STA temp ;; full
    LDA arg0
    STA temp2
  
    LDX #$00
    doDrawSpriteHudElementFullLoop:
        LDY spriteRamPointer
        ; LDA arg1
        LDA temp2
        STA SpriteRam,y
        INY
        LDA temp
        STA SpriteRam,y
        INY
        LDA arg6
        STA SpriteRam,y
        INY
        ; LDA temp2
        LDA arg1
        STA SpriteRam,y
        INY
  
        LDA spriteRamPointer
        CLC
        ADC #$04
        STA spriteRamPointer
        LDA temp2
        ; CLC
        ; ADC #$08
        SEC
        SBC #$08
        STA temp2
      
        INX
        CPX arg3 ;; is it to the max?
        BEQ doneWithSpriteDrawElement
            CPX arg5 ;; has it reached the fill point?
            BEQ changeToContainerSprite
                JMP doDrawSpriteHudElementFullLoop
            changeToContainerSprite:
          
                    ;; not done with sprite draw element, but now need to change to container
                    LDA arg2
                    STA temp
                    JMP doDrawSpriteHudElementFullLoop
            doneWithSpriteDrawElement:
      
      
      
      
    PLA
    TAX
    PLA
    TAY
    ENDM
Thanks, this really useful! If we replace the macro with your code we could only do vertical bars only or both vert. and hor. health bars?
 

TheRetroBro

Active member
View attachment 9218

Here's a modified DrawSpriteHud macro that draws the health bar (or whatever) vertically. This can be very useful to reduce the number of sprites on a scan line.

The Y starting position is at the bottom of the health bar, so the Y coordinate will have to be much further down than usual. In the example above I use the following values:

X: 16
Y: 72

Code:
DrawSpriteHud #16, #72, #125, myMaxHealth, #126, myHealth, #%00000001  ;;;; this draws health

Here is the macro. You can replace the default macro with this:

Code:
MACRO DrawSpriteHud arg1, arg0, arg2, arg3, arg4, arg5, arg6
    ; arg0 = starting position in pixels, x
    ; arg1 = starting position in pixels, y
    ; arg2 = sprite to draw, CONTAINER
    ; arg3 = MAX
    ; arg4 = sprite to draw, FILLED
    ; arg5 = variable.
    ; arg6 = attribute
 
    TYA
    PHA
    TXA
    PHA
 
    LDA arg5
    BEQ doneWithSpriteDrawElement ;; if the variable was zero, don't draw anything.
 
    LDA arg4
    STA temp ;; full
    LDA arg0
    STA temp2
 
    LDX #$00
    doDrawSpriteHudElementFullLoop:
        LDY spriteRamPointer
        ; LDA arg1
        LDA temp2
        STA SpriteRam,y
        INY
        LDA temp
        STA SpriteRam,y
        INY
        LDA arg6
        STA SpriteRam,y
        INY
        ; LDA temp2
        LDA arg1
        STA SpriteRam,y
        INY
 
        LDA spriteRamPointer
        CLC
        ADC #$04
        STA spriteRamPointer
        LDA temp2
        ; CLC
        ; ADC #$08
        SEC
        SBC #$08
        STA temp2
     
        INX
        CPX arg3 ;; is it to the max?
        BEQ doneWithSpriteDrawElement
            CPX arg5 ;; has it reached the fill point?
            BEQ changeToContainerSprite
                JMP doDrawSpriteHudElementFullLoop
            changeToContainerSprite:
         
                    ;; not done with sprite draw element, but now need to change to container
                    LDA arg2
                    STA temp
                    JMP doDrawSpriteHudElementFullLoop
            doneWithSpriteDrawElement:
     
     
     
     
    PLA
    TAX
    PLA
    TAY
    ENDM
I did something similar for my boss health bar in my game where the health goes up to 60hp. Mine was ALOT more complicated so i may swap it out with this method which is much cleaner.
 

tbizzle

Well-known member
@baardbi , Is it possible to reverse the order in which the sprites draw and disappear? For instance, this macro will delete health starting from top to bottom. I'd like to switch it and have it delete the health from bottom up to the top.

****SOLVED:
You have to comment out
Code:
SEC
SBC #$08
Then uncomment
Code:
CLC
ADC #$08

 
Last edited:
Top Bottom