Skip to main content
gamedev.net
🔒 Locked

[java] KeyListners for a Multiplayer game

Started by zubatzu Feb 23, 2007 at 2:18 PM 1 replies 650+ views
Original Post
zubatzu
zubatzu
Hey im makin pong game and so far so good but im having a problem. when player 1 is pressing a button player2 cant press a button until player1 has stopped.I want it so they can both press buttons and move at the same time can someone help me with that.
Maxamor
Maxamor
Can you supply some of your source code?

How are you listening to the key currently?
CrewNick
CrewNick
you need to make your own key handler (I know... sounds scary, but it's not).
It needs to do the following:

public class MyKeyHandler implements KeyListener
{
boolean pressed[256]; //assuming a standard char set for now

public void keyPressed(KeyEvent e)
{
pressed[e.getKeyCode] = true;
}

public void keyReleased(KeyEvent e)
{
pressed[256] = false;
}

public void CheckKeys()
{
if(pressed[])
{
//add your code here
}
if(pressed[])
{
//add your code here
}
//and so on.
}
}

I'm assuming you have a thread running to update your screen on even intervals. In the thread's Run loop, call MyKeyHandler.CheckKeys().

Does this help at all?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.