Example #1
0
  private void updateRunning(List<TouchEvent> touchEvents, float deltaTime) {

    timePassed += deltaTime;

    for (TouchEvent event : touchEvents) {
      if (event.type == TouchEvent.TOUCH_DOWN) {

        if (event.x < buttonWidth) {
          player.moveLeft();
        } else if (event.x > buttonWidth + game.getGraphics().getHeight()) {
          player.moveRight();
        }
      }
    }

    if (!player.isAlive) {
      connection.write("LOST".getBytes());
      opponent.scored();
      if (opponent.getScore() == goal) {
        ((TronGame) game).saveLose();
        state = GameState.Loser;
      } else {
        countdown = 300.0f;
        state = GameState.Lose;
      }
    } else if (timePassed > 10.0) {
      player.update();
      grid.update(player);
      timePassed -= 10.0f;
    }
  }
Example #2
0
 @Override
 public void keyPressed(KeyEvent e) {
   int keyCode = e.getKeyCode();
   if (keyCode == KeyEvent.VK_UP) {
     player.moveUp();
   } else if (keyCode == KeyEvent.VK_DOWN) {
     player.moveDown(getHeight());
   } else if (keyCode == KeyEvent.VK_LEFT) {
     player.moveLeft();
   } else if (keyCode == KeyEvent.VK_RIGHT) {
     player.moveRight(getWidth());
   }
 }
 public void keyPressed(KeyEvent k) {
   int keycode = k.getKeyCode();
   switch (keycode) {
     case KeyEvent.VK_LEFT:
       player.moveLeft();
       break;
     case KeyEvent.VK_RIGHT:
       player.moveRight();
     case KeyEvent.VK_SPACE:
       player.water();
       break;
     case KeyEvent.VK_ENTER:
       player.plantSeed();
       pickupAudio.play();
       break;
   }
 }
  public void keyPressed(KeyEvent arg0) {

    // the controller should not do anything when the player is dead
    if (player.getLives() <= 0) {
      return;
    }
    String key = ("" + arg0.getKeyChar()).toLowerCase();

    if (key.equals("a")) {
      // move to the left
      player.moveLeft();
    }
    if (key.equals("d")) {
      // move to the right
      player.moveRight();
    }
    if (key.equals(" ")) {
      // shoot
      player.fire();
    }
  }
Example #5
0
  @Override
  public void keyPressed(KeyEvent e) {
    switch (e.getKeyCode()) {
      case KeyEvent.VK_UP:
        player.moveUp();
        break;

      case KeyEvent.VK_DOWN:
        player.moveDown();
        break;

      case KeyEvent.VK_LEFT:
        player.moveLeft();
        break;

      case KeyEvent.VK_RIGHT:
        player.moveRight();
        break;

      case KeyEvent.VK_SPACE:
        player.shoot();
        break;
    }
  }
  public void actionPerformed(ActionEvent a) {
    Object source = a.getSource();

    if (scene == OVERWORLD) {
      if (source == moveTimer) {
        if (moveUp && !moveDown) player.moveUp();
        else if (!moveUp && moveDown) player.moveDown();

        if (moveLeft && !moveRight) player.moveLeft();
        else if (!moveLeft && moveRight) player.moveRight();
      }

      if (source == itemsButton) itemsButton.setText("ITEMS!");
      else if (source == equipButton) equipButton.setText("EQUIPMENT!");
      else if (source == skillsButton) skillsButton.setText("SKILLS");
      else if (source == settingsButton) settingsButton.setText("SETTINGS");
      else if (source == statusButton) statusButton.setText("STATUS");
      else if (source == dataButton) dataButton.setText("DATA");
    }
    if (scene == BATTLE) {
      if (source == moveTimer) {
        // Spell Movement
        for (int spellNum = 0; spellNum < spellsThrown.size(); spellNum++) {
          Spell spell = spellsThrown.get(spellNum);
          spell.move();
          if (spell.spellHit()) {
            enemies.get(spell.getTarget()).takeDamage(spell.getDamage());
            enemies.get(spell.getTarget()).statusPresent(spell.getEffect());
            spellsThrown.remove(spellNum);
            checkEnemyPresence();
          }
        }

        for (int enemyLoop = 0; enemyLoop < enemies.size(); enemyLoop++) {
          Enemy enemy = enemies.get(enemyLoop);
          for (int spellNum = 0; spellNum < enemy.spellsThrown.size(); spellNum++) {
            Spell spell = enemy.spellsThrown.get(spellNum);
            spell.move();
            if (spell.spellHit()) {
              player.takeDamage(spell.getDamage());
              enemy.spellsThrown.remove(spellNum);
              checkAllyPresence();
            }
          }
        }
      }
      if (source == staminaTimer) {
        // Stamina Regeneration
        player.staminaGain(16);
        // Enemy Attacks
        int enemyLoop;
        for (enemyLoop = 0; enemyLoop < enemies.size(); enemyLoop++) {
          enemies.get(enemyLoop).attack(player.centerX(), player.centerY(), 12);
        }
      }
    }
    repaint();

    // To check collision
    if (scene == OVERWORLD) {
      for (int loop = 0; loop < enemies.size(); loop++) {
        Enemy enemy = enemies.get(loop);
        if (enemy.hitbox().intersects(player.hitbox())) {
          player.combatChange(true);
          enemy.combatChange(true);
          battleBegin();
        }
      }
    }
  }
Example #7
0
 public void move(Direction d) {
   if (d == Direction.RIGHT) moveRight();
   else if (d == Direction.LEFT) moveLeft();
   else if (d == Direction.UP) moveUp();
   else if (d == Direction.DOWN) moveDown();
 }