Android Open Source - RollOverSphere---a-simple-libgdx-game Intro Scene






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;
// w  w w  .j  av a 2  s.  c  o  m
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
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.GameManager;
import com.igorcrevar.rolloverchuck.GameType.BaseGameType;
import com.igorcrevar.rolloverchuck.GameType.Difficulty;
import com.igorcrevar.rolloverchuck.IActivityRequestHandler.IConfirmDialogCallback;
import com.igorcrevar.rolloverchuck.IScene;
import com.igorcrevar.rolloverchuck.ISceneManager;
import com.igorcrevar.rolloverchuck.objects.IntroSceneButtonsObject;
import com.igorcrevar.rolloverchuck.objects.TextButton;
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 IntroScene implements IScene, InputProcessor {
  private SpriteBatch spriteBatch = new SpriteBatch();
  private String[] title = new String[] { "R", "o", "l", "l", null, "o", "v", "e", "r", null, "B", "a", "l", "l", "!" };
  private MyFontDrawer[] titleDrawers = new MyFontDrawer[title.length];
  private float[] titleXPos = new float[title.length];
  private String creditsText = "Roll over Ball! by WayILook@Games (c) 2014 ..... " + 
                 "Concept & design, programming & blabla by Igor Crevar " +
                 "also unknown as \"random guy from somewhere over the nowhere\"";
  private float creditsPos;
  
  private GameManager gameManager;
  private float timer;
  
  private IntroSceneButtonsObject buttons;
  private ISceneManager sceneManager;
    
  // batch for custom font
  private MyFontDrawerBatch myFontDrawerBatch = new MyFontDrawerBatch(new MyFontDrawerDefaultFont(), 1920, 1080);
  
  private boolean isGameChoosen;
  private BaseGameType choosenBaseGameType;
  private TextButton[] gameTypeButtons;
  private TextButton[] difficultyTypeButtons;
  private float gameChoosenTimer;
  private TextureRegion textureRegionForTitle;
  
  public IntroScene(ISceneManager sceneManager) {
    this.sceneManager = sceneManager;
    this.gameManager = sceneManager.getGameManager();
    this.textureRegionForTitle = gameManager.getTextureAtlas("base").findRegion("myfont2");
    float titleX = 320f; // 220.0f;
    int i = 0;
    for (String letter : title) {
      titleXPos[i] = titleX;
      if (letter != null) {
        titleDrawers[i] = new MyFontDrawer(letter, 20f, 20f, 10.0f, 0.00001f, textureRegionForTitle, -60f, 80f, Float.NaN, 1.0f);
        myFontDrawerBatch.addNew(titleDrawers[i]);
        titleX += titleDrawers[i].getWidth() + 15.0f;        
      }
      else {
        titleDrawers[i] = null;
        titleX += 60.0f;
      }
      
      ++i;
    }
    
    MyFontDrawer fnt2 = myFontDrawerBatch.addNew(new MyFontDrawer("(c) WayILook@Games 2014", 10f, 10f, 5.0f, 0.00001f, 
                           gameManager.getTextureAtlas("base").findRegion("myfont"), 0f, 0f, 1.0f, 1.0f)); 
    fnt2.translate((1920 - fnt2.getWidth()) / 2.0f, fnt2.getHeight() + 20, 0.0f);
    
    buttons = new IntroSceneButtonsObject(sceneManager, 600f);
    final IntroScene thisObj = this;
    gameTypeButtons = new TextButton[2];
    gameTypeButtons[0] = new TextButton(gameManager.getBitmapFont(), "Arcade", 600.0f, 600f, 120.0f) {      
      @Override
      protected void onClick() {
        thisObj.chooseGameType(BaseGameType.Arcade);
      }
    };
    gameTypeButtons[1] = new TextButton(gameManager.getBitmapFont(), "Stress Free", 400.0f, 600f, 120.0f) {      
      @Override
      protected void onClick() {
        thisObj.chooseGameType(BaseGameType.StressFree);
      }
    };
            
    difficultyTypeButtons = new TextButton[3];
    difficultyTypeButtons[0] = new TextButton(gameManager.getBitmapFont(), "Easy", 800.0f, 600f, 120f) {      
      @Override
      protected void onClick() {
        thisObj.chooseDifficulty(Difficulty.Easy);
      }
    };
    difficultyTypeButtons[1] = new TextButton(gameManager.getBitmapFont(), "Medium", 600.0f, 600f, 120f) {      
      @Override
      protected void onClick() {
        thisObj.chooseDifficulty(Difficulty.Medium);
      }
    };
    difficultyTypeButtons[2] = new TextButton(gameManager.getBitmapFont(), "Die hard!", 400.0f, 600f, 120f) {      
      @Override
      protected void onClick() {
        thisObj.chooseDifficulty(Difficulty.Hard);
      }
    };
  }
  
  public void chooseGameType(BaseGameType baseGameType) {
    isGameChoosen = true;
    gameChoosenTimer = 0.0f;
    this.choosenBaseGameType = baseGameType;
  }
  
  public void chooseDifficulty(Difficulty diff) {
    sceneManager.startGame(choosenBaseGameType, diff);
  }
  
  @Override
  public void init(ISceneManager sceneManager) {
    Gdx.input.setInputProcessor(this);
    Gdx.gl.glDisable(GL20.GL_CULL_FACE);     
    Gdx.gl.glEnable(GL20.GL_DEPTH_TEST);
    Gdx.gl.glDepthFunc(GL20.GL_LEQUAL);
    
    gameManager.playIntroMusic();
    timer = 0.0f;
    creditsPos = 1920.0f;
    isGameChoosen = false;
    
    sceneManager.getGameManager().getStars().init(sceneManager.getGameManager().getTextureAtlas("base").findRegion("star"));
  }

  @Override
  public void update(ISceneManager sceneManager, float deltaTime) {
    GameHelper.clearScreen();
    
    GameHelper.setProjectionFor2D(spriteBatch, 1920, 1080);
    spriteBatch.begin();
    sceneManager.getGameManager().getStars().update(deltaTime);
    sceneManager.getGameManager().getStars().draw(spriteBatch);
    spriteBatch.end();
    
    BitmapFont font = gameManager.getBitmapFont();
    if (!isGameChoosen) {
      float angle = Mathf.lerp(359.0f, 0.0f, timer * 0.45f);
      float titleScale = Mathf.lerp(4.0f, 1.0f, timer * 0.5f);
      float ntimer = (timer - (int)Math.max(timer - 0, 0f)) / 1.0f; // every two seconds all colors in texture are rotated
      float npos = (int)Mathf.lerp(1f, 10f, ntimer) / 10.0f; 
      for (int i = 0; i < titleDrawers.length; ++i) {
        MyFontDrawer fd = titleDrawers[i];
        if (fd != null) {
          fd.setUVMinMaxScrollV(textureRegionForTitle, npos, 0.3f);
          fd.idt().translate(titleXPos[i], 800, 0.0f).scale(titleScale, titleScale, 0.0f).rotateAround(0.0f, 0.0f, 1.0f, angle);
        }
      }
      
      myFontDrawerBatch.draw(gameManager.getShader("region"), textureRegionForTitle.getTexture());
      
      GameHelper.setProjectionFor2D(spriteBatch, 1920, 1080);
      spriteBatch.begin();
      font.setScale(0.6f);
      font.setColor(Color.WHITE);
      font.draw(spriteBatch, creditsText, creditsPos, 180);
      creditsPos -= 200.0f * deltaTime;
      if (creditsPos < -font.getBounds(creditsText).width - 20.0f) {
        creditsPos = 1920;
      }
      
      buttons.draw(spriteBatch);
      // draw textButtons
      for (TextButton tb : gameTypeButtons) {
        tb.draw(spriteBatch, font);
      }
      
    }
    // if game choosen second menu show
    else {
      GameHelper.setProjectionFor2D(spriteBatch, 1920, 1080);
      spriteBatch.begin();
      float scale = Mathf.lerp(0.0f, 1.0f, gameChoosenTimer * 4f);
      Sprite overlaySprite = sceneManager.getGameManager().getOverlaySprite(1.0f, 0.95f);
      overlaySprite.setScale(scale);
      overlaySprite.draw(spriteBatch);
      if (scale == 1.0f) {
        for (TextButton tb : difficultyTypeButtons) {
          tb.draw(spriteBatch, font);
        }
      }
      
      gameChoosenTimer += deltaTime;
    }
    
    spriteBatch.end();
    
    timer += deltaTime;
  }

  @Override
  public void leave(ISceneManager sceneManager) {
    gameManager.stopIntroMusic();
  }

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

  @Override
  public boolean keyDown(int keycode) {
    return false;
  }

  @Override
  public boolean keyUp(int keycode) {
    if (keycode == Keys.BACK || keycode == Keys.ESCAPE) {
      if (isGameChoosen) {
        isGameChoosen = false;
      }
      else {
        sceneManager.getRequestHandler().confirmDialog("Quit game?", new IConfirmDialogCallback() {      
          @Override
          public void confirmDialogResult(boolean result) {
            if (result) Gdx.app.exit();
          }
        });
      }
    }
    return true;
  }

  @Override
  public boolean keyTyped(char character) {
    return false;
  }

  @Override
  public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    float x = GameHelper.screenX2OtherX(screenX, 1920);
    float y = GameHelper.screenY2OtherY(screenY, 1080);
    if (isGameChoosen) {
      for (TextButton tb : difficultyTypeButtons) {
        tb.check(x, y);
      }
    }
    else {
      buttons.check(x, y);
      for (TextButton tb : gameTypeButtons) {
        tb.check(x, y);
      }
    }
    return true;
  }

  @Override
  public boolean touchUp(int screenX, int screenY, int pointer, int button) {    
    return true;
  }

  @Override
  public boolean touchDragged(int screenX, int screenY, int pointer) {
    return false;
  }

  @Override
  public boolean mouseMoved(int screenX, int screenY) {
    return false;
  }

  @Override
  public boolean scrolled(int amount) {
    return false;
  }  
}




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