Esempio n. 1
0
  protected void renderGame() {

    Gdx.gl.glClearDepthf(1f);
    Gdx.gl.glClear(GL20.GL_DEPTH_BUFFER_BIT);

    // Clearing screen, positioning camera, rendering map and entities
    // Positioning camera to the player
    Specular.camera.zoom = 1;
    Camera.setPosition();
    Specular.camera.update();

    // Rendering map and entities
    game.batch.setProjectionMatrix(Specular.camera.combined);
    game.batch.begin();

    game.batch.setColor(1, 1, 1, 1);
    game.batch.draw(
        currentMap.getParallax(),
        -1024 + Camera.getCameraX() / 2,
        -1024 + Camera.getCameraY() / 2,
        4096,
        4096);
    game.batch.setColor(1, 1, 1, 1);

    Camera.setZoom();
    BoardShock.setZoom();

    Specular.camera.update();
    game.batch.setProjectionMatrix(Specular.camera.combined);

    currentMap.render(game.batch, true);

    ScissorStack.calculateScissors(
        Specular.camera, game.batch.getTransformMatrix(), clipBounds, scissors);
    ScissorStack.pushScissors(scissors);

    if (tutorialOnGoing && tutorial.getCurrentWave().getEvent() == TutorialEvent.POWER_UPS_SHOWN) {
      if (!tutorial.enemiesHasSpawned()) {
        Util.writeCentered(
            game.batch,
            tutorial.getFont(),
            "these are power-ups",
            tutorial.getTextX(),
            tutorial.getTextY() + 200);

        if (tutorial.allPowerUpsActivated())
          Util.writeCentered(
              game.batch,
              tutorial.getFont(),
              "some can be combined",
              tutorial.getTextX(),
              tutorial.getTextY());
      }
    }

    for (Entity ent : entities) {
      if (!(ent instanceof Enemy)) ent.render(game.batch);
    }

    game.batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);

    for (UpgradeOrb orb : orbs) orb.render(game.batch);

    for (Particle p : particles) p.render(game.batch);

    game.batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    for (Entity ent : enemies) {
      ent.render(game.batch);
    }

    if (!gameMode.isGameOver()) player.render(game.batch);

    game.batch.flush();
    ScissorStack.popScissors();

    // Re-positioning camera for HUD
    Specular.camera.position.set(0, 0, 0);
    Specular.camera.zoom = 1;
    Specular.camera.update();
    game.batch.setProjectionMatrix(Specular.camera.combined);

    if (isPaused) { // Pause menu
      game.batch.draw(
          greyPixel,
          -Specular.camera.viewportWidth / 2,
          -Specular.camera.viewportHeight / 2,
          Specular.camera.viewportWidth,
          Specular.camera.viewportHeight);
      game.batch.draw(pauseTex, -pauseTex.getWidth() / 2, 100);
      pauseInputProcessor.getResumeButton().render();
      pauseInputProcessor.getToMenuButton().render();
    } else {
      if (!gameMode.isGameOver()) {
        // Drawing HUD
        hud.render(game.batch, scoreMultiplierTimer);
        gameInputProcessor.getShootStick().render(game.batch);
        gameInputProcessor.getMoveStick().render(game.batch);

        // Tutorial
        if (tutorialOnGoing && !showTutorialEnd) tutorial.render(game.batch);

        // Drawing SCORE in the middle top of the screen
        Util.writeCentered(
            game.batch,
            scoreFont,
            player.getFormattedScore(),
            0,
            Specular.camera.viewportHeight / 2 - 36);
        // Drawing MULTIPLIER on screen
        Util.writeCentered(
            game.batch,
            multiplierFont,
            "x" + Math.round(scoreMultiplier),
            0,
            Specular.camera.viewportHeight / 2 - 98);

        // Tutorial end
        if (showTutorialEnd) {
          tutorialTicks++;

          if (tutorialTicks > 120) {
            scoreFontAlpha = (tutorialTicks - 120) / 180f;
            scoreFontAlpha = scoreFontAlpha > 1 ? 1 : scoreFontAlpha;

            game.batch.setColor(1, 1, 1, scoreFontAlpha);
            game.batch.draw(
                greyPixel,
                -Specular.camera.viewportWidth / 2,
                -Specular.camera.viewportHeight / 2,
                Specular.camera.viewportWidth,
                Specular.camera.viewportHeight);
            game.batch.setColor(Color.WHITE);

            scoreFont.setColor(1, 0, 0, scoreFontAlpha);
            Util.writeCentered(game.batch, scoreFont, "tap to continue", 0, -100);
          }
        }

        gameMode.render(game.batch);
      } else if (gameMode.isGameOver()) { // Game over screen
        // Manual camera shake
        Specular.camera.position.set(0, 0, 0);
        Specular.camera.position.add(
            rand.nextFloat() * 100 * Camera.getShakeIntensity(),
            rand.nextFloat() * 100 * Camera.getShakeIntensity(),
            0);
        Specular.camera.update();
        game.batch.setProjectionMatrix(Specular.camera.combined);

        game.batch.draw(
            greyPixel,
            -Specular.camera.viewportWidth / 2,
            -Specular.camera.viewportHeight / 2,
            Specular.camera.viewportWidth,
            Specular.camera.viewportHeight);
        game.batch.draw(gameOverTex, -gameOverTex.getWidth() / 2, -gameOverTex.getHeight() / 2);

        // Game Over effects [fade in, camera shake]
        if (gameOverScoreFont.getScaleX() > 1f) {
          gameOverScoreFont.scale(-0.1f);
          gameOverScoreFont.setColor(
              1, 0, 0, Math.max((10 - gameOverScoreFont.getScaleX()) / 10f, 0));
        } else {
          gameOverScoreFont.setScale(1);
          if (!shaken) {
            Camera.shake(0.5f, 0.02f);
            shaken = true;
          }

          if (player.getScore() >= lastHighscore) {
            Util.drawCentered(game.batch, newHighscore, 0, 0, 0);
            lastHighscore = player.getScore();
          }
        }

        // Drawing final score and buttons
        if (music != null) music.setVolume(0.25f);
        if (gameOverTicks == GAMEOVERSOUND_TIMER && isSoundEnabled()) {
          gameOverSound.play(1f, 1, 0);
        }
        Util.writeCentered(game.batch, gameOverScoreFont, player.getFormattedScore(), 0, 100);

        game.batch.setColor(Color.WHITE);
        ggInputProcessor.getRetryBtn().render();
        ggInputProcessor.getMenuBtn().render();
        ggInputProcessor.getHighscoreBtn().render();

        if (player.getUpgradePoints() >= 1) {
          if (!ggInputProcessor.isTouchingUpgradeBtn()) {
            if (gameOverTicks % 90 < 40) {
              ggInputProcessor.getUpgradeBtn().setScale(1.00f);
              ggInputProcessor.getUpgradeBtn().setTouch(true);
            } else {
              ggInputProcessor.getUpgradeBtn().setScale(1.0f);
              ggInputProcessor.getUpgradeBtn().setTouch(false);
            }
          }
        }

        ggInputProcessor.getUpgradeBtn().render();
      }
    }

    game.batch.end();
  }
Esempio n. 2
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;
  }