Exemplo n.º 1
0
  @Override
  public void keyPressed(KeyEvent e) {
    // TODO Auto-generated method stub
    if (e.getKeyCode() == KeyEvent.VK_W) {
      this.hero.setDirection(0);
      hero.moveUp();
    } else if (e.getKeyCode() == KeyEvent.VK_D) {
      this.hero.setDirection(1);
      hero.moveRight();
    } else if (e.getKeyCode() == KeyEvent.VK_S) {
      this.hero.setDirection(2);
      hero.moveDown();
    } else if (e.getKeyCode() == KeyEvent.VK_A) {
      this.hero.setDirection(3);
      hero.moveLeft();
    }
    // 判断玩家是否按下J键 则开火
    if (e.getKeyCode() == KeyEvent.VK_J) {
      if (this.hero.bombs.size() <= 40) {

        hero.fire();
      }
    }
    this.repaint();
  }
Exemplo n.º 2
0
	public void keyPressed(KeyEvent arg0) {
		// TODO Auto-generated method stub
		int key =arg0.getKeyCode();
		if(key ==KeyEvent.VK_UP){
			hero1.moveUp();
		}
		else if(key ==KeyEvent.VK_DOWN){
			hero1.moveDown();
		}
		else if(key ==KeyEvent.VK_LEFT){
			hero1.moveLeft();
		}
		else if(key ==KeyEvent.VK_RIGHT){
			hero1.moveRight();
		}
		repaint();
	}
Exemplo n.º 3
0
 public void keyPressed(KeyEvent arg0) {
   int key = arg0.getKeyCode();
   if (key == KeyEvent.VK_UP) {
     girl.moveUp();
   } else {
     if (key == KeyEvent.VK_DOWN) {
       girl.moveDown();
     } else {
       if (key == KeyEvent.VK_RIGHT) {
         girl.moveRight();
       } else {
         if (key == KeyEvent.VK_LEFT) {
           girl.moveLeft();
         }
       }
     }
   }
   repaint();
 }