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.GravityEntity; import de.samdev.colorrunner.input.SwipeDirection; public class PlayerEntity extends GravityEntity { public final static float PLAYER_WIDTH = 32; public final static float PLAYER_HEIGHT = 32; 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; private SwipeDirection phase = SwipeDirection.UP; private boolean doFly = false; public PlayerEntity(CRGameWorld _owner, float x, float y) { super(_owner, x, y, PLAYER_WIDTH, PLAYER_HEIGHT); } @Override public void update(float delta) { super.update(delta); if (velocity.x < PLAYER_TERMINAL_SPEED) velocity.x += PLAYER_SPEED_FORCE * delta; if (doFly) velocity.y += PLAYER_FLY_FORCE * delta; doFly = false; } public void jump() { if (isTouching_BOTTOM()) velocity.y = PLAYER_JUMP_FORCE; } public void switchPhase(SwipeDirection sd) { phase = sd; } public void fly() { if (! isTouching_BOTTOM()) doFly = true; } @Override public Texture getTexture() { switch (phase) { case UP: return CRAssets.TEX_PLAYER_UP; case RIGHT: return CRAssets.TEX_PLAYER_RIGHT; case DOWN: return CRAssets.TEX_PLAYER_DOWN; case LEFT: return CRAssets.TEX_PLAYER_LEFT; default: return null; } } }