I'm programming a game in java that has two players on the same keyboard. If one of the players is holding their forward button and the second player presses his forward button the first player is stopped. This happens the other way around too and I'm not sure how to fix it.
addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
paddle.keyPressed(e);
paddletwo.keyPressed(e);
}
@Override
public void keyReleased(KeyEvent e) {
paddle.keyReleased(e);
paddletwo.keyReleased(e);
}
In each paddle class I also have this:
public void keyReleased (KeyEvent e) {
ya = 0;
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_UP)
ya = -pong.speed;
if(e.getKeyCode() == KeyEvent.VK_DOWN)
ya = pong.speed;
}
Player two uses VK_W and VK_S instead of UP and DOWN.