Android Open Source - BlockHopper Main Activity






From Project

Back to project page BlockHopper.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION...

If you think the Android project BlockHopper 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

/*
 * May 31 2013, ICS4U1 Culminating - Mr. Hutchison
 * Author: Daniel Cole/*from w w w  .j  a  v  a2s .c  o  m*/
 * AndEngine developed by Nicolas Gramlich
 */


package com.example.blockhopper;
import org.andengine.engine.Engine;
import org.andengine.engine.LimitedFPSEngine;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.WakeLockOptions;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.ui.activity.BaseGameActivity;


public class MainActivity extends BaseGameActivity{
  private  int CAMERA_WIDTH = 800; //arbitrary values, eventually designed to be changed to be phone specific
  private  int CAMERA_HEIGHT = 480;
    private  Camera camera; 
  private MenuScene mscene;
  private SplashScene spscene;

/////////////////////////////////////////////////////////BaseGameActivty Methods//////////////////////////////////////////////
  @Override
  public EngineOptions onCreateEngineOptions() {
    camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    EngineOptions options = new EngineOptions(true,ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
    options.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
    
    return options;
  }
  protected void onDestroy(){ // used to make sure the game closes properly on exit
    super.onDestroy();
    if(this.isGameLoaded()){
      System.exit(0);
    }
  }
  @Override
  public Engine onCreateEngine(EngineOptions pEngineOptions){
    return new LimitedFPSEngine(pEngineOptions,60);//limited fps engine to make sure that the game will run on slower phones
  }

  @Override
  public void onCreateResources(
      OnCreateResourcesCallback pOnCreateResourcesCallback)
      throws Exception {
    spscene = new SplashScene(this,mEngine,camera); //creates the obj that will be used to managed the spash and menu scene
    mscene = new MenuScene(this,mEngine,camera);
    
    spscene.loadSplashScene(); //loads the scenes(creates their resources, pictures etc)
    
    pOnCreateResourcesCallback.onCreateResourcesFinished();
  }



  @Override
  public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
      throws Exception {
    spscene.createSplashScene();

    pOnCreateSceneCallback.onCreateSceneFinished(spscene.getScene());
  }


  @Override
  public void onPopulateScene(Scene pScene,
    OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
    mEngine.setScene(spscene.getScene());
    
    mEngine.registerUpdateHandler(new TimerHandler(1.3f,new ITimerCallback() { //thread timer to display the splash scene for awhile
      
      @Override
      public void onTimePassed(TimerHandler pTimerHandler) {
        mscene.loadMenuScene(); //when timer is up it loads the menu scene, and sets the current scene to the menu scene
        mscene.createMenuScene();
        mEngine.setScene(mscene.getScene());

      }
    }));

    pOnPopulateSceneCallback.onPopulateSceneFinished();
  }


}




Java Source Code List

com.example.blockhopper.BuildConfig.java
com.example.blockhopper.GameScene.java
com.example.blockhopper.HighScores.java
com.example.blockhopper.Levels.java
com.example.blockhopper.MainActivity.java
com.example.blockhopper.MenuScene.java
com.example.blockhopper.SplashScene.java