Android Open Source - ssniper-andengine Scope Engine






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;
/*from w  ww  .ja va  2  s . com*/
import android.opengl.GLES20;
import org.andengine.engine.Engine;
import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.util.GLState;

public class ScopeEngine extends Engine {
    // ===========================================================
    // Constants
    // ===========================================================

    // ===========================================================
    // Fields
    // ===========================================================

    private final Camera mSecondCamera;
    private int scopeSize = 400;

    // ===========================================================
    // Constructors
    // ===========================================================

    public ScopeEngine(final EngineOptions pEngineOptions, final Camera pSecondCamera) {
        super(pEngineOptions);
        this.mSecondCamera = pSecondCamera;
        int height = (int) pSecondCamera.getHeight();
        switch(height) {
            case 800:
                scopeSize = 400;
                break;
            case 1080:
                scopeSize = 500;
                break;
            case 1600:
                scopeSize = 600;
                break;
            default:
                scopeSize = 400;
                break;
            }
    }

    // ===========================================================
    // Getter & Setter
    // ===========================================================

    @Deprecated
    @Override
    public Camera getCamera() {
        return super.mCamera;
    }

    public Camera getFirstCamera() {
        return super.mCamera;
    }

    public Camera getSecondCamera() {
        return this.mSecondCamera;
    }

    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    @Override
    protected void onDrawScene(final GLState pGLState, final Camera pCamera) {
        if(super.mScene != null) {
            final Camera secondCamera = this.getSecondCamera();

            final int surfaceWidth = this.mSurfaceWidth;
            final int surfaceHeight = this.mSurfaceHeight;

            final int glY = (this.mSurfaceHeight - scopeSize);

            pGLState.enableScissorTest();
  
      /* First Screen. With first camera, on the left half of the screens width. */
            {
                GLES20.glScissor(0, 0, surfaceWidth, surfaceHeight);
                GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight);

                super.mScene.onDraw(pGLState, pCamera);
                pCamera.onDrawHUD(pGLState);
            }
  
      /* Second Screen. With second camera, on the right half of the screens width. */
            {
                GLES20.glScissor(0, glY, scopeSize, scopeSize);
                GLES20.glViewport(0, glY, scopeSize, scopeSize);

                super.mScene.onDraw(pGLState, secondCamera);
                secondCamera.onDrawHUD(pGLState);
            }

            pGLState.disableScissorTest();
        }
    }

    @Override
    protected Camera getCameraFromSurfaceTouchEvent(final TouchEvent pTouchEvent) {
        return this.getFirstCamera();
    }

    @Override
    protected void convertSurfaceToSceneTouchEvent(final Camera pCamera, final TouchEvent pSurfaceTouchEvent) {
        pCamera.convertSurfaceToSceneTouchEvent(pSurfaceTouchEvent, this.mSurfaceWidth, this.mSurfaceHeight);
    }

    @Override
    protected void onUpdateUpdateHandlers(final float pSecondsElapsed) {
        super.onUpdateUpdateHandlers(pSecondsElapsed);
        this.getSecondCamera().onUpdate(pSecondsElapsed);
    }

    @Override
    protected void onUpdateCameraSurface() {
        final int surfaceWidth = this.mSurfaceWidth;
        final int scopeSize = 400;

        this.getFirstCamera().setSurfaceSize(0, 0, surfaceWidth, this.mSurfaceHeight);
        this.getSecondCamera().setSurfaceSize(0, 0, scopeSize, scopeSize);
    }

    // ===========================================================
    // Methods
    // ===========================================================

    // ===========================================================
    // Inner and Anonymous Classes
    // ===========================================================
}




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