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

public class Position {
	private Map.Entry<Double, Double> velocity;
	private boolean ground;
	private Map.Entry<Double, Double> position;

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

	public void updateGround(boolean ground) {
		this.ground = ground;
		if (getOnGround())
			position = new AbstractMap.SimpleEntry<>((this.position.getKey() + (0.01 * velocity.getKey())), 0.0);
		else
			new AbstractMap.SimpleEntry<>((this.position.getKey() + (0.01 * velocity.getKey())),
					(this.position.getValue() + (0.01 * velocity.getValue())));
	}

	public Map.Entry<Double, Double> getPosition() {
		return position;
	}

	// AND
	private boolean getOnGround() {
		if (!ground)
			return false;
		return ((this.position.getValue() + (0.01 * velocity.getValue())) < 0.0);
	}
}