You can create a TIMER() so the key is only allowed to be pressed at a specific delay. With the TIMER() command 1 second = 1000. The following checks for the spacebar but only allows it every 500 milliseconds (half a second). To make it detect faster decrease the 500... to make it detect slower increase 500.
` Create a timer
tim=timer()
do
` Check for the spacebar every 500 milliseconds
if keystate(57) and timer()>tim+500
` Increase the number of times the spacebar has been hit counter
inc Count
` Show that the spacebar was detected
print "Spacebar Hit "+str$(Count)+" times."
` Reset timer
tim=timer()
endif
loop
Most of the time when we make a health bar we use a SPRITE to create it because it can be quickly stretched to the right percentage with the STRETCH SPRITE command.
hide mouse
` Define the starting health
MaxHealth=500
Health=MaxHealth
` Make a health bar background image
box 0,0,112,30
ink rgb(10,10,10),0
box 1,1,111,29
get image 2,0,0,112,30,1
` Make the health bar image
ink rgb(255,0,0),0
box 0,0,110,28
get image 1,0,0,110,28,1
` Create a timer
tim=timer()
ink rgb(255,255,255),0
do
` Show the health bar background
paste image 2,mousex()-1,mousey()-1,1
` Show the health bar
sprite 1,mousex(),mousey(),1
` Show the Health in text form
center text mousex()+55,mousey()+35,"Health "+str$(Health)+" / "+str$(MaxHealth)
` Show the health percentage (same variable for stretch sprite)
center text mousex()+55,mousey()+52,str$(HPercentage)+"% "+"Health Left"
` Check if the timer is up
if timer()>tim+100 and Health>0
` Decrease the health
dec Health
` Calculate the current health percentage (for stretch sprite)
HPercentage=(Health*100)/MaxHealth
` Stretch the sprite to the percentage of health left
stretch sprite 1,HPercentage,100
` Reset timer
tim=timer()
endif
` Check if the health is zero and reset to MaxHealth
if Health=0 then Health=MaxHealth
loop
