Exemplo n.º 1
0
  protected void update() {
    if (!isPaused) {

      if (tutorialOnGoing) tutorial.update();

      // Remove random particles if there are too many
      while (particles.size >= PARTICLE_LIMIT) particles.removeIndex(rand.nextInt(particles.size));

      // Remove random orbs if there are too many
      while (orbs.size >= ORB_LIMIT) orbs.removeIndex(rand.nextInt(orbs.size));

      // Adding played time
      if (!gameMode.isGameOver()) ticks++;

      // Updating combos
      cs.update();

      BoardShock.update();

      if (scoreMultiplier > 1) {
        if (scoreMultiplierTimer < MULTIPLIER_COOLDOWN_TIME) {
          float decreaseRate = (float) scoreMultiplier / 3;

          scoreMultiplierTimer += decreaseRate;
        } else {
          if (isSoundEnabled())
            multiplierDownSound.play(1f, (float) Math.sqrt(scoreMultiplier / 3), 0);

          scoreMultiplierTimer = 0;
          scoreMultiplier--;
        }
      }

      if (cs.getCombo() > 7) {
        if (isSoundEnabled()) multiplierUpSound.play(1f, (float) Math.sqrt(scoreMultiplier / 3), 0);

        setScoreMultiplier(scoreMultiplier + 1);
        if (getScoreMultiplier() % 10 == 0) {
          multiplierFont.scale(2);
        }

        cs.resetCombo();
      }

      if (multiplierFont.getScaleX() > 1) {
        multiplierFont.scale(-0.05f);
        if (multiplierFont.getScaleX() <= 1) {
          multiplierFont.setScale(1);
        }
      }

      boolean playerKilled = false; // A variable to keep track of player status
      if (!gameMode.isGameOver()) {
        // Update game mode, enemy spawning and player hit detection
        gameMode.update(TICK_LENGTH / 1000000);

        if (!tutorialOnGoing) {
          // Update power-ups
          powerUpSpawnTime--;
          if (powerUpSpawnTime < 0) {
            if (enablePowerUps) {
              puss.spawn();
              powerUpSpawnTime = 300;
            }
          }
        }

        updateHitDetections();

        // So that they don't spawn while death animation is playing
        if (!player.isDying() && !player.isSpawning()) {
          if (player.isDead() && !tutorialOnGoing) {
            pss.spawn(true);
            waveNumber++;
            currentWave = waveManager.getWave(waveNumber);
          } else {
            player.updateHitDetection();
            if (!tutorialOnGoing) {
              if (currentWave.update()) {
                waveNumber++;
                currentWave = waveManager.getWave(waveNumber);
              }
            }
          }
        }

        if (player.update() && !player.isDying()) {
          if (!tutorialOnGoing) {
            gameMode.playerKilled();
            playerKilled = true;
          }
        }
      } else {
        clearLists();
        gameOverTicks++;
      }

      // Removing destroyed entities
      for (Iterator<Entity> it = entities.iterator(); it.hasNext(); ) {
        Entity ent = it.next();
        if (ent.update()) {
          if (ent instanceof Particle) pass.getPool().free((Particle) ent);
          else if (ent instanceof UpgradeOrb) oss.getPool().free((UpgradeOrb) ent);
          else if (ent instanceof Enemy) enemies.removeIndex(enemies.indexOf((Enemy) ent, true));
          else if (ent instanceof PowerUp)
            powerups.removeIndex(powerups.indexOf((PowerUp) ent, true));
          else if (ent instanceof Bullet) {
            bullets.removeIndex(bullets.indexOf((Bullet) ent, true));
            Bullet.free((Bullet) ent);
          }

          it.remove();
        }
      }

      for (Iterator<UpgradeOrb> it = orbs.iterator(); it.hasNext(); ) {
        if (it.next().update()) it.remove();
      }

      for (Iterator<Particle> it = particles.iterator(); it.hasNext(); ) {
        if (it.next().update()) it.remove();
      }
      // Enemy Slowdown
      SlowdownEnemies.setUpdatedSlowdown(false);

      if (playerKilled && tutorialHasEnded()) {
        if (!gameMode.isGameOver()) {
          clearLists();
          resetGameTime();
          pss.spawn(false);
        } else {
          saveStats();
          input.setInputProcessor(ggInputProcessor);
          gameOverScoreFont.scale(14);

          if (Specular.nativeAndroid.isLoggedIn()) {
            Specular.nativeAndroid.postHighscore(player.getScore(), true);
          }
        }
      }

      Camera.update(this);
    }
  }
Exemplo n.º 2
0
 public void boardshock() {
   if (boardshockCharge >= 1 && !player.isDying() && !player.isSpawning()) {
     BoardShock.activate(this);
     boardshockCharge = 0;
   }
 }