Computer Science Canada Check to see if a key is held down? |
Author: | bshennette [ 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.
Please specify what version of Turing you are using 4.1.1 |
Author: | Raknarg [ 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. |
Author: | Zren [ 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. |
Author: | bshennette [ 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. |
Author: | bshennette [ 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:
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) |
Author: | Tony [ 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 |
Author: | bshennette [ 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... |