Author |
Message |
bshennette
|
Posted: Wed May 18, 2011 7:55 pm Post subject: Check to see if a key is held down? |
|
|
How would one go about this?
For a game I'm making, I need to be able to make the character have 2 jump heights. What I had hoped to do was have pressing the key quickly be a small jump, and holding down the key be a large jump. Any form of checking to see if the key is held down would be fine.
If anyone could help me with this that would be great.
Turing: |
%My Movement codes.
Input.KeyDown (chars )
if chars ('a') then
xv - = 1
elsif chars ('d') then
xv + = 1
end if
if chars ('w') and ground = true then
yv + = 10
end if
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Wed May 18, 2011 8:04 pm Post subject: RE:Check to see if a key is held down? |
|
|
hmm... Well, I would use a counter. Have it start when the user clicks a key. When they let go, if the counter is within a certain range, perfom an action. |
|
|
|
|
![](images/spacer.gif) |
Zren
![](http://compsci.ca/v3/uploads/user_avatars/1110053965512db6185954b.png)
|
Posted: Wed May 18, 2011 8:49 pm Post subject: RE:Check to see if a key is held down? |
|
|
Why not use acceleration?
Pressing Jump at the start of a jump (when standing on ground), your acceleration is set.
While in air, the acceleration decreases (due to gravity). Holding onto jump would lessen gravity's effect, say a -=0.1 versus -=0.5 per frame. |
|
|
|
|
![](images/spacer.gif) |
bshennette
|
Posted: Thu May 19, 2011 7:54 pm Post subject: Re: Check to see if a key is held down? |
|
|
I don't think a counter would work, because I can't use delays or else the rest of the program will stop running too.
Ill try Zren's idea. |
|
|
|
|
![](images/spacer.gif) |
bshennette
|
Posted: Thu May 19, 2011 10:18 pm Post subject: Re: Check to see if a key is held down? |
|
|
Came up with my own idea:
Turing: |
%Movement setup.
Input.KeyDown (chars )
if chars ('a') then
xv - = 1
elsif chars ('d') then
xv + = 1
end if
if chars ('w') and ground = true then
yv + = 5
end if
if chars ('w') and y2 < 100 then
yv + = 1
end if
|
Just pressing makes a jump like 58, holding is 58<jump<140 depending on how long you hold it. (These are not accurately measured numbers, but rather approximations) |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Thu May 19, 2011 10:27 pm Post subject: RE:Check to see if a key is held down? |
|
|
An interesting side effect is that if one continues to hold 'w' for the entire jump, the fall (below the height of 100) will slow down as well ![Wink Wink](http://compsci.ca/v3/images/smiles/icon_wink.gif) |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
bshennette
|
Posted: Fri May 20, 2011 12:56 am Post subject: Re: Check to see if a key is held down? |
|
|
It doesn't seem to noticably for me... |
|
|
|
|
![](images/spacer.gif) |
|