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-11 00:24:55 +02:00
|
|
|
import de.samdev.colorrunner.game.world.SwipeDirection;
|
|
|
|
import de.samdev.colorrunner.game.world.entities.CRGameEntity;
|
2014-08-10 17:19:40 +02:00
|
|
|
import de.samdev.colorrunner.game.world.entities.GravityEntity;
|
|
|
|
|
|
|
|
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;
|
2014-08-11 15:36:03 +02:00
|
|
|
|
|
|
|
public final static float PLAYER_ROTATION_SPEED = -200f;
|
|
|
|
|
2014-08-10 20:59:50 +02:00
|
|
|
private SwipeDirection phase = SwipeDirection.UP;
|
2014-08-11 15:36:03 +02:00
|
|
|
|
2014-08-10 20:59:50 +02:00
|
|
|
private boolean doFly = false;
|
2014-08-11 15:36:03 +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-11 15:36:03 +02:00
|
|
|
public void update(float delta) {
|
2014-08-10 20:59:50 +02:00
|
|
|
if (velocity.x < PLAYER_TERMINAL_SPEED)
|
|
|
|
velocity.x += PLAYER_SPEED_FORCE * delta;
|
2014-08-11 15:36:03 +02:00
|
|
|
|
2014-08-10 20:59:50 +02:00
|
|
|
if (doFly)
|
|
|
|
velocity.y += PLAYER_FLY_FORCE * delta;
|
|
|
|
doFly = false;
|
2014-08-11 15:36:03 +02:00
|
|
|
|
|
|
|
if (!isTouching_BOTTOM() || visualRotation % 90 != 0) {
|
|
|
|
if (! isTouching_BOTTOM()) {
|
|
|
|
visualRotation = visualRotation + PLAYER_ROTATION_SPEED * delta;
|
|
|
|
visualRotation = (visualRotation + 720f) % 360f;
|
|
|
|
|
|
|
|
float p = (float) ((Math.max(Math.abs(Math.cos(Math.toRadians(visualRotation + 45))), Math.abs(Math.sin(Math.toRadians(visualRotation + 45)))) * Math.sqrt(PLAYER_WIDTH * PLAYER_WIDTH + PLAYER_HEIGHT * PLAYER_HEIGHT)));
|
|
|
|
updateHitBox(p, p);
|
|
|
|
} else {
|
|
|
|
visualRotation = (visualRotation + 720f) % 90f;
|
|
|
|
|
|
|
|
if (visualRotation < 45)
|
|
|
|
visualRotation = visualRotation + PLAYER_ROTATION_SPEED * delta;
|
|
|
|
else
|
|
|
|
visualRotation = visualRotation - PLAYER_ROTATION_SPEED * delta;
|
|
|
|
|
|
|
|
if (visualRotation >= 90f || visualRotation <= 0f)
|
|
|
|
visualRotation = 0f;
|
|
|
|
|
|
|
|
visualRotation = (visualRotation + 720f) % 90f;
|
|
|
|
|
|
|
|
float p = (float) ((Math.max(Math.abs(Math.cos(Math.toRadians(visualRotation + 45))), Math.abs(Math.sin(Math.toRadians(visualRotation + 45)))) * Math.sqrt(PLAYER_WIDTH * PLAYER_WIDTH + PLAYER_HEIGHT * PLAYER_HEIGHT)));
|
|
|
|
updateHitBox(p, p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
super.update(delta);
|
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-11 15:36:03 +02:00
|
|
|
if (!isTouching_BOTTOM())
|
2014-08-10 20:59:50 +02:00
|
|
|
doFly = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Texture getTexture() {
|
|
|
|
switch (phase) {
|
2014-08-11 15:36:03 +02:00
|
|
|
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 20:59:50 +02:00
|
|
|
}
|
2014-08-10 17:19:40 +02:00
|
|
|
}
|
2014-08-11 00:24:55 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canCollide(boolean actualCollision, CRGameEntity collider) {
|
|
|
|
return collider.canCollide(actualCollision, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public SwipeDirection getPhase() {
|
|
|
|
return phase;
|
|
|
|
}
|
2014-08-10 17:19:40 +02:00
|
|
|
}
|