Ejemplo n.º 1
0
  public void update() {
    for (AOEType a : AOEType.values()) {
      a.incrementCooldown(Delta());
    }
    if (showTowerSelectMenu) {
      TowerSelectUI.draw();
      UpdateButtons();
    }
    updateTowers();
    updateAOE();

    // Pick which style of placement drawing I like better, and use that one for both.
    if (placingTower) {
      Tower.PlacementDraw(
          CurrentTowerType, Mouse.getX(), (int) Math.floor(HEIGHT - Mouse.getY() - 1));
    }
    if (placingAOE) {
      CurrentAOEType.PlacementDraw(Mouse.getX(), (int) Math.floor(HEIGHT - Mouse.getY() - 1));
    }

    // Handle mouse input

    // Left Mouse was newly clicked
    if (Mouse.isButtonDown(0) && !mouseButton0 && !mouseWait) {
      if (placingTower) {
        placeTower();
      } else if (placingAOE && CurrentAOEType.cooldownComplete()) {
        placeAOE();
      } else if (!placingTower && !placingAOE) {
        setMenuTower();
      }
    }
    // Cancel tower or AOE placement or close tower menu by pressing right mouse
    if (Mouse.isButtonDown(1) && !mouseButton1 && !mouseWait) {
      placingTower = false;
      placingAOE = false;
      Tower.CloseMenu();
    }
    mouseButton0 = Mouse.isButtonDown(0);
    mouseButton1 = Mouse.isButtonDown(1);

    // Handle keyboard input

    while (Keyboard.next()) {
      // Toggle Pause and toggle pause menu
      if (Keyboard.getEventKey() == Keyboard.KEY_P && Keyboard.getEventKeyState()) {
        showPauseMenu = !showPauseMenu;
        Clock.Pause();
      }
      // Speed up and slow down time with arrow keys
      if (Keyboard.getEventKey() == Keyboard.KEY_RIGHT && Keyboard.getEventKeyState()) {
        Clock.ChangeMultiplier(0.2f);
      }
      if (Keyboard.getEventKey() == Keyboard.KEY_LEFT && Keyboard.getEventKeyState()) {
        Clock.ChangeMultiplier(-0.2f);
      }
      if (Keyboard.getEventKey() == Keyboard.KEY_UP && Keyboard.getEventKeyState()) {
        Clock.ResetMultiplier();
      }

      // Select and and begin placing towers

      // Open tower menu
      if (Keyboard.getEventKey() == Keyboard.KEY_T && Keyboard.getEventKeyState()) {
        showTowerSelectMenu = !showTowerSelectMenu;
      }
      // Hotkeys for tower selection
      if (Keyboard.getEventKey() == Keyboard.KEY_1 && Keyboard.getEventKeyState()) {
        selectTowerType(CannonBlue);
      }
      if (Keyboard.getEventKey() == Keyboard.KEY_2
          && Keyboard.getEventKeyState()
          && PlayerLevel >= TOWER_CANNONRED_UNLOCK) {
        selectTowerType(CannonRed);
      }
      if (Keyboard.getEventKey() == Keyboard.KEY_3
          && Keyboard.getEventKeyState()
          && PlayerLevel >= TOWER_ICE_UNLOCK) {
        selectTowerType(IceTower);
      }
      if (Keyboard.getEventKey() == Keyboard.KEY_4
          && Keyboard.getEventKeyState()
          && PlayerLevel >= TOWER_ROCKET_UNLOCK) {
        selectTowerType(RocketTower);
      }

      // Select and begin placing AOE

      if (Keyboard.getEventKey() == Keyboard.KEY_Q
          && Keyboard.getEventKeyState()
          && PlayerLevel >= AOE_FIRESTRIKE_UNLOCK) {
        selectAOEType(FireStrike);
      }
      if (Keyboard.getEventKey() == Keyboard.KEY_W
          && Keyboard.getEventKeyState()
          && PlayerLevel >= AOE_TOWERBUFF_UNLOCK) {
        selectAOEType(TowerBuff);
      }
      if (Keyboard.getEventKey() == Keyboard.KEY_E
          && Keyboard.getEventKeyState()
          && PlayerLevel >= AOE_SLOW_UNLOCK) {
        selectAOEType(Slow);
      }

      // Tower deletion
      if (Keyboard.getEventKey() == Keyboard.KEY_D && Keyboard.getEventKeyState()) {
        deleteTower();
      }

      // Tower upgrade
      if (Keyboard.getEventKey() == Keyboard.KEY_U && Keyboard.getEventKeyState()) {
        levelUpTower();
      }
    }
    // Keep waiting until both buttons are not down. May be changed
    // to have one for each button.
    mouseWait = (Mouse.isButtonDown(0) || Mouse.isButtonDown(1));
  }