ColorRunner/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/RunBottomPlayerController.java

50 lines
1.2 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;
public class RunBottomPlayerController extends AbstractPlayerController {
private boolean isJumping = false;
public RunBottomPlayerController(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;
}
}
}