2014-08-10 17:19:40 +02:00
|
|
|
package de.samdev.colorrunner.game.world.entities.gameentities;
|
|
|
|
|
2014-08-10 20:59:50 +02:00
|
|
|
import com.badlogic.gdx.graphics.Texture;
|
2014-08-10 19:41:06 +02:00
|
|
|
|
2014-08-10 20:59:50 +02:00
|
|
|
import de.samdev.colorrunner.game.renderer.CRAssets;
|
2014-08-10 19:41:06 +02:00
|
|
|
import de.samdev.colorrunner.game.world.CRGameWorld;
|
2014-08-10 17:19:40 +02:00
|
|
|
import de.samdev.colorrunner.game.world.entities.GravityEntity;
|
2014-08-10 19:41:06 +02:00
|
|
|
import de.samdev.colorrunner.input.SwipeDirection;
|
2014-08-10 17:19:40 +02:00
|
|
|
|
|
|
|
public class PlayerEntity extends GravityEntity {
|
|
|
|
public final static float PLAYER_WIDTH = 32;
|
|
|
|
public final static float PLAYER_HEIGHT = 32;
|
2014-08-10 19:41:06 +02:00
|
|
|
|
2014-08-10 20:59:50 +02:00
|
|
|
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;
|
2014-08-10 17:19:40 +02:00
|
|
|
|
2014-08-10 19:41:06 +02:00
|
|
|
public PlayerEntity(CRGameWorld _owner, float x, float y) {
|
|
|
|
super(_owner, x, y, PLAYER_WIDTH, PLAYER_HEIGHT);
|
2014-08-10 20:59:50 +02:00
|
|
|
|
2014-08-10 17:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-08-10 19:41:06 +02:00
|
|
|
public void update(float delta) {
|
2014-08-10 17:19:40 +02:00
|
|
|
super.update(delta);
|
2014-08-10 20:59:50 +02:00
|
|
|
|
|
|
|
if (velocity.x < PLAYER_TERMINAL_SPEED)
|
|
|
|
velocity.x += PLAYER_SPEED_FORCE * delta;
|
|
|
|
|
|
|
|
if (doFly)
|
|
|
|
velocity.y += PLAYER_FLY_FORCE * delta;
|
|
|
|
doFly = false;
|
2014-08-10 19:41:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void jump() {
|
2014-08-10 20:59:50 +02:00
|
|
|
if (isTouching_BOTTOM())
|
2014-08-10 19:41:06 +02:00
|
|
|
velocity.y = PLAYER_JUMP_FORCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void switchPhase(SwipeDirection sd) {
|
2014-08-10 20:59:50 +02:00
|
|
|
phase = sd;
|
2014-08-10 19:41:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void fly() {
|
2014-08-10 20:59:50 +02:00
|
|
|
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;
|
|
|
|
}
|
2014-08-10 17:19:40 +02:00
|
|
|
}
|
|
|
|
}
|