Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Check to see if a key is held down?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bshennette




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: 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.
Zren




PostPosted: 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.
bshennette




PostPosted: 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.
bshennette




PostPosted: 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)
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
bshennette




PostPosted: 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...
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: