From a2d19985e71c21d07cbb18d2e86c936412d5231d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Mon, 11 Aug 2014 21:36:01 +0200 Subject: [PATCH] added [R]eset --- .../game/renderer/AbstractGameRenderer.java | 6 ++++++ .../colorrunner/game/world/CRGameWorld.java | 18 +++++++++++++++--- .../input/CRGameInputProcessor.java | 7 +++++++ .../colorrunner/input/GameInputListener.java | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/core/src/de/samdev/colorrunner/game/renderer/AbstractGameRenderer.java b/core/src/de/samdev/colorrunner/game/renderer/AbstractGameRenderer.java index 548f378..b5b2241 100644 --- a/core/src/de/samdev/colorrunner/game/renderer/AbstractGameRenderer.java +++ b/core/src/de/samdev/colorrunner/game/renderer/AbstractGameRenderer.java @@ -48,6 +48,12 @@ public abstract class AbstractGameRenderer { cam.update(); updateCamMatrices(); } + + if (lookAtX < cam.position.x - cam.viewportWidth/2) { + cam.position.x += lookAtX - cam.position.x + cam.viewportWidth/2; + cam.update(); + updateCamMatrices(); + } } public Rectangle getCamViewRectangle() { diff --git a/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java b/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java index 478fab7..646f789 100644 --- a/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java +++ b/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java @@ -24,8 +24,8 @@ import de.samdev.colorrunner.input.GameInputListener; public class CRGameWorld implements GameInputListener { public PlayerEntity player; - public List entities = new ArrayList(); - public List sections = new ArrayList(); + public List entities; + public List sections; public FPSCounter fps = new FPSCounter(); @@ -34,9 +34,16 @@ public class CRGameWorld implements GameInputListener { public Rectangle camViewBoundaries = new Rectangle(); public CRGameWorld() { + reinitialize(); + } + + private void reinitialize() { + entities = new ArrayList(); + sections = new ArrayList(); + addEntity(player = new PlayerEntity(this, 40, 290)); - mapRightBoundary = appendMap(CRMapStorage.map_start, new Vector2(mapRightBoundary, 0)); + mapRightBoundary = appendMap(CRMapStorage.map_start, new Vector2(0, 0)); expandMap(); } @@ -133,4 +140,9 @@ public class CRGameWorld implements GameInputListener { public void doFly() { player.fly(); } + + @Override + public void reset() { + reinitialize(); + } } diff --git a/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java b/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java index 3d9fa0a..d23747b 100644 --- a/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java +++ b/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java @@ -6,6 +6,7 @@ import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.input.GestureDetector.GestureListener; import com.badlogic.gdx.math.Vector2; +import de.samdev.colorrunner.CRGame; import de.samdev.colorrunner.game.world.SwipeDirection; public class CRGameInputProcessor implements InputProcessor, GestureListener { @@ -47,6 +48,12 @@ public class CRGameInputProcessor implements InputProcessor, GestureListener { owner.doJump(); return true; } + + + if (keycode == Input.Keys.R && CRGame.DEBUG) { + owner.reset(); + return true; + } return false; } diff --git a/core/src/de/samdev/colorrunner/input/GameInputListener.java b/core/src/de/samdev/colorrunner/input/GameInputListener.java index cff08db..67d8d39 100644 --- a/core/src/de/samdev/colorrunner/input/GameInputListener.java +++ b/core/src/de/samdev/colorrunner/input/GameInputListener.java @@ -6,4 +6,5 @@ public interface GameInputListener { public void doJump(); public void doFly(); public void switchColor(SwipeDirection sd); + public void reset(); }