Author |
Message |
hinaspins
|
Posted: Sun Jan 01, 2012 5:03 am Post subject: need help with spacebar and bombs in game |
|
|
What is it you are trying to achieve?
For everytime I click the spacebar I need it to take away a bomb on the screen
What is the problem you are having?
When I press spacebar it takes 10 away but because it's in a loop it keeps on taking 10 away really fast where I have it set up as 30=3 bombs 20=2 bombs 10=1 bomb 0=0 bombs.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
if KEY (' ')then
bomb:=bomb-10
end if
if bomb=20
drawfilloval(35,392,5,5,white)
end if
All I want it to do atm is take away the three circles on the top left corner of the screen everytime I press space
Please specify what version of Turing you are using
Turing 4.1.1
I'm sorry If I sound retarded, I'm new to this. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dreadnought
|
Posted: Sun Jan 01, 2012 11:48 am Post subject: Re: need help with spacebar and bombs in game |
|
|
Use a variable to remember if the spacebar was just pressed.
Depending on the type of behavior you want you can set this up differently. Say you want it to work like when you're typing at a computer. You want it to type on letter then wait before spamming that letter. If you store the time the spacebar was last pressed, you can check if its ok to remove bombs. If you want it to work only when you press the spacebar then reset when you release, then you can simply store the last state of the space bar (up or down) and then check if there was a change. |
|
|
|
|
|
Tony
|
Posted: Sun Jan 01, 2012 12:13 pm Post subject: RE:need help with spacebar and bombs in game |
|
|
to elaborate on Dreadnought's point -- a key has 4 states that it could be in:
up -- not being pressed (likely for a long time)
up-down -- the single moment the state transitions from up to down (also known as "on-click")
down -- is being pressed (could be held down for a long time)
down-up -- the single moment the state transitions from down to up (also known as "on-release")
In computer time, you holding down a key is "a long time". |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
evildaddy911
|
Posted: Sun Jan 01, 2012 1:16 pm Post subject: Re: need help with spacebar and bombs in game |
|
|
what i do is have a variable: space_pressed (boolean)
Turing: | if KEY (' ') and space_pressed=false then
space_pressed:=true
-
-
end if
if KEY (' ') =false then
space_pressed:=false
end if |
|
|
|
|
|
|
chipanpriest
|
Posted: Sun Jan 01, 2012 1:37 pm Post subject: Re: need help with spacebar and bombs in game |
|
|
Turing: | var ch : array char of boolean
Input.KeyDown (ch )
if ch (' ') then
shoot := true
end if
|
|
|
|
|
|
|
|