From 9460893b324e9f0c94a775aaa95a0425cc364f2f Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 8 Sep 2015 19:25:13 +0200 Subject: [PATCH] Add Visile lesstime warnig in the JustPlay Modus --- .../java/de/sopa/scene/game/GameScene.java | 17 +++-- .../scene/justplay/JustPlayGameScene.java | 64 ++++++++++++------- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/de/sopa/scene/game/GameScene.java b/app/src/main/java/de/sopa/scene/game/GameScene.java index 5a54ddf3..f7efc6e2 100644 --- a/app/src/main/java/de/sopa/scene/game/GameScene.java +++ b/app/src/main/java/de/sopa/scene/game/GameScene.java @@ -11,11 +11,18 @@ import org.andengine.engine.handler.timer.TimerHandler; import org.andengine.entity.scene.background.Background; +import org.andengine.entity.scene.background.IBackground; +import org.andengine.entity.scene.background.modifier.ColorBackgroundModifier; +import org.andengine.entity.scene.background.modifier.IBackgroundModifier; import org.andengine.entity.text.Text; import org.andengine.input.touch.detector.ContinuousHoldDetector; import org.andengine.util.color.Color; +import org.andengine.util.modifier.IModifier; +import org.andengine.util.modifier.ease.EaseExponentialIn; +import org.andengine.util.modifier.ease.EaseQuadIn; +import org.andengine.util.modifier.ease.EaseQuadInOut; /** @@ -26,11 +33,12 @@ public abstract class GameScene extends BaseScene implements GameSceneObserver { protected GameService gameService; private ContinuousHoldDetector continuousHoldDetector; - private float spacePerTile; + protected float spacePerTile; private Text scoreText; - private GameFieldView gameFieldView; + protected GameFieldView gameFieldView; protected final Level level; protected Level levelBackup; + protected Background background; public GameScene(Level level) { @@ -104,7 +112,7 @@ private void calculateSpacePerTile(int width) { } - private float getTileSceneStartY() { + protected float getTileSceneStartY() { return (camera.getHeight() - (spacePerTile * gameService.getLevel().getField().length)) / 2; } @@ -148,7 +156,8 @@ private void registerTouchHandler() { private void addBackground() { - setBackground(new Background(Color.BLACK)); + background = new Background(Color.BLACK); + setBackground(background); } diff --git a/app/src/main/java/de/sopa/scene/justplay/JustPlayGameScene.java b/app/src/main/java/de/sopa/scene/justplay/JustPlayGameScene.java index 554f0610..9b5e0f73 100644 --- a/app/src/main/java/de/sopa/scene/justplay/JustPlayGameScene.java +++ b/app/src/main/java/de/sopa/scene/justplay/JustPlayGameScene.java @@ -13,8 +13,13 @@ import org.andengine.engine.handler.timer.ITimerCallback; import org.andengine.engine.handler.timer.TimerHandler; +import org.andengine.entity.IEntity; +import org.andengine.entity.modifier.AlphaModifier; +import org.andengine.entity.modifier.IEntityModifier; +import org.andengine.entity.primitive.Rectangle; import org.andengine.entity.sprite.ButtonSprite; import org.andengine.entity.text.Text; +import org.andengine.util.modifier.IModifier; /** @@ -22,16 +27,18 @@ */ public class JustPlayGameScene extends GameScene implements JustPlaySceneObserver { - private final JustPlayLevel justPlayLevel; private TimeBasedGameService timeBasedGameService; private Text leftTime; private boolean leaveScene; private ButtonSprite restartButton; + private Rectangle gameViewBackground; public JustPlayGameScene(JustPlayLevel justPlayLevel) { super(justPlayLevel.getLevel()); - this.justPlayLevel = justPlayLevel; + gameViewBackground = new Rectangle(0f, getTileSceneStartY() + spacePerTile, camera.getWidth(), camera.getWidth(), vbom); + gameViewBackground.setColor(1f,1f,1f,0f); + attachChild(gameViewBackground); leaveScene = false; timeBasedGameService = new TimeBasedGameServiceImpl(justPlayLevel.getLeftTime()); timeBasedGameService.start(); @@ -43,7 +50,6 @@ public JustPlayGameScene(JustPlayLevel justPlayLevel) { public JustPlayGameScene(TimeBasedGameService timeBasedGameService, JustPlayLevel justPlayLevel) { super(justPlayLevel.getLevel()); - this.justPlayLevel = justPlayLevel; leaveScene = false; this.timeBasedGameService = timeBasedGameService; @@ -137,9 +143,9 @@ public void onTimePassed(TimerHandler pTimerHandler) { engine.unregisterUpdateHandler(pTimerHandler); storyService.loadJustPlayScoreSceneFromJustPlayScene( - new JustPlayLevelResult(timeBasedGameService.getRemainingTime(), - gameService.getLevel().getMovesCount(), - gameService.getLevel().getMinimumMovesToSolve())); + new JustPlayLevelResult(timeBasedGameService.getRemainingTime(), + gameService.getLevel().getMovesCount(), + gameService.getLevel().getMinimumMovesToSolve())); } })); } @@ -152,18 +158,9 @@ public void onLostGame() { if (!leaveScene) { restartButton.setEnabled(false); leaveScene = true; - engine.registerUpdateHandler(new TimerHandler(1f, new ITimerCallback() { - - @Override - public void onTimePassed(TimerHandler pTimerHandler) { - - engine.unregisterUpdateHandler(pTimerHandler); - storyService.loadJustPlayLostSceneFromJustPlayScene( - new JustPlayLevelResult(-1, gameService.getLevel().getMovesCount(), - gameService.getLevel().getMinimumMovesToSolve())); - } - })); - } + storyService.loadJustPlayLostSceneFromJustPlayScene(new JustPlayLevelResult(-1, + gameService.getLevel().getMovesCount(), gameService.getLevel().getMinimumMovesToSolve())); + } } @@ -180,15 +177,36 @@ public void updateJustPlayScene() { engine.registerUpdateHandler(new TimerHandler(0.1f, new ITimerCallback() { - @Override - public void onTimePassed(TimerHandler pTimerHandler) { + @Override + public void onTimePassed(TimerHandler pTimerHandler) { - leftTime.setText(String.valueOf(timeBasedGameService.getRemainingTime())); - } - })); + leftTime.setText(String.valueOf(timeBasedGameService.getRemainingTime())); + if (timeBasedGameService.getRemainingTime() <= 5) { + backgroundFlash(); + } + } + })); if (timeBasedGameService.getRemainingTime() == 0 && !gameService.solvedPuzzle()) { onLostGame(); } } + + private void backgroundFlash() { + final AlphaModifier alphaModifier1 = new AlphaModifier(0.1f, 0f, 1f); + final AlphaModifier alphaModifier2 = new AlphaModifier(0.1f, 1f, 0f); + alphaModifier1.addModifierListener(new IEntityModifier.IEntityModifierListener() { + @Override + public void onModifierStarted(IModifier pModifier, IEntity pItem) { + + } + + @Override + public void onModifierFinished(IModifier pModifier, IEntity pItem) { + alphaModifier2.reset(); + gameViewBackground.registerEntityModifier(alphaModifier2); + } + }); + gameViewBackground.registerEntityModifier(alphaModifier1); + } }