ColorRunner/core/src/de/samdev/colorrunner/game/world/entities/gameentities/controller/RunTopPlayerController.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 RunTopPlayerController extends AbstractPlayerController {
private boolean isJumping = false;
public RunTopPlayerController(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_TOP() && Player.velocity.y > 0)
Player.velocity.y = 0;
}
@Override
public ControllingType getControllerType() {
return ControllingType.RUNTOP;
}
@Override
public void jumpPressed() {
if (Player.isTouching_TOP()) {
Player.velocity.y = -PLAYER_JUMP_FORCE;
isJumping = true;
}
}
}