diff --git a/android/assets/levels/plevel001.tmx b/android/assets/levels/plevel001.tmx
index 41050cf..d62d5ca 100644
--- a/android/assets/levels/plevel001.tmx
+++ b/android/assets/levels/plevel001.tmx
@@ -4051,9 +4051,9 @@
-
-
+
+
@@ -4553,7 +4553,7 @@
-
+
@@ -5053,7 +5053,7 @@
-
+
@@ -5553,7 +5553,7 @@
-
+
@@ -6053,7 +6053,7 @@
-
+
@@ -6553,7 +6553,7 @@
-
+
@@ -7053,7 +7053,7 @@
-
+
@@ -7553,7 +7553,7 @@
-
+
@@ -8053,7 +8053,7 @@
-
+
@@ -8553,7 +8553,7 @@
-
+
@@ -9051,9 +9051,9 @@
-
-
+
+
@@ -9546,14 +9546,14 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
@@ -14056,7 +14056,6 @@
-
@@ -14091,6 +14090,7 @@
+
@@ -14590,7 +14590,7 @@
-
+
@@ -15090,7 +15090,7 @@
-
+
@@ -15590,7 +15590,7 @@
-
+
@@ -16090,7 +16090,7 @@
-
+
@@ -16590,7 +16590,7 @@
-
+
@@ -17090,7 +17090,7 @@
-
+
@@ -17590,7 +17590,7 @@
-
+
@@ -18090,7 +18090,7 @@
-
+
@@ -18590,7 +18590,7 @@
-
+
@@ -19056,7 +19056,6 @@
-
@@ -19091,6 +19090,7 @@
+
@@ -19590,7 +19590,7 @@
-
+
diff --git a/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java b/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java
index f9af9f3..132cff0 100644
--- a/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java
+++ b/core/src/de/samdev/colorrunner/game/world/CRGameWorld.java
@@ -13,7 +13,6 @@ import java.util.List;
import de.samdev.colorrunner.CRGame;
import de.samdev.colorrunner.game.world.entities.CRGameEntity;
import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity;
-import de.samdev.colorrunner.game.world.map.provider.EndlessMapProvider;
import de.samdev.colorrunner.game.world.map.provider.MapProvider;
import de.samdev.colorrunner.input.GameInputListener;
import de.samdev.colorrunner.screens.gameScreen.GameScreen;
@@ -101,7 +100,7 @@ public class CRGameWorld implements GameInputListener {
@Override
public void doJump() {
- player.jump();
+ player.jumpPressed();
}
@Override
@@ -109,11 +108,6 @@ public class CRGameWorld implements GameInputListener {
player.switchPhase(sd);
}
- @Override
- public void doFly() {
- player.fly();
- }
-
@Override
public void reset() {
reinitialize();
diff --git a/core/src/de/samdev/colorrunner/game/world/entities/GravityEntity.java b/core/src/de/samdev/colorrunner/game/world/entities/GravityEntity.java
deleted file mode 100644
index 23082dc..0000000
--- a/core/src/de/samdev/colorrunner/game/world/entities/GravityEntity.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package de.samdev.colorrunner.game.world.entities;
-
-import de.samdev.colorrunner.game.world.CRGameWorld;
-import de.samdev.colorrunner.game.world.entities.gameentities.ControllingType;
-
-public abstract class GravityEntity extends MovingEntity {
- public float GRAVITY_FORCE = 700f;
- public final static float TERMINAL_VELOCITY = 900f;
- public ControllingType ctrlType = ControllingType.RUNBOTTOM;
-
- public GravityEntity(CRGameWorld _owner, float width, float height) {
- this(_owner, 0, 0, width, height);
- }
-
- public GravityEntity(CRGameWorld _owner, float x, float y, float width, float height) {
- super(_owner, x, y, width, height);
- }
-
- @Override
- public void update(float delta) {
-
- switch (ctrlType){
- 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) {
- velocity.y = -TERMINAL_VELOCITY;
- }
-
- super.update(delta);
-
- if (isTouching_BOTTOM() && velocity.y < 0)
- velocity.y = 0;
- }
-}
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 c8e945f..3051ad9 100644
--- a/core/src/de/samdev/colorrunner/game/world/entities/MovingEntity.java
+++ b/core/src/de/samdev/colorrunner/game/world/entities/MovingEntity.java
@@ -8,7 +8,7 @@ import de.samdev.colorrunner.CRGame;
import de.samdev.colorrunner.game.world.CRGameWorld;
public abstract class MovingEntity extends CRGameEntity {
- protected Vector2 velocity = new Vector2();
+ public Vector2 velocity = new Vector2();
public final static float EPSILON = 1e-4f;
public final static float EPSILON_TOUCH = 5e-4f;
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 9169d5c..bab75ce 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
@@ -7,17 +7,18 @@ 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.game.world.entities.MovingEntity;
+import de.samdev.colorrunner.game.world.entities.gameentities.controller.AbstractPlayerController;
+import de.samdev.colorrunner.game.world.entities.gameentities.controller.DefaultPlayerController;
+import de.samdev.colorrunner.game.world.entities.gameentities.controller.FlyingPlayerController;
+import de.samdev.colorrunner.game.world.entities.gameentities.controller.InvertedPlayerController;
import de.samdev.colorrunner.game.world.entities.gameentities.floor.FloorTileEntity;
import de.samdev.colorrunner.game.world.map.provider.TriggerType;
-public class PlayerEntity extends GravityEntity {
+public class PlayerEntity extends MovingEntity {
public final static float PLAYER_WIDTH = 31.9f;
public final static float PLAYER_HEIGHT = 31.9f;
- public final static float PLAYER_JUMP_FORCE = 356f;
- public final static float PLAYER_FLY_FORCE = 250f;
-
public final static float PLAYER_SPEED_FORCE = 166f;
public final static float PLAYER_TERMINAL_SPEED = 320f;
@@ -25,10 +26,12 @@ public class PlayerEntity extends GravityEntity {
private SwipeDirection phase = SwipeDirection.UP;
- private boolean doFly = false;
+ private AbstractPlayerController controller;
public PlayerEntity(CRGameWorld _owner, float x, float y) {
super(_owner, x, y, PLAYER_WIDTH, PLAYER_HEIGHT);
+
+ controller = new DefaultPlayerController(this);
}
@Override
@@ -36,29 +39,23 @@ public class PlayerEntity extends GravityEntity {
if (velocity.x < PLAYER_TERMINAL_SPEED)
velocity.x += PLAYER_SPEED_FORCE * delta;
- if (doFly) {
- if ( ctrlType == ControllingType.RUNBOTTOM)
- velocity.y += PLAYER_FLY_FORCE * delta;
- else if(ctrlType == ControllingType.RUNTOP)
- velocity.y += -PLAYER_FLY_FORCE * delta;
- }
- doFly = false;
-
updateRotation(delta);
TriggerType trigger = world.mapprovider.getTrigger((int)((bounds.x + bounds.width/2f) / FloorTileEntity.FLOORTILE_WIDTH), (int)((bounds.y + bounds.height/2f) / FloorTileEntity.FLOORTILE_HEIGHT));
switch (trigger){
case RUNTOP:
- ctrlType = ControllingType.RUNTOP;
+ if (controller.getControllerType() != ControllingType.RUNTOP) controller = new InvertedPlayerController(this);
break;
case RUNBOTTOM:
- ctrlType = ControllingType.RUNBOTTOM;
+ if (controller.getControllerType() != ControllingType.RUNBOTTOM) controller = new DefaultPlayerController(this);
break;
case FLY:
- ctrlType = ControllingType.FLY;
+ if (controller.getControllerType() != ControllingType.FLY) controller = new FlyingPlayerController(this);
break;
}
+ controller.update(delta);
+
super.update(delta);
}
@@ -98,11 +95,8 @@ public class PlayerEntity extends GravityEntity {
}
}
- public void jump() {
- if (isTouching_BOTTOM() && ctrlType == ControllingType.RUNBOTTOM)
- velocity.y = PLAYER_JUMP_FORCE;
- else if(isTouching_TOP() && ctrlType == ControllingType.RUNTOP)
- velocity.y = -PLAYER_JUMP_FORCE;
+ public void jumpPressed() {
+ controller.jumpPressed();
}
public void switchPhase(SwipeDirection sd) {
@@ -118,13 +112,6 @@ public class PlayerEntity extends GravityEntity {
}
}
- public void fly() {
- if (!isTouching_BOTTOM() && ctrlType == ControllingType.RUNBOTTOM)
- doFly = true;
- else if(isTouching_TOP() && ctrlType == ControllingType.RUNTOP)
- doFly = true;
- }
-
@Override
public Texture getTexture() {
switch (phase) {
diff --git a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/AbstractPlayerController.java b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/AbstractPlayerController.java
new file mode 100644
index 0000000..96b8c37
--- /dev/null
+++ b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/AbstractPlayerController.java
@@ -0,0 +1,23 @@
+package de.samdev.colorrunner.game.world.entities.gameentities.controller;
+
+import de.samdev.colorrunner.game.world.entities.gameentities.ControllingType;
+import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity;
+
+public abstract class AbstractPlayerController {
+ public float GRAVITY_FORCE = 700f;
+ public final static float TERMINAL_VELOCITY = 900f;
+
+ public final static float PLAYER_JUMP_FORCE = 356f;
+ public final static float PLAYER_FLY_UP_FORCE = 555f;
+
+ protected final PlayerEntity Player;
+
+ public AbstractPlayerController(PlayerEntity e) {
+ Player = e;
+ }
+
+ public abstract void update(float delta);
+ public abstract ControllingType getControllerType();
+
+ public abstract void jumpPressed();
+}
diff --git a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/DefaultPlayerController.java b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/DefaultPlayerController.java
new file mode 100644
index 0000000..eda7398
--- /dev/null
+++ b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/DefaultPlayerController.java
@@ -0,0 +1,49 @@
+package de.samdev.colorrunner.game.world.entities.gameentities.controller;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.Input;
+
+import de.samdev.colorrunner.game.world.entities.gameentities.ControllingType;
+import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity;
+
+public class DefaultPlayerController extends AbstractPlayerController {
+ private boolean isJumping = false;
+
+ public DefaultPlayerController(PlayerEntity e) {
+ super(e);
+ }
+
+ @Override
+ public void update(float delta) {
+ boolean down = Gdx.input.isKeyPressed(Input.Keys.SPACE) || Gdx.input.isTouched();
+
+ if (!down && isJumping) {
+ if (Player.velocity.y > 0) Player.velocity.y = 0;
+ isJumping = false;
+ }
+
+ if (! down) isJumping = false;
+
+ Player.velocity.y -= GRAVITY_FORCE * delta;
+
+ if (Player.velocity.y < -TERMINAL_VELOCITY) {
+ Player.velocity.y = -TERMINAL_VELOCITY;
+ }
+
+ if (Player.isTouching_BOTTOM() && Player.velocity.y < 0)
+ Player.velocity.y = 0;
+ }
+
+ @Override
+ public ControllingType getControllerType() {
+ return ControllingType.RUNBOTTOM;
+ }
+
+ @Override
+ public void jumpPressed() {
+ if (Player.isTouching_BOTTOM()) {
+ Player.velocity.y = PLAYER_JUMP_FORCE;
+ isJumping = true;
+ }
+ }
+}
diff --git a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/FlyingPlayerController.java b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/FlyingPlayerController.java
new file mode 100644
index 0000000..5cfa80f
--- /dev/null
+++ b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/FlyingPlayerController.java
@@ -0,0 +1,32 @@
+package de.samdev.colorrunner.game.world.entities.gameentities.controller;
+
+import de.samdev.colorrunner.game.world.entities.gameentities.ControllingType;
+import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity;
+
+public class FlyingPlayerController extends AbstractPlayerController {
+ public FlyingPlayerController(PlayerEntity e) {
+ super(e);
+ }
+
+ @Override
+ public void update(float delta) {
+ Player.velocity.y -= GRAVITY_FORCE * delta;
+
+ if (Player.velocity.y < -TERMINAL_VELOCITY) {
+ Player.velocity.y = -TERMINAL_VELOCITY;
+ }
+
+ if (Player.isTouching_BOTTOM() && Player.velocity.y < 0) Player.velocity.y = 0;
+ if (Player.isTouching_TOP() && Player.velocity.y > 0) Player.velocity.y = 0;
+ }
+
+ @Override
+ public ControllingType getControllerType() {
+ return ControllingType.FLY;
+ }
+
+ @Override
+ public void jumpPressed() {
+ Player.velocity.y += PLAYER_FLY_UP_FORCE;
+ }
+}
diff --git a/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/InvertedPlayerController.java b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/InvertedPlayerController.java
new file mode 100644
index 0000000..55ffd64
--- /dev/null
+++ b/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/InvertedPlayerController.java
@@ -0,0 +1,49 @@
+package de.samdev.colorrunner.game.world.entities.gameentities.controller;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.Input;
+
+import de.samdev.colorrunner.game.world.entities.gameentities.ControllingType;
+import de.samdev.colorrunner.game.world.entities.gameentities.PlayerEntity;
+
+public class InvertedPlayerController extends AbstractPlayerController {
+ private boolean isJumping = false;
+
+ public InvertedPlayerController(PlayerEntity e) {
+ super(e);
+ }
+
+ @Override
+ public void update(float delta) {
+ boolean down = Gdx.input.isKeyPressed(Input.Keys.SPACE) || Gdx.input.isTouched();
+
+ if (!down && isJumping) {
+ if (Player.velocity.y < 0) Player.velocity.y = 0;
+ isJumping = false;
+ }
+
+ if (! down) isJumping = false;
+
+ Player.velocity.y += GRAVITY_FORCE * delta;
+
+ if (Player.velocity.y > TERMINAL_VELOCITY) {
+ Player.velocity.y = TERMINAL_VELOCITY;
+ }
+
+ if (Player.isTouching_TOP() && Player.velocity.y > 0)
+ Player.velocity.y = 0;
+ }
+
+ @Override
+ public ControllingType getControllerType() {
+ return ControllingType.RUNTOP;
+ }
+
+ @Override
+ public void jumpPressed() {
+ if (Player.isTouching_TOP()) {
+ Player.velocity.y = -PLAYER_JUMP_FORCE;
+ isJumping = true;
+ }
+ }
+}
diff --git a/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java b/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java
index f785464..7dd99a8 100644
--- a/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java
+++ b/core/src/de/samdev/colorrunner/input/CRGameInputProcessor.java
@@ -1,6 +1,5 @@
package de.samdev.colorrunner.input;
-import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.input.GestureDetector.GestureListener;
@@ -17,9 +16,7 @@ public class CRGameInputProcessor implements InputProcessor, GestureListener {
}
public void update() {
- if (Gdx.input.isKeyPressed(Input.Keys.SPACE) || Gdx.input.isTouched()) {
- owner.doFly();
- }
+
}
@Override
diff --git a/core/src/de/samdev/colorrunner/input/GameInputListener.java b/core/src/de/samdev/colorrunner/input/GameInputListener.java
index 67d8d39..0fcbd76 100644
--- a/core/src/de/samdev/colorrunner/input/GameInputListener.java
+++ b/core/src/de/samdev/colorrunner/input/GameInputListener.java
@@ -4,7 +4,6 @@ import de.samdev.colorrunner.game.world.SwipeDirection;
public interface GameInputListener {
public void doJump();
- public void doFly();
public void switchColor(SwipeDirection sd);
public void reset();
}