예제 #1
0
  public void enemyHit(Enemy e) {
    if (e.getLife() <= 0) {
      gameMode.enemyKilled(e);

      cs.activate(enemies.size);

      enemiesKilled++;
      oss.spawn(
          e.getX(), e.getY(), e.getDx() * Enemy.getSlowdown(), e.getDy() * Enemy.getSlowdown(), 2);

      Camera.shake(0.3f, 0.1f);

      if (isSoundEnabled()) killSound.play(0.75f, (float) (1 + Math.random() / 3 - 0.16), 0);
    }
  }
예제 #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);
    }
  }