Be a Supporter!

May someone please help me?

  • 180 Views
  • 2 Replies
New Topic Respond to this Topic
thebreadandbutter
thebreadandbutter
  • Member since: Dec. 26, 2012
  • Offline.
Forum Stats
Member
Level 14
Animator
May someone please help me? 2013-07-13 04:19:25 Reply

I am making a fighting game and I want to know how I would make it so when you hold down 2 keys it'll do another move
for example I have made it so by pressing S you can grab a knife but I want the player to be able to throw said knife by pressing both S and D(same time) , how would I do this?

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to May someone please help me? 2013-07-13 09:55:59 Reply

Check if a key has been pressed just like you are now but instead check if two keys are down instead of one. You would probably want to allow something like 10-20 milliseconds to pass before treating the keys as "down" because it's unlikely that the player would press down two keys at precisely the same time.

Here's some psuedocode:

do message loop:
    if event is keyboard event:
        keys_down.push(event.key)
    if event is time event and time passed since previous update is 10 ms:
        if keys_down is ["S"]:
            player.grab("knife")
        if keys_down is ["S", "D"]:
            player.throw("knife")
thebreadandbutter
thebreadandbutter
  • Member since: Dec. 26, 2012
  • Offline.
Forum Stats
Member
Level 14
Animator
Response to May someone please help me? 2013-07-13 13:49:06 Reply

THANK YOU SO MUCH :D

Here's some psuedocode:

do message loop:
if event is keyboard event:
keys_down.push(event.key)
if event is time event and time passed since previous update is 10 ms:
if keys_down is ["S"]:
player.grab("knife")
if keys_down is ["S", "D"]:
player.throw("knife")