Пример #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();
  }