Android Open Source - MoonMiner Main Menu Scene






From Project

Back to project page MoonMiner.

License

The source code is released under:

MIT License

If you think the Android project MoonMiner 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.lhbdev.moonminer.scene;
//  w  ww  .ja v  a  2  s.c o  m
import org.andengine.entity.scene.menu.MenuScene;
import org.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener;
import org.andengine.entity.scene.menu.item.IMenuItem;
import org.andengine.entity.scene.menu.item.SpriteMenuItem;
import org.andengine.entity.scene.menu.item.decorator.ScaleMenuItemDecorator;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.util.GLState;
import org.andengine.engine.camera.Camera;

import com.lhbdev.moonminer.base.BaseScene;
import com.lhbdev.moonminer.manager.SceneManager;
import com.lhbdev.moonminer.manager.SceneManager.SceneType;

public class MainMenuScene extends BaseScene implements IOnMenuItemClickListener {
  private MenuScene menuChildScene;
  private final int MENU_PLAY = 0;
  private final int MENU_OPTIONS = 1;

  @Override
  public void createScene() 
  {
    createBackground();
    createMenuChildScene();
  }

  @Override
  public void onBackKeyPressed() 
  {
    System.exit(0);
  }

  @Override
  public SceneType getSceneType() 
  {
    return SceneType.SCENE_MENU;
  }
  
  private void createBackground()
  {
    attachChild(new Sprite(400,240, resourcesManager.menu_background_region,vbom)
    {
      @Override
      protected void preDraw(GLState pGLState, Camera pCamera)
      {
        super.preDraw(pGLState, pCamera);
        pGLState.enableDither();
      }
    });
  }
  
  private void createMenuChildScene()
  {
    menuChildScene = new MenuScene(camera);
    menuChildScene.setPosition(0, 0);
      
      final IMenuItem playMenuItem = new ScaleMenuItemDecorator(new SpriteMenuItem(MENU_PLAY, resourcesManager.play_region, vbom), 1.2f, 1);
      final IMenuItem optionsMenuItem = new ScaleMenuItemDecorator(new SpriteMenuItem(MENU_OPTIONS, resourcesManager.options_region, vbom), 1.2f, 1);
      
      menuChildScene.addMenuItem(playMenuItem);
      menuChildScene.addMenuItem(optionsMenuItem);
      
      menuChildScene.buildAnimations();
      menuChildScene.setBackgroundEnabled(false);
      
      playMenuItem.setPosition(playMenuItem.getX(), playMenuItem.getY()- 40);
      optionsMenuItem.setPosition(optionsMenuItem.getX(), optionsMenuItem.getY() - 90);
      
      menuChildScene.setOnMenuItemClickListener(this);
      
      setChildScene(menuChildScene);
  }
  
  public boolean onMenuItemClicked(MenuScene pMenuScene, IMenuItem pMenuItem, float pMenuItemLocalX, float pMenuItemLocalY)
  {
      switch(pMenuItem.getID())
      {
          case MENU_PLAY:
              //Load Game Scene!
              SceneManager.getInstance().loadGameScene(engine);
              return true;
          case MENU_OPTIONS:
              return true;
          default:
              return false;
      }
  }

  @Override
  public void disposeScene() {
    // TODO Auto-generated method stub
    
  }

}




Java Source Code List

com.lhbdev.moonminer2.MainActivity.java
com.lhbdev.moonminer.base.BaseScene.java
com.lhbdev.moonminer.manager.ResourcesManager.java
com.lhbdev.moonminer.manager.SceneManager.java
com.lhbdev.moonminer.object.Dpad.java
com.lhbdev.moonminer.object.Player.java
com.lhbdev.moonminer.scene.GameScene.java
com.lhbdev.moonminer.scene.LoadingScene.java
com.lhbdev.moonminer.scene.MainMenuScene.java
com.lhbdev.moonminer.scene.SplashScene.java