Example #1
0
 @Override
 public void keyPressed(KeyEvent e) {
   if (e.getKeyCode() == KeyEvent.VK_W) {
     p.moveUp();
   } else if (e.getKeyCode() == KeyEvent.VK_A) {
     p.moveLeft();
   } else if (e.getKeyCode() == KeyEvent.VK_D) {
     p.moveRight();
   } else if (e.getKeyCode() == KeyEvent.VK_S) {
     p.moveDown();
   }
 }
Example #2
0
 public void keyReleased(KeyEvent e) {
   p.stopMovement();
 }
Example #3
0
 public void paintComponent(Graphics g) {
   g.drawImage(bg, 0, 0, getWidth(), getHeight(), this);
   p.render(g);
   repaint();
 }