示例#1
0
  /** Total reset */
  public void reset() {
    clearLists();

    ticks = 0;
    gameOverTicks = 0;

    soundEffects = !Specular.prefs.getBoolean("SoundsMuted");
    particlesEnabled = Specular.prefs.getBoolean("Particles");

    if (music != null) music.setVolume(1f);

    gameMode = new Ranked(this);
    enemiesKilled = 0;
    // Adding player and setting up input processor
    pss.spawn(false);

    shaken = false;

    gameInputProcessor = new GameInputProcessor(this);
    gameInputProcessor.reset();
    input.setInputProcessor(gameInputProcessor);
    ggInputProcessor = new GameOverInputProcessor(game, this);
    pauseInputProcessor = new PauseInputProcessor(game, this);

    resetGameTime();

    cs.resetCombo();
    scoreMultiplier = 1;
    scoreMultiplierTimer = 0;

    boardshockCharge = 0;
    Bullet.maxBounces = 0;
    Bullet.setTwist(false);
    Bullet.setDamage(1);
    FireRateBoost.stacks = 0;

    // Refreshing upgrades
    refreshUpgrades();

    waveNumber = 0;
    waveManager.resetGame();
    currentWave = waveManager.getWave(waveNumber);
  }
示例#2
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);
    }
  }