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

public class Acceleration {
	private double mass;
	private Map.Entry<Double, Double> force;
	private Velocity velocity;
	private Onground onground;
	private Map.Entry<Double, Double> acceleration;

	public void updateMass(double mass) {
		this.mass = mass;

		if (getOnground())
			acceleration = new AbstractMap.SimpleEntry<>((force.getKey() / mass), 0.0);
		else
			acceleration = new AbstractMap.SimpleEntry<>((force.getKey() / mass), (force.getValue() / mass));
		velocity.updateAcceleration(acceleration);
	}

	public void updateForce(Map.Entry<Double, Double> force) {
		this.force = force;

		if (getOnground())
			acceleration = new AbstractMap.SimpleEntry<>((force.getKey() / mass), 0.0);
		else
			acceleration = new AbstractMap.SimpleEntry<>((force.getKey() / mass), (force.getValue() / mass));
		velocity.updateAcceleration(acceleration);
	}

	public Acceleration(Velocity velocity, Onground onground) {
		this.onground = onground;
	}

	public Map.Entry<Double, Double> getAcceleration() {
		return acceleration;
	}

	private boolean getOnground() {
		return (this.onground.getOnground());
	}
}