Android Open Source - RollOverSphere---a-simple-libgdx-game Arcade Game Mode






From Project

Back to project page RollOverSphere---a-simple-libgdx-game.

License

The source code is released under:

MIT License

If you think the Android project RollOverSphere---a-simple-libgdx-game listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.igorcrevar.rolloverchuck.scenes.GameMode;
//from   w ww  .j  av  a  2s .co  m
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.igorcrevar.rolloverchuck.ISceneManager;
import com.igorcrevar.rolloverchuck.objects.EndGameButtonsObject;
import com.igorcrevar.rolloverchuck.utils.GameHelper;
import com.igorcrevar.rolloverchuck.utils.Mathf;
import com.igorcrevar.rolloverchuck.utils.MyFontDrawer;
import com.igorcrevar.rolloverchuck.utils.MyFontDrawerBatch;
import com.igorcrevar.rolloverchuck.utils.MyFontDrawerDefaultFont;

public class ArcadeGameMode implements IGameMode {
  private static final float PauseAfterEndGame = 2.0f;
  private int countDown;
  private ISceneManager sceneManager;
  private Sprite pointImage = new Sprite();
  private EndGameButtonsObject buttons;
  private float endGameTimer;
  private boolean isSaved;
  
  // batch for custom font
  private MyFontDrawerBatch myFontDrawerBatch = new MyFontDrawerBatch(new MyFontDrawerDefaultFont(), 1920, 1080);
  private MyFontDrawer title;
  
  public ArcadeGameMode(ISceneManager sceneManager) {
    this.sceneManager = sceneManager;
    
    buttons = new EndGameButtonsObject(sceneManager, 450);
    
    title = new MyFontDrawer("Time's up!", 25.0f, 25.0f, 10.0f, 0.00001f);
    title.setUVMinMax(sceneManager.getGameManager().getTextureAtlas("base").findRegion("myfont"));
    title = myFontDrawerBatch.addNew(title);
  }

  @Override
  public void init() {
    isSaved = false;
    countDown = getCountdownFrom();
    endGameTimer = 0.0f;
    
    pointImage.setRegion(sceneManager.getGameManager().getTextureAtlas("base").findRegion("clock"));
    pointImage.setSize(60, 60);
    pointImage.setPosition(1620, 850);
  }

  @Override
  public void update(float timer, float deltaTime) {
    if (sceneManager.isGameActive()) {
      countDown = getCountdownFrom() - (int)timer;
      if (countDown < 1) {
        sceneManager.setGameState(com.igorcrevar.rolloverchuck.ISceneManager.GameState.GAMEOVER);
        endGameTimer = 0.0f;
      }
    }
    else if (sceneManager.isGameOver()) {
      endGameTimer += deltaTime;
    }
  }

  @Override
  public void drawSprites(BitmapFont font, SpriteBatch spriteBatch) {
    pointImage.draw(spriteBatch);
    font.draw(spriteBatch, String.valueOf(countDown), 1700, 900);
    if (!sceneManager.isGameActive()) {
      float scale = Mathf.lerp(0.0f, 1.0f, endGameTimer / PauseAfterEndGame);
      Sprite overlaySprite = sceneManager.getGameManager().getOverlaySprite(0.0f, 0.65f);
      overlaySprite.setScale(scale);
      overlaySprite.draw(spriteBatch);
      
      if (endGameTimer > PauseAfterEndGame) {
        if (!isSaved) {
          isSaved = true;
          // save
          sceneManager.finishGame(true);
        }
        
        font.setScale(1.0f);
        String sc = "New Score: " + GameHelper.getStringPoints(sceneManager.getCurrentScore());
        font.setColor(Color.BLACK);
        font.draw(spriteBatch, sc, (1920 - font.getBounds(sc).width) / 2.0f + 5.0f, 650);
        font.setColor(Color.WHITE);
        font.draw(spriteBatch, sc, (1920 - font.getBounds(sc).width) / 2.0f, 660.0f);
        sc = "Top Score: " + GameHelper.getStringPoints(sceneManager.getGameManager().getTopScore(sceneManager.getCurrentGameType()));
        font.setColor(Color.BLACK);
        font.draw(spriteBatch, sc, (1920 - font.getBounds(sc).width) / 2.0f + 5.0f, 550);
        font.setColor(Color.WHITE);
        font.draw(spriteBatch, sc, (1920 - font.getBounds(sc).width) / 2.0f, 560.0f);
        
        buttons.draw(spriteBatch);
      }
    }
  }

  @Override
  public TextureRegion getFieldTextureRegion() {
    String texture = "";
    switch (sceneManager.getCurrentGameType().getDifficulty()) {
    case Easy:
      texture = "field1";
      break;
    case Medium:
      texture = "field2";
      break;
    case Hard:
      texture = "field3";
      break;
    }
    return sceneManager.getGameManager().getTextureAtlas("base").findRegion(texture);
  }

