Ejemplo n.º 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);
  }
Ejemplo n.º 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);
    }
  }
Ejemplo n.º 3
0
  public void updateHitDetections() {
    // Checking if any bullet hit an enemy
    for (Bullet b : bullets) {
      for (Enemy e : enemies) {
        if (e.hasSpawned() && e.getLife() > 0) {
          // Custom hitdetection for the worm
          // It just uses the parts as they were enemies
          if (e instanceof EnemyWorm) {
            for (EnemyWorm.Part p : ((EnemyWorm) e).getParts()) {
              if ((b.getX() - p.getX()) * (b.getX() - p.getX())
                      + (b.getY() - p.getY()) * (b.getY() - p.getY())
                  < p.getOuterRadius() * p.getOuterRadius() + b.getWidth() * b.getWidth() * 4) {
                p.hit(Bullet.damage);
                b.hit();

                // Adding a small camerashake
                Camera.shake(0.1f, 0.05f);

                // Rewarding player depending on game mode
                enemyHit(e);
                break;
              }
            }
          } else if ((b.getX() - e.getX()) * (b.getX() - e.getX())
                  + (b.getY() - e.getY()) * (b.getY() - e.getY())
              < e.getOuterRadius() * e.getOuterRadius() + b.getWidth() * b.getWidth() * 4) {

            e.hit(Bullet.damage);
            b.hit();

            // Rewarding player depending on game mode
            enemyHit(e);
            break;
          }
        }
      }
    }
  }
Ejemplo n.º 4
0
  public GameState(Specular game) {
    super(game);

    // Loading map texture from a internal directory
    Texture mapTexture = new Texture(Gdx.files.internal("graphics/game/packed/Level.png"));
    Texture shockLight = new Texture(Gdx.files.internal("graphics/game/packed/ShockLight.png"));
    Texture parallax = new Texture(Gdx.files.internal("graphics/game/packed/Parallax.png"));

    // Loading gameover textures
    gameOverTex = new Texture(Gdx.files.internal("graphics/game/packed/Background.png"));
    newHighscore = new Texture(Gdx.files.internal("graphics/menu/gameover/New Highscore.png"));

    // Loading pause menu textures
    pauseTex = new Texture(Gdx.files.internal("graphics/menu/pausemenu/Pause.png"));
    greyPixel = new Texture(Gdx.files.internal("graphics/menu/pausemenu/Grey Pixel.png"));

    textureAtlas = new TextureAtlas(Gdx.files.internal("graphics/game/packed/Specular.atlas"));

    // Loading HUD
    hud = new HUD(this);

    // Initializing map handler for handling many maps
    mapHandler = new MapHandler();
    mapHandler.addMap(
        "Map",
        mapTexture,
        shockLight,
        parallax,
        mapTexture.getWidth(),
        mapTexture.getHeight(),
        this);
    currentMap = mapHandler.getMap("Map");

    clipBounds = new Rectangle(0, 0, currentMap.getWidth(), currentMap.getHeight());

    // Initializing font
    FreeTypeFontGenerator fontGen =
        new FreeTypeFontGenerator(Gdx.files.internal("fonts/Battlev2l.ttf"));
    FreeTypeFontParameter ftfp = new FreeTypeFontParameter();
    ftfp.size = 96; // MAX SIZE
    ftfp.characters = "1234567890,";
    gameOverScoreFont = fontGen.generateFont(ftfp);
    gameOverScoreFont.setColor(Color.RED);

    ftfp.characters = "1234567890,tapocniue"; // Characters for "Tap to continue"
    ftfp.size = 64;
    scoreFont = fontGen.generateFont(ftfp);
    scoreFont.setColor(Color.RED);

    ftfp.characters = "1234567890,x";
    ftfp.size = 40;
    multiplierFont = fontGen.generateFont(ftfp);
    multiplierFont.setColor(Color.RED);

    // Tutorial (Must be initialized before fontGen.dispose())
    tutorial = new Tutorial(this, fontGen);

    fontGen.dispose();
    // Graphics Settings
    GfxSettings.init();

    // Tutorial
    Tutorial.init(textureAtlas);

    // Initializing entities and analogstick statically
    Player.init(textureAtlas);
    Bullet.init(this);
    Particle.init(textureAtlas);
    UpgradeOrb.init(textureAtlas);
    EnemyWanderer.init(textureAtlas);
    EnemyCircler.init(textureAtlas);
    EnemyStriver.init(textureAtlas);
    EnemyBooster.init(textureAtlas);
    EnemyWorm.init(textureAtlas);
    EnemyVirus.init(textureAtlas);
    EnemyShielder.init(textureAtlas);
    EnemyExploder.init(textureAtlas);
    EnemyDasher.init(textureAtlas);
    EnemyTanker.init(textureAtlas);
    AnalogStick.init(hud);

    // Initializing power-ups
    AddLife.init(textureAtlas);
    BulletBurst.init(textureAtlas);
    FireRateBoost.init(textureAtlas);
    ScoreMultiplier.init(textureAtlas);
    ShieldPowerUp.init(textureAtlas);
    SlowdownEnemies.init(textureAtlas);
    BoardshockPowerUp.init(textureAtlas);
    Ricochet.init(textureAtlas);
    Repulsor.init(textureAtlas);
    LaserPowerup.init(textureAtlas);
    ShockWaveRenderer.init(textureAtlas);
    Laser.init(this);
    Swarm.init(textureAtlas);
    PDSPowerUp.init(textureAtlas);

    pss = new PlayerSpawnSystem(this);
    puss = new PowerUpSpawnSystem(this);
    pass = new ParticleSpawnSystem(this);
    oss = new OrbSpawnSystem(this);
    cs = new ComboSystem();
    waveManager = new WaveManager(this);

    input = Gdx.input;
  }