From 520973d010e6baafa61454ed45e018d85748fd48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Mon, 11 Aug 2014 00:24:55 +0200 Subject: [PATCH] Reimplemented Colors + cam --- .../game/renderer/AbstractGameRenderer.java | 33 +++-- .../colorrunner/game/renderer/CRAssets.java | 30 ++++- .../game/renderer/CRGameRenderer.java | 2 + .../game/world/AverageExecutionLogger.java | 1 - .../colorrunner/game/world/CRGameWorld.java | 125 +++++++++--------- .../{input => game/world}/SwipeDirection.java | 2 +- .../game/world/entities/CRGameEntity.java | 2 + .../game/world/entities/MovingEntity.java | 33 ++++- .../gameentities/FloorTileEntity.java | 30 ----- .../entities/gameentities/PlayerEntity.java | 12 +- .../floor/DownStateFloorTileEntity.java | 25 ++++ .../gameentities/floor/FloorTileEntity.java | 31 +++++ .../floor/LeftStateFloorTileEntity.java | 25 ++++ .../floor/RightStateFloorTileEntity.java | 25 ++++ .../floor/UpStateFloorTileEntity.java | 25 ++++ .../input/CRGameInputProcessor.java | 2 + .../colorrunner/input/GameInputListener.java | 2 + 17 files changed, 287 insertions(+), 118 deletions(-) rename core/src/de/samdev/colorrunner/{input => game/world}/SwipeDirection.java (58%) delete mode 100644 core/src/de/samdev/colorrunner/game/world/entities/gameentities/FloorTileEntity.java create mode 100644 core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/DownStateFloorTileEntity.java create mode 100644 core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/FloorTileEntity.java create mode 100644 core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/LeftStateFloorTileEntity.java create mode 100644 core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/RightStateFloorTileEntity.java create mode 100644 core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/UpStateFloorTileEntity.java diff --git a/core/src/de/samdev/colorrunner/game/renderer/AbstractGameRenderer.java b/core/src/de/samdev/colorrunner/game/renderer/AbstractGameRenderer.java index d58445c..542c830 100644 --- a/core/src/de/samdev/colorrunner/game/renderer/AbstractGameRenderer.java +++ b/core/src/de/samdev/colorrunner/game/renderer/AbstractGameRenderer.java @@ -6,12 +6,14 @@ import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; +import com.badlogic.gdx.math.Vector3; public abstract class AbstractGameRenderer { private final static float GAME_HEIGHT = 512; private final static float MIN_GAME_WIDTH = 672; // ~ 512 * (4/3) private final static float MAX_GAME_WIDTH = 1024; // ~ 512 * (2/1) // ~~ 16:9 + + private final static float FREE_ROAM_WIDTH = 1f/4f; private int debugTextCount; @@ -31,21 +33,22 @@ public abstract class AbstractGameRenderer { } public void render() { - Gdx.gl.glClearColor(1, 0, 1, 1f); + Gdx.gl.glClearColor(0.22f, 0.22f, 0.22f, 1f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); // ################# - shapeRenderer.begin(ShapeType.Filled); - - shapeRenderer.setColor(0.22f, 0.22f, 0.22f, 1); - shapeRenderer.rect(0, 0, MIN_GAME_WIDTH, GAME_HEIGHT); - - shapeRenderer.end(); - doRender(); } + protected void updateCameraOffset(float lookAtX) { + if (lookAtX > cam.position.x + cam.viewportWidth * FREE_ROAM_WIDTH/2) { + cam.position.x += lookAtX - cam.position.x - cam.viewportWidth * FREE_ROAM_WIDTH/2; + cam.update(); + updateCamMatrices(); + } + } + public void resize(float width, float height) { float cam_width = (width / height) * GAME_HEIGHT; @@ -56,7 +59,10 @@ public abstract class AbstractGameRenderer { Gdx.app.error("SIZE", "Maximal aspect ratio is 2:1"); cam.setToOrtho(false, cam_width, GAME_HEIGHT); - + updateCamMatrices(); + } + + private void updateCamMatrices() { shapeRenderer.setProjectionMatrix(cam.combined); spriteBatch.setProjectionMatrix(cam.combined); fontBatch.setProjectionMatrix(cam.combined); @@ -65,12 +71,13 @@ public abstract class AbstractGameRenderer { protected void beginDebug() { fontBatch.begin(); font.setColor(1, 0, 1, 1); - + debugTextCount = 0; } - + protected void renderDebug(String s) { - font.draw(fontBatch, s, 10, GAME_HEIGHT - 10 - debugTextCount++ * 20); + Vector3 coords = cam.unproject(new Vector3(10, 10 + debugTextCount++ * 20, 0)); + font.draw(fontBatch, s, coords.x, coords.y); } protected void endDebug() { diff --git a/core/src/de/samdev/colorrunner/game/renderer/CRAssets.java b/core/src/de/samdev/colorrunner/game/renderer/CRAssets.java index b75f7f3..4fe36a5 100644 --- a/core/src/de/samdev/colorrunner/game/renderer/CRAssets.java +++ b/core/src/de/samdev/colorrunner/game/renderer/CRAssets.java @@ -10,7 +10,10 @@ public class CRAssets { public static Texture TEX_PLAYER_LEFT; public static Texture TEX_PLAYER_DOWN; - public static Texture TEX_FLOORTILE; + public static Texture TEX_FLOORTILE_UP; + public static Texture TEX_FLOORTILE_DOWN; + public static Texture TEX_FLOORTILE_LEFT; + public static Texture TEX_FLOORTILE_RIGHT; static { { @@ -43,9 +46,30 @@ public class CRAssets { { Pixmap pixmap = new Pixmap(64, 64, Format.RGBA8888); - pixmap.setColor(1, 1, 1, 1); + pixmap.setColor(1, 0, 0, 1); pixmap.fill(); - TEX_FLOORTILE = new Texture(pixmap); + TEX_FLOORTILE_UP = new Texture(pixmap); + } + + { + Pixmap pixmap = new Pixmap(64, 64, Format.RGBA8888); + pixmap.setColor(0, 1, 0, 1); + pixmap.fill(); + TEX_FLOORTILE_RIGHT = new Texture(pixmap); + } + + { + Pixmap pixmap = new Pixmap(64, 64, Format.RGBA8888); + pixmap.setColor(0, 0, 1, 1); + pixmap.fill(); + TEX_FLOORTILE_DOWN = new Texture(pixmap); + } + + { + Pixmap pixmap = new Pixmap(64, 64, Format.RGBA8888); + pixmap.setColor(1, 1, 0, 1); + pixmap.fill(); + TEX_FLOORTILE_LEFT = new Texture(pixmap); } } } diff --git a/core/src/de/samdev/colorrunner/game/renderer/CRGameRenderer.java b/core/src/de/samdev/colorrunner/game/renderer/CRGameRenderer.java index eef7807..26bb50b 100644 --- a/core/src/de/samdev/colorrunner/game/renderer/CRGameRenderer.java +++ b/core/src/de/samdev/colorrunner/game/renderer/CRGameRenderer.java @@ -19,6 +19,8 @@ public class CRGameRenderer extends AbstractGameRenderer { @Override public void doRender() { + updateCameraOffset(gameworld.player.bounds.x); + beginDebug(); renderDebug("FPS: " + (int)gameworld.fps.getFPS()); renderDebug("Entitys: " + gameworld.entities.size()); diff --git a/core/src/de/samdev/colorrunner/game/world/AverageExecutionLogger.java b/core/src/de/samdev/colorrunner/game/world/AverageExecutionLogger.java index be782fd..b36e21a 100644 --- a/core/src/de/samdev/colorrunner/game/world/AverageExecutionLogger.java +++ b/core/src/de/samdev/colorrunner/game/world/AverageExecutionLogger.java @@ -1,6 +1,5 @@ package de.samdev.colorrunner.game.world; -import com.badlogic.gdx.Gdx; import com.badlogic.gdx.utils.TimeUtils; public class AverageExecutionLogger { diff --git a/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java b/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java index 2dd392c..834d385 100644 --- a/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java +++ b/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java @@ -4,87 +4,82 @@ import java.util.ArrayList; import java.util.List; import de.samdev.colorrunner.game.world.entities.CRGameEntity; -import de.samdev.colorrunner.game.world.entities.gameentities.FloorTileEntity; import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity; +import de.samdev.colorrunner.game.world.entities.gameentities.floor.DownStateFloorTileEntity; +import de.samdev.colorrunner.game.world.entities.gameentities.floor.LeftStateFloorTileEntity; +import de.samdev.colorrunner.game.world.entities.gameentities.floor.RightStateFloorTileEntity; +import de.samdev.colorrunner.game.world.entities.gameentities.floor.UpStateFloorTileEntity; import de.samdev.colorrunner.input.GameInputListener; -import de.samdev.colorrunner.input.SwipeDirection; public class CRGameWorld implements GameInputListener { - + public PlayerEntity player; - + public List entities = new ArrayList(); - + public FPSCounter fps = new FPSCounter(); - + public CRGameWorld() { addEntity(player = new PlayerEntity(this, 40, 290)); - - addEntity(new FloorTileEntity(this, 1*32, 32)); - addEntity(new FloorTileEntity(this, 2*32, 32)); - addEntity(new FloorTileEntity(this, 3*32, 32)); - addEntity(new FloorTileEntity(this, 4*32, 32)); - addEntity(new FloorTileEntity(this, 5*32, 32)); - addEntity(new FloorTileEntity(this, 6*32, 32)); - addEntity(new FloorTileEntity(this, 7*32, 32)); - addEntity(new FloorTileEntity(this, 8*32, 32)); - addEntity(new FloorTileEntity(this, 9*32, 32)); - addEntity(new FloorTileEntity(this, 10*32, 32)); - addEntity(new FloorTileEntity(this, 11*32, 32)); - addEntity(new FloorTileEntity(this, 12*32, 32)); - addEntity(new FloorTileEntity(this, 13*32, 32)); - addEntity(new FloorTileEntity(this, 14*32, 32)); - addEntity(new FloorTileEntity(this, 15*32, 32)); - addEntity(new FloorTileEntity(this, 16*32, 32)); - addEntity(new FloorTileEntity(this, 17*32, 32)); - - addEntity(new FloorTileEntity(this, 18*32, 1*32)); - addEntity(new FloorTileEntity(this, 19*32, 2*32)); - addEntity(new FloorTileEntity(this, 19*32, 3*32)); - addEntity(new FloorTileEntity(this, 18*32, 4*32)); - addEntity(new FloorTileEntity(this, 18*32, 5*32)); - addEntity(new FloorTileEntity(this, 19*32, 6*32)); - addEntity(new FloorTileEntity(this, 20*32, 7*32)); - - - addEntity(new FloorTileEntity(this, 21*32, 32)); - addEntity(new FloorTileEntity(this, 22*32, 32)); - addEntity(new FloorTileEntity(this, 26*32, 32)); - addEntity(new FloorTileEntity(this, 27*32, 32)); - addEntity(new FloorTileEntity(this, 28*32, 32)); - addEntity(new FloorTileEntity(this, 29*32, 32)); - addEntity(new FloorTileEntity(this, 29*32, 64)); - + addEntity(new UpStateFloorTileEntity(this, 1 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 2 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 3 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 4 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 5 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 6 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 7 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 8 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 9 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 10 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 11 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 12 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 13 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 14 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 15 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 16 * 32, 32)); + addEntity(new UpStateFloorTileEntity(this, 17 * 32, 32)); - - addEntity(new FloorTileEntity(this, 32*32, 32)); - addEntity(new FloorTileEntity(this, 33*32, 32)); - addEntity(new FloorTileEntity(this, 34*32, 32)); - addEntity(new FloorTileEntity(this, 35*32, 32)); - addEntity(new FloorTileEntity(this, 36*32, 32)); - addEntity(new FloorTileEntity(this, 37*32, 32)); - addEntity(new FloorTileEntity(this, 38*32, 32)); - addEntity(new FloorTileEntity(this, 39*32, 32)); - - + addEntity(new UpStateFloorTileEntity(this, 18 * 32, 1 * 32)); + addEntity(new UpStateFloorTileEntity(this, 19 * 32, 2 * 32)); + addEntity(new UpStateFloorTileEntity(this, 19 * 32, 3 * 32)); + addEntity(new UpStateFloorTileEntity(this, 18 * 32, 4 * 32)); + addEntity(new UpStateFloorTileEntity(this, 18 * 32, 5 * 32)); + addEntity(new UpStateFloorTileEntity(this, 19 * 32, 6 * 32)); + addEntity(new UpStateFloorTileEntity(this, 20 * 32, 7 * 32)); - - addEntity(new FloorTileEntity(this, 11*32, 456)); - addEntity(new FloorTileEntity(this, 12*32, 456)); - addEntity(new FloorTileEntity(this, 13*32, 456)); - addEntity(new FloorTileEntity(this, 14*32, 456)); - addEntity(new FloorTileEntity(this, 15*32, 456)); - addEntity(new FloorTileEntity(this, 16*32, 456)); - addEntity(new FloorTileEntity(this, 17*32, 456)); - addEntity(new FloorTileEntity(this, 18*32, 456)); - addEntity(new FloorTileEntity(this, 19*32, 456)); + addEntity(new RightStateFloorTileEntity(this, 21 * 32, 32)); + addEntity(new RightStateFloorTileEntity(this, 22 * 32, 32)); + addEntity(new RightStateFloorTileEntity(this, 26 * 32, 32)); + addEntity(new RightStateFloorTileEntity(this, 27 * 32, 32)); + addEntity(new RightStateFloorTileEntity(this, 28 * 32, 32)); + addEntity(new RightStateFloorTileEntity(this, 29 * 32, 32)); + addEntity(new RightStateFloorTileEntity(this, 29 * 32, 64)); + + addEntity(new LeftStateFloorTileEntity(this, 32 * 32, 32)); + addEntity(new LeftStateFloorTileEntity(this, 33 * 32, 32)); + addEntity(new LeftStateFloorTileEntity(this, 34 * 32, 32)); + addEntity(new LeftStateFloorTileEntity(this, 35 * 32, 32)); + addEntity(new LeftStateFloorTileEntity(this, 36 * 32, 32)); + addEntity(new LeftStateFloorTileEntity(this, 37 * 32, 32)); + addEntity(new LeftStateFloorTileEntity(this, 38 * 32, 32)); + addEntity(new LeftStateFloorTileEntity(this, 39 * 32, 32)); + + addEntity(new DownStateFloorTileEntity(this, 11 * 32, 456)); + addEntity(new DownStateFloorTileEntity(this, 12 * 32, 456)); + addEntity(new DownStateFloorTileEntity(this, 13 * 32, 456)); + addEntity(new DownStateFloorTileEntity(this, 14 * 32, 456)); + addEntity(new DownStateFloorTileEntity(this, 15 * 32, 456)); + addEntity(new DownStateFloorTileEntity(this, 16 * 32, 456)); + addEntity(new DownStateFloorTileEntity(this, 17 * 32, 456)); + addEntity(new DownStateFloorTileEntity(this, 18 * 32, 456)); + addEntity(new DownStateFloorTileEntity(this, 19 * 32, 456)); } public void update(float delta) { fps.Inc(); - + for (CRGameEntity ent : entities) { ent.update(delta); } @@ -92,7 +87,7 @@ public class CRGameWorld implements GameInputListener { public CRGameEntity addEntity(CRGameEntity ent) { entities.add(ent); - + return ent; } diff --git a/core/src/de/samdev/colorrunner/input/SwipeDirection.java b/core/src/de/samdev/colorrunner/game/world/SwipeDirection.java similarity index 58% rename from core/src/de/samdev/colorrunner/input/SwipeDirection.java rename to core/src/de/samdev/colorrunner/game/world/SwipeDirection.java index dc1f5bd..4eab83e 100644 --- a/core/src/de/samdev/colorrunner/input/SwipeDirection.java +++ b/core/src/de/samdev/colorrunner/game/world/SwipeDirection.java @@ -1,4 +1,4 @@ -package de.samdev.colorrunner.input; +package de.samdev.colorrunner.game.world; public enum SwipeDirection { UP, diff --git a/core/src/de/samdev/colorrunner/game/world/entities/CRGameEntity.java b/core/src/de/samdev/colorrunner/game/world/entities/CRGameEntity.java index 1c2716f..85a49a2 100644 --- a/core/src/de/samdev/colorrunner/game/world/entities/CRGameEntity.java +++ b/core/src/de/samdev/colorrunner/game/world/entities/CRGameEntity.java @@ -31,4 +31,6 @@ public abstract class CRGameEntity { public abstract void update(float delta); public abstract Texture getTexture(); + + public abstract boolean canCollide(boolean actualCollision, CRGameEntity collider); } diff --git a/core/src/de/samdev/colorrunner/game/world/entities/MovingEntity.java b/core/src/de/samdev/colorrunner/game/world/entities/MovingEntity.java index dc007a5..673a6e0 100644 --- a/core/src/de/samdev/colorrunner/game/world/entities/MovingEntity.java +++ b/core/src/de/samdev/colorrunner/game/world/entities/MovingEntity.java @@ -1,6 +1,7 @@ package de.samdev.colorrunner.game.world.entities; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; import de.samdev.colorrunner.game.world.CRGameWorld; @@ -26,12 +27,20 @@ public abstract class MovingEntity extends CRGameEntity { boolean collided = false; + Rectangle original = new Rectangle(bounds); + bounds.x += bx; for (CRGameEntity ent : world.entities) { if (ent == this) continue; - if (ent.bounds.overlaps(bounds)) { + if (ent.bounds.overlaps(bounds) && ent.canCollide(true, this)) { + + if (ent.bounds.overlaps(original)) { + Gdx.app.log("Collision", "Ignore in bounds collision"); + continue; + } + if (bx < 0) { // LEFT float correction = (ent.bounds.x + ent.bounds.width) - bounds.x; @@ -57,13 +66,21 @@ public abstract class MovingEntity extends CRGameEntity { if (by == 0) return false; boolean collided = false; + + Rectangle original = new Rectangle(bounds); bounds.y += by; for (CRGameEntity ent : world.entities) { if (ent == this) continue; - if (ent.bounds.overlaps(bounds)) { + if (ent.bounds.overlaps(bounds) && ent.canCollide(true, this)) { + + if (ent.bounds.overlaps(original)) { + Gdx.app.log("Collision", "Ignore in bounds collision"); + continue; + } + if (by < 0) { // DOWN float correction = (ent.bounds.y + ent.bounds.height) - bounds.y; @@ -94,13 +111,21 @@ public abstract class MovingEntity extends CRGameEntity { for (CRGameEntity ent : world.entities) { if (ent == this) continue; - if (Math.abs((ent.bounds.y + ent.bounds.height) - bounds.y) < F_EPSILON && ent.bounds.x < (bounds.x + bounds.width) && (ent.bounds.x + ent.bounds.width) > bounds.x) { + if (Math.abs((ent.bounds.y + ent.bounds.height) - bounds.y) < F_EPSILON && ent.bounds.x < (bounds.x + bounds.width) && (ent.bounds.x + ent.bounds.width) > bounds.x && ent.canCollide(false, this)) { face_BOTTOM_isTouching = true; } - if (Math.abs((bounds.y + bounds.height) - ent.bounds.y) < F_EPSILON && ent.bounds.x < (bounds.x + bounds.width) && (ent.bounds.x + ent.bounds.width) > bounds.x) { + if (Math.abs((bounds.y + bounds.height) - ent.bounds.y) < F_EPSILON && ent.bounds.x < (bounds.x + bounds.width) && (ent.bounds.x + ent.bounds.width) > bounds.x && ent.canCollide(false, this)) { face_TOP_isTouching = true; } + + if (Math.abs((bounds.x + bounds.width) - ent.bounds.x) < F_EPSILON && ent.bounds.y < (bounds.y + bounds.height) && (ent.bounds.y + ent.bounds.height) > bounds.y && ent.canCollide(false, this)) { + face_RIGHT_isTouching = true; + } + + if (Math.abs((ent.bounds.x + ent.bounds.width) - bounds.x) < F_EPSILON && ent.bounds.y < (bounds.y + bounds.height) && (ent.bounds.y + ent.bounds.height) > bounds.y && ent.canCollide(false, this)) { + face_LEFT_isTouching = true; + } } } diff --git a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/FloorTileEntity.java b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/FloorTileEntity.java deleted file mode 100644 index 174c5a9..0000000 --- a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/FloorTileEntity.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.samdev.colorrunner.game.world.entities.gameentities; - -import com.badlogic.gdx.graphics.Texture; - -import de.samdev.colorrunner.game.renderer.CRAssets; -import de.samdev.colorrunner.game.world.CRGameWorld; -import de.samdev.colorrunner.game.world.entities.StaticEntity; - -public class FloorTileEntity extends StaticEntity { - public final static float FLOORTILE_WIDTH = 32; - public final static float FLOORTILE_HEIGHT = 32; - - public FloorTileEntity(CRGameWorld _owner, float x, float y) { - super(_owner, x, y, FLOORTILE_WIDTH, FLOORTILE_HEIGHT); - // TODO Auto-generated constructor stub - } - - @Override - public void update(float delta) { - // TODO Auto-generated method stub - - } - - @Override - public Texture getTexture() { - // TODO Auto-generated method stub - return CRAssets.TEX_FLOORTILE; - } - -} diff --git a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/PlayerEntity.java b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/PlayerEntity.java index a9a3979..b4b1502 100644 --- a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/PlayerEntity.java +++ b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/PlayerEntity.java @@ -4,8 +4,9 @@ import com.badlogic.gdx.graphics.Texture; import de.samdev.colorrunner.game.renderer.CRAssets; import de.samdev.colorrunner.game.world.CRGameWorld; +import de.samdev.colorrunner.game.world.SwipeDirection; +import de.samdev.colorrunner.game.world.entities.CRGameEntity; import de.samdev.colorrunner.game.world.entities.GravityEntity; -import de.samdev.colorrunner.input.SwipeDirection; public class PlayerEntity extends GravityEntity { public final static float PLAYER_WIDTH = 32; @@ -63,4 +64,13 @@ public class PlayerEntity extends GravityEntity { default: return null; } } + + @Override + public boolean canCollide(boolean actualCollision, CRGameEntity collider) { + return collider.canCollide(actualCollision, this); + } + + public SwipeDirection getPhase() { + return phase; + } } diff --git a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/DownStateFloorTileEntity.java b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/DownStateFloorTileEntity.java new file mode 100644 index 0000000..e43d70f --- /dev/null +++ b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/DownStateFloorTileEntity.java @@ -0,0 +1,25 @@ +package de.samdev.colorrunner.game.world.entities.gameentities.floor; + +import com.badlogic.gdx.graphics.Texture; + +import de.samdev.colorrunner.game.renderer.CRAssets; +import de.samdev.colorrunner.game.world.CRGameWorld; +import de.samdev.colorrunner.game.world.SwipeDirection; + +public class DownStateFloorTileEntity extends FloorTileEntity { + public final SwipeDirection PHASE = SwipeDirection.DOWN; + + public DownStateFloorTileEntity(CRGameWorld _owner, float x, float y) { + super(_owner, x, y); + } + + @Override + public Texture getTexture() { + return CRAssets.TEX_FLOORTILE_DOWN; + } + + @Override + public SwipeDirection getPhase() { + return PHASE; + } +} diff --git a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/FloorTileEntity.java b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/FloorTileEntity.java new file mode 100644 index 0000000..0fd70a5 --- /dev/null +++ b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/FloorTileEntity.java @@ -0,0 +1,31 @@ +package de.samdev.colorrunner.game.world.entities.gameentities.floor; + +import de.samdev.colorrunner.game.world.CRGameWorld; +import de.samdev.colorrunner.game.world.SwipeDirection; +import de.samdev.colorrunner.game.world.entities.CRGameEntity; +import de.samdev.colorrunner.game.world.entities.StaticEntity; +import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity; + +public abstract class FloorTileEntity extends StaticEntity { + public final static float FLOORTILE_WIDTH = 32; + public final static float FLOORTILE_HEIGHT = 32; + + public FloorTileEntity(CRGameWorld _owner, float x, float y) { + super(_owner, x, y, FLOORTILE_WIDTH, FLOORTILE_HEIGHT); + } + + @Override + public void update(float delta) { + // nothing + } + + @Override + public boolean canCollide(boolean actualCollision, CRGameEntity collider) { + if (collider instanceof PlayerEntity && ((PlayerEntity)collider).getPhase() == getPhase()) + return true; + else + return false; + } + + public abstract SwipeDirection getPhase(); +} diff --git a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/LeftStateFloorTileEntity.java b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/LeftStateFloorTileEntity.java new file mode 100644 index 0000000..52caffc --- /dev/null +++ b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/LeftStateFloorTileEntity.java @@ -0,0 +1,25 @@ +package de.samdev.colorrunner.game.world.entities.gameentities.floor; + +import com.badlogic.gdx.graphics.Texture; + +import de.samdev.colorrunner.game.renderer.CRAssets; +import de.samdev.colorrunner.game.world.CRGameWorld; +import de.samdev.colorrunner.game.world.SwipeDirection; + +public class LeftStateFloorTileEntity extends FloorTileEntity { + public final SwipeDirection PHASE = SwipeDirection.LEFT; + + public LeftStateFloorTileEntity(CRGameWorld _owner, float x, float y) { + super(_owner, x, y); + } + + @Override + public Texture getTexture() { + return CRAssets.TEX_FLOORTILE_LEFT; + } + + @Override + public SwipeDirection getPhase() { + return PHASE; + } +} diff --git a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/RightStateFloorTileEntity.java b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/RightStateFloorTileEntity.java new file mode 100644 index 0000000..2b12422 --- /dev/null +++ b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/RightStateFloorTileEntity.java @@ -0,0 +1,25 @@ +package de.samdev.colorrunner.game.world.entities.gameentities.floor; + +import com.badlogic.gdx.graphics.Texture; + +import de.samdev.colorrunner.game.renderer.CRAssets; +import de.samdev.colorrunner.game.world.CRGameWorld; +import de.samdev.colorrunner.game.world.SwipeDirection; + +public class RightStateFloorTileEntity extends FloorTileEntity { + public final SwipeDirection PHASE = SwipeDirection.RIGHT; + + public RightStateFloorTileEntity(CRGameWorld _owner, float x, float y) { + super(_owner, x, y); + } + + @Override + public Texture getTexture() { + return CRAssets.TEX_FLOORTILE_RIGHT; + } + + @Override + public SwipeDirection getPhase() { + return PHASE; + } +} diff --git a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/UpStateFloorTileEntity.java b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/UpStateFloorTileEntity.java new file mode 100644 index 0000000..2ea298d --- /dev/null +++ b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/floor/UpStateFloorTileEntity.java @@ -0,0 +1,25 @@ +package de.samdev.colorrunner.game.world.entities.gameentities.floor; + +import com.badlogic.gdx.graphics.Texture; + +import de.samdev.colorrunner.game.renderer.CRAssets; +import de.samdev.colorrunner.game.world.CRGameWorld; +import de.samdev.colorrunner.game.world.SwipeDirection; + +public class UpStateFloorTileEntity extends FloorTileEntity { + public final SwipeDirection PHASE = SwipeDirection.UP; + + public UpStateFloorTileEntity(CRGameWorld _owner, float x, float y) { + super(_owner, x, y); + } + + @Override + public Texture getTexture() { + return CRAssets.TEX_FLOORTILE_UP; + } + + @Override + public SwipeDirection getPhase() { + return PHASE; + } +} diff --git a/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java b/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java index c07f248..ad68272 100644 --- a/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java +++ b/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java @@ -6,6 +6,8 @@ import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.input.GestureDetector.GestureListener; import com.badlogic.gdx.math.Vector2; +import de.samdev.colorrunner.game.world.SwipeDirection; + public class CRGameInputProcessor implements InputProcessor, GestureListener { private GameInputListener owner; diff --git a/core/src/de/samdev/colorrunner/input/GameInputListener.java b/core/src/de/samdev/colorrunner/input/GameInputListener.java index 034df43..cff08db 100644 --- a/core/src/de/samdev/colorrunner/input/GameInputListener.java +++ b/core/src/de/samdev/colorrunner/input/GameInputListener.java @@ -1,5 +1,7 @@ package de.samdev.colorrunner.input; +import de.samdev.colorrunner.game.world.SwipeDirection; + public interface GameInputListener { public void doJump(); public void doFly();