Posted: 8th Dec 2003 1:26
Here is an extremely dynamic healthbar function I came up with.

You can change every aspect of this healthbar simply by adjusting variables.

It is easy to understand, and easy to use. You may have to come up with your own conditions however to prevent some undesirable effects.

I included some additional code to show off how dynanmic and adjustable this healthbar really is.

This code can be adapted to any information that you would want to display on a bar graph.
Posted: 10th Dec 2003 2:04
I don't see any code

But I'm interested

Posted: 10th Dec 2003 3:59
Click the button that says source :p
Posted: 11th Dec 2003 23:21
How's this?

+ Code Snippet
max = 548
current = 394

DO
  drawHealthBar(1,1,100,20,current, max)
  sync
LOOP


function drawHealthBar(X, Y, LOB, WOB, CHP, MHP)
   REM X = X coordinate to position health bar at
   REM Y = Y coordinate to position health bar at
   REM LOB = length of health bar
   REM WOB = width of health bar
   REM CHP = current health points
   REM MHP = maximum health points

   if CHP < 0 then CHP = 0
   if CHP > MHP then CHP = MHP

   percent = (CHP*LOB)/MHP

   ink rgb(0,0,0), 0
   box X, Y, X+LOB, Y
   ink rgb(255,0,0), 0
   box X, Y, X+precent, Y+WOB

endfunction
Posted: 12th Dec 2003 0:33
I had to write something like that for my RTS, very good!
Posted: 30th Dec 2003 19:27
hmm....i tried both the healthbars there for my 3D game, but neither of them showed up. I followed the directions exactly and im not getting any errors there just not there??? here's a snippet. What am i doin wrong?

+ Code Snippet
Draw to Front
...
   rem Minimum, Maximum, and Current HP
   MinHP# = 0
   MaxHP# = 200
   CurHP# = 200

   rem How many pixels long do we want the bar
   pixlength = 500
   pixheight = 10

   rem XY location of bar on the display
   x = 275
   y = 30
...
do

   rem Update input data
   UpdateKeyHold()


   rem Display screen data
   set text size 22
   text 0, 0, "FPS: "+str$(screen FPS())
   text 0, 30, "Enemies Killed: "+str$(enemys_killed)

   UpdateFollowCamera()
   UpdatePlayer()
   healthbar(x,y,MinHP#,MaxHP#,CurHP#,pixlength,pixheight)

   UpdateEnemyAI()
   UpdateElevator()

   RunCollisionPRO()

   CheckExit()

   sync

loop
...
function healthbar(x as integer, y as integer, MinHP# as float, MaxHP# as float, CurHP# as float, pixlength as integer, pixheight as integer )
   rem The Math

   rem some conditions so that you don't go negative on certain values
   if CurHP# < MinHP# then CurHP# = MinHP#
   if CurHP# > MaxHP# then CurHP# = MaxHP#
   if pixlength < 1 then pixlength = 1
   if pixheight < 1 then pixheight = 1


   rem Change our values from Integers to a percent so that we can see how much of the bar needs to be filled
   pBar# = CurHP# / MaxHP#

   rem Get the percentage of the bar to be filled
   thebar = int(pixlength * pBar#)

   rem Draw the bar
   box x,y, x + thebar, y + pixheight
   line x + pixlength, y, x + pixlength, y + pixheight
   line x,y, x, y + pixheight

endfunction CurHP#
Posted: 31st Dec 2003 22:16
Yup, almost identical to what I'm using . Mine has X-Y-X2-Y2 though, and input for the for and background colors.
Posted: 31st Dec 2003 22:21
Oh, I see your has most of that-- was looking at the less complex one Phaelax posted. Nevermind.
Posted: 19th Jan 2004 4:59
Purpleheart,

Probably a little late to reply. I hardly check these boards.

I'm not sure why its not working for you.

sync makes the bar do wierd things. Its possible that if you remove the single the bar will be visible. You might move the function call right up under where you are displaying your text as something in the functions right above it might be cause the bar to behave oddly.

I would actually try using a image rather than the 2d commands when it comes down to it.
Posted: 16th Feb 2004 2:10
how would you go about using your healthbar for several different characters at once ralen, I'm trying to see if I could use yours in my rpg or develop one off it? I tried fooling with your code phaelax but it wouldn't work.
Posted: 18th Feb 2004 0:16
darn those dynamic variables!
I also found another mistake in my function. The first box that is drawn has no width, so it'll never show. You can tell I never tested my code. Ok, here's a tested, working function. And an example of how to use it with multiple units. You use an array. More customizable and easier with a type.

+ Code Snippet
sync on

type charHealth
   x
   y
   hp
   mp
endtype

dim char(10) as charHealth

for t=1 to 10
   char(t).x = rnd(540)
   char(t).y = rnd(460)
   char(t).hp = rnd(100)
   char(t).mp = 100
next t



DO
   for t=1 to 10
      drawHealthBar(char(t).x,char(t).y,100,10,char(t).hp, char(t).mp)
   next t


  sync
LOOP




function drawHealthBar(X, Y, LOB, WOB, CHP, MHP)
   REM X = X coordinate to position health bar at
   REM Y = Y coordinate to position health bar at
   REM LOB = length of health bar
   REM WOB = width of health bar
   REM CHP = current health points
   REM MHP = maximum health points

   if CHP < 0 then CHP = 0
   if CHP > MHP then CHP = MHP

   percent = (CHP*LOB)/MHP

   ink rgb(100,100,100), 0
   box X, Y, X+LOB, Y+WOB
   ink rgb(255,0,0), 0
   box X, Y, X+percent, Y+WOB

endfunction
Posted: 18th Feb 2004 2:46
can you provide a more detailed explanation into how you set it up and what the different things are for? no one ever seems to put much detail into explanations and I'd like to understand how to do it so I can do it on my own again without having to return to try to modify someone elses code for my own use.
Posted: 18th Feb 2004 10:16
Well the function should explain everything you need to know about it. You know what an array is?

+ Code Snippet
dim thing(10)

thing(1) = 145
thing(2) = 4561
thing(3) = 456
thing(4) = 8970
etc.....



The point?

so if you wanted to do something like lets say display the data in all those variables, you could easily do it like so:

+ Code Snippet
for t=1 to 10
  print thing(t)
next t


that's like saying

+ Code Snippet
print thing(1)
print thing(2)
print thing(3)
print thing(4)
print thing(5)


This thread is turning out to be not so code-snippet-like.