
-----------------------------------
bshennette
Wed May 18, 2011 7:55 pm

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.


%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

-----------------------------------
Raknarg
Wed May 18, 2011 8:04 pm

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.

-----------------------------------
Zren
Wed May 18, 2011 8:49 pm

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.

-----------------------------------
bshennette
Thu May 19, 2011 7:54 pm

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.

-----------------------------------
bshennette
Thu May 19, 2011 10:18 pm

Re: Check to see if a key is held down?
-----------------------------------
Came up with my own idea:



%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