Android Open Source - ssniper-andengine Pause Scene






From Project

Back to project page ssniper-andengine.

License

The source code is released under:

Apache License

If you think the Android project ssniper-andengine 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.cladophora.ssniper.scene;
/*  w  ww  . j av  a  2 s.co  m*/
import com.cladophora.ssniper.BaseActivity;
import com.cladophora.ssniper.R;
import com.cladophora.ssniper.entity.Rifle;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.camera.hud.HUD;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.CameraScene;
import org.andengine.entity.scene.IOnSceneTouchListener;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.text.Text;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.color.Color;

public class PauseScene extends CameraScene implements IOnSceneTouchListener {

    public static PauseScene instance;
    private float timePaused;
    public static HUD lastHUD;
    public static HUD pauseMenu;
    public static Text button1T;
    public static Text button2T;
    public static Rectangle button1;
    public static Rectangle button2;
    public static float menuPadding;


    public PauseScene(final Camera mCamera) {
    super(mCamera);
        instance = this;
        lastHUD = GameScene.mCamera.getHUD();
        GameScene.pause();
        GameScene.inGame = false;
        setBackgroundEnabled(false);
        setOnSceneTouchListener(this);
        GameScene.deactivateSlowTime();
        timePaused = BaseActivity.getSharedInstance().getEngine().getSecondsElapsedTotal();
        init();
    }

    public static void init() {
        initializePauseMenuHUD();
        initializePauseMenuButtons();
        setPauseMenuButtonPositions();
        initializeTouchAreas();
        attachPauseMenuEntities();
    }

    public static PauseScene getSharedInstance() {
        if (instance == null) {
            instance = new PauseScene(BaseActivity.mCamera);
        }
        return instance;
    }

    private static void initializeTouchAreas() {
        instance.registerTouchArea(button1);
        instance.registerTouchArea(button2);
    }

    private static void initializePauseMenuHUD() {
        pauseMenu = new HUD();
        BaseActivity.mCamera.setHUD(pauseMenu);
    }

    private static void initializePauseMenuButtons() {
        final VertexBufferObjectManager vbom = BaseActivity.getSharedInstance().getVertexBufferObjectManager();
        final BaseActivity activity = BaseActivity.getSharedInstance();

        menuPadding = 20;

        button1T = new Text(0,0,BaseActivity.mNotoSansFont,activity.getString(R.string.survivor0), vbom);
        button2T = new Text(0,0,BaseActivity.mNotoSansFont,activity.getString(R.string.start), vbom);

        final float button1w = button1T.getWidth() + menuPadding * 2;
        final float button1h = button1T.getHeight() + menuPadding * 2;
        final float button2w = button2T.getWidth() + menuPadding * 2;
        final float button2h = button2T.getHeight() + menuPadding * 2;

        button1 = new Rectangle(0,0, button1w, button1h,vbom) {
            @Override
            public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float X, float Y) {
                if (pSceneTouchEvent.isActionUp()) {
                    goToSurvivorMode();
                }
                return true;
            }
        };
        button2 = new Rectangle(0,0, button2w, button2h,vbom) {
            @Override
            public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float X, float Y) {
                if (pSceneTouchEvent.isActionUp()) {
                    goToArcadeMode();
                }
                return true;
            }
        };

    }

    private static void setPauseMenuButtonPositions() {
        final float button1Tx = BaseActivity.SCOPE_SIZE + menuPadding;
        final float button1Ty = button1.getHeight() * 3;
        final float button2Tx = BaseActivity.SCOPE_SIZE + menuPadding;
        final float button2Ty = button1Ty + button1T.getHeight() + menuPadding * 4;
        final float button1x = button1Tx - menuPadding;
        final float button1y = button1Ty - menuPadding;
        final float button2x = button2Tx - menuPadding;
        final float button2y = button2Ty - menuPadding;
        button1T.setPosition(button1Tx, button1Ty);
        button2T.setPosition(button2Tx, button2Ty);
        button1.setPosition(button1x, button1y);
        button2.setPosition(button2x, button2y);
        button1T.setColor(Color.BLACK);
        button2T.setColor(Color.BLACK);
        button1.setColor(Color.WHITE);
        button2.setColor(Color.WHITE);
        button1.setAlpha(GameScene.P_ALPHA);
        button2.setAlpha(GameScene.P_ALPHA);
    }

    private static void attachPauseMenuEntities() {
        button1.detachSelf();
        button2.detachSelf();
        button1T.detachSelf();
        button2T.detachSelf();
        pauseMenu.attachChild(button1);
        pauseMenu.attachChild(button2);
        pauseMenu.attachChild(button1T);
        pauseMenu.attachChild(button2T);
    }

    @Override
  public boolean onSceneTouchEvent(Scene arg0, TouchEvent arg1) {
        GameScene.tStart += BaseActivity.getSharedInstance().getEngine().getSecondsElapsedTotal() - timePaused;
        Rifle.getSharedInstance().resetValues();
        leavePauseMenu();
        if (GameScene.inTutorial) {TutorialScene.autoAimAndFire(2500);}
        return false;
  }

    private static void leavePauseMenu() {
        GameScene.inGame = true;
        GameScene.resume();
        GameScene.mCurrentScene.clearChildScene();
        GameScene.mCamera.setHUD(lastHUD);
    }

    private static void goToSurvivorMode() {
        GameScene.inTutorial = false;
        SurvivorScene.inSurvivorMode = true;
        leavePauseMenu();
        GameScene.exitMission();
        GameScene.loadLevel(0);
    }

    private static void goToArcadeMode() {
        GameScene.inTutorial = false;
        SurvivorScene.inSurvivorMode = false;
        leavePauseMenu();
        GameScene.exitMission();
        GameScene.loadLevel(GameScene.levelID);
    }


}