  @Override
  public void touchUp(int screenX, int screenY, int pointer, int button) {
    if (endGameTimer > PauseAfterEndGame) {
      buttons.check(screenX, screenY);
    }
  }
  
  private int getCountdownFrom() {
    return sceneManager.getGameManager().getGameData().ArcadeGameTimer;
  }

  @Override
  public void postUpdate(SpriteBatch spriteBatch) {
    if (!sceneManager.isGameActive()) {
      float xPos = Mathf.lerp(1920.0f, (1920 - title.getWidth()) / 2.0f, endGameTimer / PauseAfterEndGame);
      title.idt().translate(xPos, 900f, 0.0f);
      myFontDrawerBatch.draw(sceneManager.getGameManager().getShader("region"), sceneManager.getGameManager().getTextureAtlas("base").findRegion("myfont").getTexture());
    }
  }

  @Override
  public void dispose() {
    myFontDrawerBatch.dispose();
  }
}




Java Source Code List

com.google.example.games.basegameutils.GameHelperUtils.java
com.google.example.games.basegameutils.GameHelper.java
com.igorcrevar.rolloverchuck.DesktopRunner.java
com.igorcrevar.rolloverchuck.GameConsts.java
com.igorcrevar.rolloverchuck.GameData.java
com.igorcrevar.rolloverchuck.GameListener.java
com.igorcrevar.rolloverchuck.GameManager.java
com.igorcrevar.rolloverchuck.GameType.java
com.igorcrevar.rolloverchuck.IActivityRequestHandler.java
com.igorcrevar.rolloverchuck.ISceneManager.java
com.igorcrevar.rolloverchuck.IScene.java
com.igorcrevar.rolloverchuck.mesh.CubeMeshWithNormals.java
com.igorcrevar.rolloverchuck.mesh.CubeMesh.java
com.igorcrevar.rolloverchuck.mesh.FieldMesh.java
com.igorcrevar.rolloverchuck.mesh.IMesh.java
com.igorcrevar.rolloverchuck.mesh.SphereMesh.java
com.igorcrevar.rolloverchuck.objects.BoxObject.java
com.igorcrevar.rolloverchuck.objects.ChuckObject.java
com.igorcrevar.rolloverchuck.objects.ChuckSpriteObject.java
com.igorcrevar.rolloverchuck.objects.EndGameButtonsObject.java
com.igorcrevar.rolloverchuck.objects.FieldObject.java
com.igorcrevar.rolloverchuck.objects.GameButton.java
com.igorcrevar.rolloverchuck.objects.IntroSceneButtonsObject.java
com.igorcrevar.rolloverchuck.objects.MainWallObject.java
com.igorcrevar.rolloverchuck.objects.StarsObject.java
com.igorcrevar.rolloverchuck.objects.TextButton.java
com.igorcrevar.rolloverchuck.objects.TrailObject.java
com.igorcrevar.rolloverchuck.objects.boxes.BoxManager.java
com.igorcrevar.rolloverchuck.objects.boxes.BoxRegionManager.java
com.igorcrevar.rolloverchuck.objects.boxes.BoxRegion.java
com.igorcrevar.rolloverchuck.objects.boxes.BoxTypeFactory.java
com.igorcrevar.rolloverchuck.objects.boxes.IBoxRegion.java
com.igorcrevar.rolloverchuck.objects.boxes.IBoxType.java
com.igorcrevar.rolloverchuck.physics.CollisionSolver.java
com.igorcrevar.rolloverchuck.physics.ICollisionIterationHandler.java
com.igorcrevar.rolloverchuck.physics.SphereMoving.java
com.igorcrevar.rolloverchuck.points.PlayerPoint.java
com.igorcrevar.rolloverchuck.points.PointsManager.java
com.igorcrevar.rolloverchuck.scenes.GameLoadingScene.java
com.igorcrevar.rolloverchuck.scenes.GameScene.java
com.igorcrevar.rolloverchuck.scenes.IntroScene.java
com.igorcrevar.rolloverchuck.scenes.GameMode.ArcadeGameMode.java
com.igorcrevar.rolloverchuck.scenes.GameMode.IGameMode.java
com.igorcrevar.rolloverchuck.scenes.GameMode.StressFreeGameMode.java
com.igorcrevar.rolloverchuck.utils.CollisionHelper.java
com.igorcrevar.rolloverchuck.utils.GameHelper.java
com.igorcrevar.rolloverchuck.utils.IMyFontDrawerFont.java
com.igorcrevar.rolloverchuck.utils.Mathf.java
com.igorcrevar.rolloverchuck.utils.MyFontDrawerBatch.java
com.igorcrevar.rolloverchuck.utils.MyFontDrawerDefaultFont.java
com.igorcrevar.rolloverchuck.utils.MyFontDrawer.java
com.igorcrevar.rolloverchuck.utils.ShaderAssetLoader.java
com.wayilookatgames.rolloverball.MainActivity.java