TGC Codebase Backup



Basic Health Bar by MikeS

23rd Nov 2003 13:58
Summary

This is a Basic health bar.(Or power/magic/ammo/etc.) Same 2D principles can be applied to anything that needs to grow/decrease in value on your 2D screen.



Description

This is a Basic health bar.(Or power/magic/ammo/etc.) Same 2D principles can be applied to anything that needs to grow/decrease in value on your 2D screen.Use 1 and 2 to increase/decrease values.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `This sets up your screen refresh rate
sync on : sync rate 60
backdrop on : color backdrop 60
set text size 24
ink rgb(255,255,255),1

`This is your variable that you'll use for your health box
H=1

do

`This is the health box used to increase/decrease
`H is your variable. Basically, when you add to H, the box grows and when you subtract, it decreases.
box 10,20,H,30

`It wouldn't be fair to have a million+ health.
`So now we add some control factors
If H >100
H=H-0.01
endif

`Now, it's not necessary to have this function, but we can limit the minimum health to 0 in the same way
If H<0
H=H+0.01
endif

`Now we make our test function, to make sure the box works.
`(Press 1 to add health)
If keystate(2)=1
`This makes H equal H+1
H=H+1
endif
`This is the subtraction of health.(for testing purposes)
`(Press 2 to decrease health)
If keystate(3)=1
H=H-1
endif

`You can also add more advanved features to your health bar. Simple, but effective
`((int(H/1))*1) This line is used to round your health to the nearest 1's place.
set cursor 5,30
print "Health "+str$((int(H/1))*1)


sync
loop