From ee91769e8448d0af6485e49b7a43d943aa7656a2 Mon Sep 17 00:00:00 2001 From: Armin Benz Date: Tue, 25 Apr 2017 18:44:34 +0200 Subject: [PATCH] get the Triggers --- .../game/world/entities/GravityEntity.java | 17 ++++++++++++++- .../entities/gameentities/GetTriggerType.java | 9 ++++++++ .../entities/gameentities/PlayerEntity.java | 21 +++++++++++++++++++ .../game/world/map/provider/MapProvider.java | 2 +- .../input/CRGameInputProcessor.java | 2 +- 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 core/src/de/samdev/colorrunner/game/world/entities/gameentities/GetTriggerType.java diff --git a/core/src/de/samdev/colorrunner/game/world/entities/GravityEntity.java b/core/src/de/samdev/colorrunner/game/world/entities/GravityEntity.java index e4c9c27..cb35bb7 100644 --- a/core/src/de/samdev/colorrunner/game/world/entities/GravityEntity.java +++ b/core/src/de/samdev/colorrunner/game/world/entities/GravityEntity.java @@ -1,10 +1,12 @@ package de.samdev.colorrunner.game.world.entities; import de.samdev.colorrunner.game.world.CRGameWorld; +import de.samdev.colorrunner.game.world.entities.gameentities.GetTriggerType; public abstract class GravityEntity extends MovingEntity { - public final static float GRAVITY_FORCE = 700f; + public float GRAVITY_FORCE = 700f; public final static float TERMINAL_VELOCITY = 900f; + public GetTriggerType getType = GetTriggerType.RUNBOTTOM; public GravityEntity(CRGameWorld _owner, float width, float height) { this(_owner, 0, 0, width, height); @@ -16,6 +18,19 @@ public abstract class GravityEntity extends MovingEntity { @Override public void update(float delta) { + + switch (getType){ + case RUNTOP: + GRAVITY_FORCE = -700; + break; + case RUNBOTTOM: + GRAVITY_FORCE = 700; + break; + case FLY: + GRAVITY_FORCE = 400; + break; + } + velocity.y -= GRAVITY_FORCE * delta; if (velocity.y < -TERMINAL_VELOCITY) { diff --git a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/GetTriggerType.java b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/GetTriggerType.java new file mode 100644 index 0000000..139b5d9 --- /dev/null +++ b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/GetTriggerType.java @@ -0,0 +1,9 @@ +package de.samdev.colorrunner.game.world.entities.gameentities; + +/** + * Created by benza on 23.04.2017. + */ + +public enum GetTriggerType { + RUNBOTTOM, RUNTOP, FLY, NOTHING +} 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 e9b29e1..0546035 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 @@ -10,8 +10,11 @@ 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.game.world.entities.gameentities.floor.FloorTileEntity; +import de.samdev.colorrunner.game.world.map.provider.TriggerType; import de.samdev.colorrunner.screens.menu.MainMenu; +import static de.samdev.colorrunner.game.world.map.provider.TriggerType.RUNTOP; + public class PlayerEntity extends GravityEntity { public final static float PLAYER_WIDTH = 32; public final static float PLAYER_HEIGHT = 32; @@ -26,7 +29,10 @@ public class PlayerEntity extends GravityEntity { private SwipeDirection phase = SwipeDirection.UP; + private boolean doFly = false; + private TriggerType triggerType; + public PlayerEntity(CRGameWorld _owner, float x, float y) { super(_owner, x, y, PLAYER_WIDTH, PLAYER_HEIGHT); @@ -43,6 +49,21 @@ public class PlayerEntity extends GravityEntity { updateRotation(delta); + triggerType = world.mapprovider.getTrigger((int)(bounds.x / FloorTileEntity.FLOORTILE_WIDTH), (int)(bounds.y / FloorTileEntity.FLOORTILE_HEIGHT)); + + switch (triggerType){ + case RUNTOP: + getType = GetTriggerType.RUNTOP; + break; + case RUNBOTTOM: + getType = GetTriggerType.RUNBOTTOM; + break; + case FLY: + getType = GetTriggerType.FLY; + break; + } + + super.update(delta); } diff --git a/core/src/de/samdev/colorrunner/game/world/map/provider/MapProvider.java b/core/src/de/samdev/colorrunner/game/world/map/provider/MapProvider.java index ae29b18..7d077e9 100644 --- a/core/src/de/samdev/colorrunner/game/world/map/provider/MapProvider.java +++ b/core/src/de/samdev/colorrunner/game/world/map/provider/MapProvider.java @@ -14,5 +14,5 @@ public abstract class MapProvider { public abstract MapProvider createNew(); - public abstract Enum getTrigger(int x, int y); + public abstract TriggerType getTrigger(int x, int y); } diff --git a/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java b/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java index d23747b..8f30ba8 100644 --- a/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java +++ b/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java @@ -95,12 +95,12 @@ public class CRGameInputProcessor implements InputProcessor, GestureListener { @Override public boolean touchDown(float x, float y, int pointer, int button) { - owner.doJump(); return false; } @Override public boolean tap(float x, float y, int count, int button) { + owner.doJump(); return false; }