Newer
Older
JumpingGame / src / Velocity.java
import java.util.AbstractMap;
import java.util.Map;

public class Velocity {
	private Map.Entry<Double, Double> acceleration;
	private Map.Entry<Double, Double> move;
	private Position position;
	private Onground onground;
	private Map.Entry<Double, Double> velocity;

	public void updateAcceleration(Map.Entry<Double, Double> acceleration) {
		this.acceleration = acceleration;
		if (onJump())
			velocity = new AbstractMap.SimpleEntry<>((this.velocity.getKey() + (0.01 * acceleration.getKey())), 0.0);
		else
			velocity = new AbstractMap.SimpleEntry<>((this.velocity.getKey() + (0.01 * acceleration.getKey())),
					(this.velocity.getValue() + (0.01 * acceleration.getValue())));
		position.updateVelocity(velocity);
	}

	public void updateMove(Map.Entry<Double, Double> move) {
		this.move = move;
		if (onMove())
			velocity = move;

		position.updateVelocity(velocity);
	}

	public Velocity(Position position, Onground onground) {
		this.onground = onground;
	}

	public Map.Entry<Double, Double> getVelocity() {
		return velocity;
	}

	// AND, In Air
	private boolean onJump() {
		if (!this.onground.getOnground())
			return false;
		return (this.velocity.getValue() < 0.0);
	}

	// AND, Push Button
	private boolean onMove() {
		if (!this.onground.getOnground())
			return false;
		return (move.getValue() >= 0.0);
	}
}