hey guys im making my first java game and everythign was going smoothly till i added the movements, player 1 moves with W and S (up and down obvs) and player 2 moves with up arrow and down arrow, when player 1 moves up or down he moves fine but when player too moves so down player one, i will post the code and can someone see if they can solve this ty
THIS IS FROM THE MAIN SCREEN
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_UP) {
player2up = true;
} else if(e.getKeyCode() == KeyEvent.VK_DOWN) {
player2down = true;
} else if(e.getKeyCode() == KeyEvent.VK_W) {
player1up = true;
} else if(e.getKeyCode() == KeyEvent.VK_S) {
player1down = true; }
}
@Override
public void keyReleased(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_UP) {
player2up = false;
} else if(e.getKeyCode() == KeyEvent.VK_DOWN) {
player2down = false;
} else if(e.getKeyCode() == KeyEvent.VK_W) {
player1up = false;
} else if(e.getKeyCode() == KeyEvent.VK_S) {
player1down = false; }
}
@Override
public void keyTyped(KeyEvent c) {
;
}
THIS IS FROM THE PLAYER FILE
@Override
void update(final shooter shooter, int id) {
if (id == 1) {
if(shooter.isPlayer1up()) {
if(!(ypos < 26)) {
ypos--;
}
} else if(shooter.isPlayer1down()) {
if(!(ypos > shooter.getHeight() -96)) {
ypos++;
}
}
} else if(id == 2) {}
if(shooter.isPlayer2up()) {
if(!(ypos < 26)) {
ypos--;
}
} else if(shooter.isPlayer2down()) {
if(!(ypos > shooter.getHeight() -96)) {
ypos++;
}
}