Newer
Older
JumpingGame / src / Velocity.java
import java.util.*;

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;
		velocity = (onJump()
				? new AbstractMap.SimpleEntry<>((this.velocity.getKey() + (0.01 * acceleration.getKey())), 0.0)
				: 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;
		velocity = (onMove() ? move : this.velocity);
		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);
	}
}