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.scene; /* w ww. j a va2 s .co m*/ import com.cladophora.ssniper.BaseActivity; import com.cladophora.ssniper.GameUtil; import com.cladophora.ssniper.R; import com.cladophora.ssniper.entity.Reticle; import com.cladophora.ssniper.entity.Rifle; import com.cladophora.ssniper.entity.SPen; import org.andengine.engine.camera.Camera; import org.andengine.engine.camera.hud.HUD; import org.andengine.engine.handler.timer.ITimerCallback; import org.andengine.engine.handler.timer.TimerHandler; import org.andengine.entity.IEntity; import org.andengine.entity.modifier.*; 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.util.color.Color; public class TutorialScene extends CameraScene implements IOnSceneTouchListener { public static TutorialScene instance; public static Text tutorialText; public static Rectangle bg; public static HUD tutorialHUD; public static LoopEntityModifier blinkModifier; public static boolean done; public TutorialScene(Camera mCamera) { super(mCamera); instance = this; GameScene.inTutorial = true; GameScene.userControl = false; setBackgroundEnabled(false); setOnSceneTouchListener(this); Reticle.hide(); GameScene.pause(); init(); } public static TutorialScene getSharedInstance () { if (instance == null) { instance = new TutorialScene(BaseActivity.mCamera); } return instance; } public static void init() { done = false; initializeTutorialText(); attachTutorialTextToHUD(); SPen.init(); initializeTutorialHUD(); attachTutorialHUDChildren(); animateSPen(); registerEnemySortHandler(); } public static void animateSPen () { final float pToY = (BaseActivity.CAMERA_HEIGHT * 0.6f) - (SPen.spenSprite.getHeight() / 2); final float pToX = BaseActivity.CAMERA_WIDTH * 0.6f; SPen.spenSprite.registerEntityModifier(new MoveModifier(1.5f,SPen.spenSprite.getX(), pToX,SPen.spenSprite.getY(), pToY) { @Override protected void onModifierFinished(IEntity pItem) { done = true; } } ); } public static void initializeTutorialText() { blinkModifier = new LoopEntityModifier(new SequenceEntityModifier(new FadeOutModifier(1), new FadeInModifier(1))); tutorialText = new Text(0,0,BaseActivity.mNotoSansFont,BaseActivity.getSharedInstance().getString(R.string.tutorial), BaseActivity.getSharedInstance().getVertexBufferObjectManager()); tutorialText.setColor(Color.BLACK); tutorialText.registerEntityModifier(blinkModifier); } public static void attachTutorialTextToHUD() { float x0 = (BaseActivity.CAMERA_WIDTH / 2) - ((tutorialText.getWidth() / 2) + 20); float y0 = (tutorialText.getHeight() * 2) - ((tutorialText.getHeight() / 2) + 20); bg = new Rectangle(x0,y0, tutorialText.getWidth() + 60,tutorialText.getHeight() + 20,BaseActivity.getSharedInstance().getVertexBufferObjectManager()); bg.setColor(Color.WHITE); bg.setAlpha(GameScene.P_ALPHA); tutorialText.setPosition((bg.getWidth()/2) - (tutorialText.getWidth()/2),10); final LoopEntityModifier blinkRepeatedly = new LoopEntityModifier(new SequenceEntityModifier(new FadeOutModifier(1), new FadeInModifier(1))); tutorialText.registerEntityModifier(blinkRepeatedly); } public static void initializeTutorialHUD() { tutorialHUD = new HUD(); BaseActivity.mCamera.setHUD(tutorialHUD); } public static void attachTutorialHUDChildren() { bg.detachSelf(); SPen.spenSprite.detachSelf(); bg.attachChild(tutorialText); tutorialHUD.attachChild(bg); tutorialHUD.attachChild(SPen.spenSprite); } @Override public boolean onSceneTouchEvent(Scene arg0, TouchEvent arg1) { if (!done) { return true; } GameScene.tStart = BaseActivity.getSharedInstance().getEngine().getSecondsElapsedTotal() + 6f; GameScene.resume(); GameScene.getSharedInstance().clearChildScene(); Reticle.show(); Rifle.getSharedInstance().resetValues(); attachSPenToHUD(); autoAimAndFire(3500); return false; } private static void attachSPenToHUD() { SPen.setScale(0.5f); final float pFromX = BaseActivity.CAMERA_WIDTH * 0.6f; final float pFromY = BaseActivity.CAMERA_HEIGHT * 0.6f; Reticle.center.setPosition(pFromX,pFromY); SPen.spenSprite.setPosition(Reticle.center.getX()-(SPen.spenSprite.getWidthScaled() * 0.1f),Reticle.center.getY()- SPen.spenSprite.getHeightScaled()); } public static void autoAimAndFire(final long delay) { GameUtil.getSharedInstance().autoAimAndFireUntilMagEmpty(delay); } public static void registerEnemySortHandler() { GameScene.getSharedInstance().registerUpdateHandler(new TimerHandler(GameScene.CLOCK_RESOLUTION, true, getSortCallback())); } private static ITimerCallback getSortCallback() { return new ITimerCallback() { @Override public void onTimePassed(final TimerHandler pTimerHandler) { GameScene.sortEnemies(); if (!GameScene.inTutorial) { GameScene.getSharedInstance().clearUpdateHandlers(); } } }; } }