46 lines
1.1 KiB
Java
46 lines
1.1 KiB
Java
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;
|
|
|
|
/**
|
|
* Created by benza on 25.05.2017.
|
|
*/
|
|
|
|
public class GravityPlayerController extends AbstractPlayerController{
|
|
public GravityPlayerController(PlayerEntity e)
|
|
{
|
|
super(e);
|
|
}
|
|
|
|
@Override
|
|
public void update(float delta) {
|
|
boolean down = Gdx.input.isKeyPressed(Input.Keys.SPACE) || Gdx.input.isTouched();
|
|
|
|
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.GRAVITY;
|
|
}
|
|
|
|
@Override
|
|
public void jumpPressed() {
|
|
if(Player.isTouching_BOTTOM() || Player.isTouching_TOP())
|
|
{
|
|
GRAVITY_FORCE = GRAVITY_FORCE * -1;
|
|
}
|
|
}
|
|
}
|