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 && Player.velocity.y > 0) {
			Player.velocity.y += PLAYER_JUMP_FORCE_AIR * delta;
		} else {
			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_INITIAL;
			isJumping = true;
		}
	}
}
