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 setAcceleration(Map.Entry<Double, Double> acceleration) {
		this.acceleration = acceleration;
	}

	public void setMove(Map.Entry<Double, Double> move) {
		this.move = move;
	}

	public void updateAcceleration() {
		velocity = ((this.onground.getOnground() && (this.velocity.getValue() < 0.0))
				? 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.setVelocity(velocity);
		position.updatePosition();
	}

	public void updateMove() {
		velocity = ((this.onground.getOnground() && (move.getValue() >= 0.0)) ? move : this.velocity);

		position.setVelocity(velocity);
		position.updatePosition();
	}

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

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