Java Source Code List

com.cladophora.ssniper.BaseActivity.java
com.cladophora.ssniper.DeviceUtil.java
com.cladophora.ssniper.EnemyPool.java
com.cladophora.ssniper.GameEffects.java
com.cladophora.ssniper.GameEvents.java
com.cladophora.ssniper.GameLoopUpdateHandler.java
com.cladophora.ssniper.GameUtil.java
com.cladophora.ssniper.HUDManager.java
com.cladophora.ssniper.HoverListener.java
com.cladophora.ssniper.ItemPool.java
com.cladophora.ssniper.LevelLoader.java
com.cladophora.ssniper.PlantPool.java
com.cladophora.ssniper.SPenHoverView.java
com.cladophora.ssniper.ScopeEngine.java
com.cladophora.ssniper.SoundManager.java
com.cladophora.ssniper.SpriteManager.java
com.cladophora.ssniper.andengine.IRandomTimerCallBack.java
com.cladophora.ssniper.andengine.RandomTimerHandler.java
com.cladophora.ssniper.entity.EnemyLayer.java
com.cladophora.ssniper.entity.Enemy.java
com.cladophora.ssniper.entity.ItemLayer.java
com.cladophora.ssniper.entity.Item.java
com.cladophora.ssniper.entity.PlantLayer.java
com.cladophora.ssniper.entity.Plant.java
com.cladophora.ssniper.entity.Reticle.java
com.cladophora.ssniper.entity.Rifle.java
com.cladophora.ssniper.entity.SPen.java
com.cladophora.ssniper.scene.GameScene.java
com.cladophora.ssniper.scene.InstructionScene.java
com.cladophora.ssniper.scene.IntroScene.java
com.cladophora.ssniper.scene.MainMenuScene.java
com.cladophora.ssniper.scene.PauseScene.java
com.cladophora.ssniper.scene.ResultScene.java
com.cladophora.ssniper.scene.ShopScene.java
com.cladophora.ssniper.scene.SplashScene.java
com.cladophora.ssniper.scene.SurvivorIntroScene.java
com.cladophora.ssniper.scene.SurvivorScene.java
com.cladophora.ssniper.scene.TutorialScene.java
com.cladophora.ssniper.scene.WeaponInfoScene.java