Пример #1
0
  public Player() {
    PlayerLevel = 1;
    CurrentExp = 0;
    this.showPauseMenu = false;
    this.showTowerSelectMenu = false;
    this.placingTower = false;
    this.mouseButton0 = false;
    this.mouseButton1 = false;
    // Keeps track of if there was an interactive click this update cycle. If so
    // other mouse actions are blocked until both mouse buttons are not clicked
    this.mouseWait = true;

    // Setup towerUI
    TowerSelectUI = new UI();
    TowerSelectUI.addButton(
        "Towermenutitle",
        "towerselectbutton",
        TILE_SIZE,
        TILE_SIZE * 12); // Title bar, no functionality
    TowerSelectUI.addButton("Towercannonblue", "cannonbaseblue", TILE_SIZE * 1, TILE_SIZE * 13);

    CurrentTowerType = TowerType.CannonBlue;
    CurrentAOEType = AOEType.NULL;
    for (AOEType a : AOEType.values()) {
      a.resetCooldown(); // All AOEs are initially available
      a.incrementCooldown(a.cooldown);
    }

    Cash = 0; // These are modified when setup() is called
    Lives = 0;

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