Use GFILL. Then when you lose health, decrement an amount from the length of GFILL. Since health will likely be 100 though and your GFILL coordinates will likely be entirely different, you should be able to figure out the math for that I'll let you figure that part out.
Refer to the following program.
ACLS:GPAGE 0,4:GFILL 0,0,15,15,#YELLOW
SPSET 0,0:SPOFS 0,150,200,0
SPSCALE 0,100/16,1
C=0:NHP=100:HP=100
WHILE TRUE
VSYNC 1
IF C==0 THEN NHP=RND(101)
C=(C+1)MOD 60
IF HP!=NHP THEN HP=HP+SGN(NHP-HP)
LOCATE 19,28,0
?FORMAT$("HP: %03D / 100",HP);
SPSCALE 0,HP/16,1
WEND
Remove "IF C==0 THEN..." and "C=(C+1)MOD 60".
And when you want to change the health, substitute any value for NHP (not HP) in the loop. HP (displayed health amount and length of the bar) will follow NHP in the loop.
Hi Clash, I made the game that you put on the screenshot.
'DEFINE a new sprite that display a pixel. This pixel is on the point 0,0 of the sprite sheet.
SPDEF 0,0,0,1,1
VAR HP,HPMAX
VAR spContainer,spBar
spContainer=SPSET(0)
spBar=SPSET(0)
HP=50
HPMAX=100;
SPSCALE spContainer,120,16
'This is important: Resize the life bar based on the current hp
SPSCALE spBar,120*(hp/hpMax),16
The code from above is a simple way to explain how to render the bar. On the game, the hp is on the player module while the code that handle the sprites are on other module that render the upper screen.
There is one thing that I didn't put on my last post.
'Change the color of the bar to yellow.
SPCOLOR spBar,&HFFEEF442
I guess that you didn't read this:
'DEFINE a new sprite that display a pixel. This pixel is on the point 0,0 of the sprite sheet.
You need to either load a GRP that has that pixel, use other coordinate with a white pixel or use the function GPSET to draw one.
Anyway, I made a small program with the HP Bar. KEY:[EXC443K4]