Back to project page ssniper-andengine.
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.
package com.cladophora.ssniper; /* w w w.j av a 2 s . c o m*/ import android.os.Bundle; import android.view.KeyEvent; import android.view.ViewGroup; import com.cladophora.ssniper.entity.SPen; import com.cladophora.ssniper.scene.GameScene; import com.cladophora.ssniper.scene.PauseScene; import com.cladophora.ssniper.scene.SplashScene; import org.andengine.engine.Engine; import org.andengine.engine.camera.Camera; import org.andengine.engine.camera.ZoomCamera; import org.andengine.engine.options.EngineOptions; import org.andengine.engine.options.ScreenOrientation; import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy; import org.andengine.entity.scene.Scene; import org.andengine.opengl.font.Font; import org.andengine.opengl.view.RenderSurfaceView; import org.andengine.ui.activity.SimpleBaseGameActivity; import java.util.Random; public class BaseActivity extends SimpleBaseGameActivity { // =========================================================== // Constants // =========================================================== // =========================================================== // Fields // =========================================================== public static BaseActivity instance; public static int CAMERA_WIDTH; public static int CAMERA_HEIGHT; public static float SCOPE_SIZE; public static String SCREEN_TYPE; private static SPenHoverView mSPenHoverView; public static Scene mCurrentScene; public static Camera mCamera; public static ZoomCamera mScopeCamera; public static Random r = new Random(); public static Font mNotoSansFont; public static Font mDigitFont; public static Font mDigitFontL; // =========================================================== // Constructors // =========================================================== public static BaseActivity getSharedInstance() { if (instance == null) { instance = new BaseActivity(); } return instance; } @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); mSPenHoverView = new SPenHoverView(this); final ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); this.addContentView(mSPenHoverView, params); this.mRenderSurfaceView.bringToFront(); } // =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== @Override protected void onSetContentView() { this.mRenderSurfaceView = new RenderSurfaceView(this); this.mRenderSurfaceView.setRenderer(this.mEngine, this); this.setContentView(this.mRenderSurfaceView, createSurfaceViewLayoutParams()); } @Override public EngineOptions onCreateEngineOptions() { instance = this; CAMERA_WIDTH = DeviceUtil.getWidth(instance); CAMERA_HEIGHT = DeviceUtil.getHeight(instance); //SCREEN_TYPE = DeviceUtil.getScreenType(instance); mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); int smallDim; if (CAMERA_HEIGHT < CAMERA_WIDTH) { smallDim = CAMERA_HEIGHT; } else { smallDim = CAMERA_WIDTH; } switch(smallDim) { case 720: SCOPE_SIZE = 400; break; case 800: SCOPE_SIZE = 400; break; case 1080: SCOPE_SIZE = 500; break; case 1600: SCOPE_SIZE = 600; break; default: SCOPE_SIZE = 400; break; } mScopeCamera = new ZoomCamera(0, 0, SCOPE_SIZE, SCOPE_SIZE); final RatioResolutionPolicy pResolutionPolicy = new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT); final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_SENSOR, pResolutionPolicy, mCamera ); engineOptions.getAudioOptions().setNeedsSound(true); return engineOptions; } @Override public Engine onCreateEngine(final EngineOptions pEngineOptions) { return new ScopeEngine(pEngineOptions, this.mScopeCamera); } @Override protected void onCreateResources() { SpriteManager.loadGraphics(); SpriteManager.loadFonts(); com.cladophora.ssniper.SoundManager.loadSounds(); } @Override protected void onPause() { if (GameScene.inGame) { SPen.setEntityPositions(); GameScene.pause(); } super.onPause(); } @Override protected void onResume() { super.onResume(); SpriteManager.loadGraphics(); SpriteManager.loadFonts(); com.cladophora.ssniper.SoundManager.loadSounds(); SpriteManager.initializeRifleSprites(); if (GameScene.inGame) { GameScene.resume(); } } @Override public synchronized void onResumeGame() { if (this.mEngine != null) { super.onResumeGame(); } } @Override protected Scene onCreateScene() { mCurrentScene = new SplashScene(); return mCurrentScene; } @Override public boolean onKeyDown(final int pKeyCode, final KeyEvent pEvent) { if(pEvent.getAction() != KeyEvent.ACTION_DOWN || !GameScene.inGame) { return super.onKeyDown(pKeyCode, pEvent); } if(pKeyCode == KeyEvent.KEYCODE_MENU) { GameScene.mCurrentScene.setChildScene(new PauseScene(mCamera), false, true, true); return true; } else if (pKeyCode == KeyEvent.KEYCODE_VOLUME_DOWN && (!GameScene.slowTimeActive && GameScene.slowTimeBank > (GameScene.SLOW_TIME_BANK_MAX * 0.5f))) { GameScene.activateSlowTime(); return true; } else { return super.onKeyDown(pKeyCode, pEvent); } } // =========================================================== // Methods // =========================================================== // to change the current main scene public static void setCurrentScene(Scene scene) { mCurrentScene = null; mCurrentScene = scene; BaseActivity.getSharedInstance().getEngine().setScene(mCurrentScene); } // =========================================================== // Inner and Anonymous Classes // =========================================================== }