public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); for (Entity en : MarioBros.control.entity) { if (en.getId() == Id.Jugador) { switch (key) { case KeyEvent.VK_W: en.setVely(-4); if (!en.saltando) { en.saltando = true; en.gravedad = 5.0; } break; case KeyEvent.VK_A: en.setVelx(-5); en.caras = 1; break; case KeyEvent.VK_D: en.setVelx(5); en.caras = 0; break; } } } }
public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); for (Entity en : MarioBros.control.entity) { if (en.getId() == Id.Jugador) { switch (key) { case KeyEvent.VK_W: en.setVely(0); break; case KeyEvent.VK_A: en.setVelx(0); break; case KeyEvent.VK_D: en.setVelx(0); break; case KeyEvent.VK_S: en.setVely(0); break; } } } }