Example #1
0
  void inputListener() {
    if (keyboard.keyDown(KeyEvent.VK_W)) player.moveDir[1] = -1;
    else if (keyboard.keyDown(KeyEvent.VK_S)) player.moveDir[1] = 1;
    else player.moveDir[1] = 0;

    if (keyboard.keyDown(KeyEvent.VK_A)) player.moveDir[0] = -1;
    else if (keyboard.keyDown(KeyEvent.VK_D)) player.moveDir[0] = 1;
    else player.moveDir[0] = 0;

    if (keyboard.keyDown(KeyEvent.VK_1)) player.SetWeapon(1);
    if (keyboard.keyDown(KeyEvent.VK_2)) player.SetWeapon(2);
    if (keyboard.keyDown(KeyEvent.VK_3)) player.SetWeapon(3);
    if (keyboard.keyDown(KeyEvent.VK_4)) player.SetWeapon(4);
    if (keyboard.keyDown(KeyEvent.VK_5)) player.SetWeapon(5);
    if (keyboard.keyDown(KeyEvent.VK_6)) player.SetWeapon(6);
    if (keyboard.keyDown(KeyEvent.VK_7)) player.SetWeapon(7);
    if (keyboard.keyDown(KeyEvent.VK_8)) player.SetWeapon(8);
    if (keyboard.keyDown(KeyEvent.VK_9)) player.SetWeapon(9);

    if (keyboard.keyDownOnce(KeyEvent.VK_Z)) {
      if (showDebug) showDebug = false;
      else showDebug = true;
    }
    if (keyboard.keyDownOnce(KeyEvent.VK_F9)) {
      cheated = true;
      player.health = 1000000;
    }
    if (keyboard.keyDownOnce(KeyEvent.VK_F10)) {
      cheated = true;
      player.unlockWeapon(2, true);
      player.unlockWeapon(3, true);
      player.unlockWeapon(4, true);
    }
    if (keyboard.keyDownOnce(KeyEvent.VK_F11)) {
      cheated = true;
      player.upgradeWeapon(1, 1);
      player.upgradeWeapon(2, 1);
      player.upgradeWeapon(3, 1);
      player.upgradeWeapon(4, 1);
    }
    if (keyboard.keyDown(KeyEvent.VK_F12)) {
      cheated = true;
      player.score = (int) (player.score + 1 / delta);
    }

    if (keyboard.keyDownOnce(KeyEvent.VK_MINUS)) if (difficulty < 19) difficulty = difficulty + 1;
    if (keyboard.keyDownOnce(KeyEvent.VK_BACK_SLASH))
      if (difficulty > 1) difficulty = difficulty - 1;
    if (keyboard.keyDownOnce(KeyEvent.VK_ESCAPE)) paused = true;
    if (keyboard.keyDownOnce(KeyEvent.VK_M))
      if (removeMode) removeMode = false;
      else removeMode = true;

    if (mouse.buttonDown(1))
      player.Shoot(mouse.getPosition().getX() - xOffset, mouse.getPosition().getY() - yOffset);
  }
Example #2
0
  void playerHandeler() {

    inputListener();

    if (player.health <= 0) {
      player.isDead = true;
      if (cheated == false) newHighscore = setHighscore();
    }

    player.Update(xOffset, yOffset, delta);
    double[] pos = checkIfInsideBounds(player);
    player.body.setFrame(pos[0], pos[1], player.body.getWidth(), player.body.getHeight());

    int levelupDif = 10;
    double val = levelupDif;
    for (int i = 0; i < difficulty; i++) {
      val = val + val / levelupDif + levelupDif;
    }
    if (player.score > val) {
      if (difficulty < 19) {
        difficulty = difficulty + 1;

        int toUpgrade = 0;
        int curLev = 100;
        for (int i = 0; i < player.weapon.length; i++) {
          if (player.weapon[i][11] != null
              && (Boolean) player.weapon[i][11] == true
              && player.unlockedWeapons[i] == true) {
            if ((Integer) player.weapon[i][10] < curLev) {
              curLev = (Integer) player.weapon[i][10];
              toUpgrade = i;
            }
          }
        }
        if (curLev < 5 && curLev < difficulty / 2) {
          player.upgradeWeapon(toUpgrade, 1);
          player.newMessage(
              "Level up! The "
                  + player.weapon[toUpgrade][13]
                  + " was uppgraded to level "
                  + (curLev + 1),
              2000);
        }
      }
    }
  }