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

public class Velocity {
	private Vector2 acceleration;
	private Vector2 move;
	private Position position;
	private Onground onground;
	private Vector2 velocity;

	public void updateAcceleration(Vector2 acceleration) {
		this.acceleration = acceleration;
		velocity = ((this.onground.getOnground() && (this.velocity.getY() < 0.0))
				? new Vector2(this.velocity.getX() + (0.01 * acceleration.getX()), 0.0)
				: new Vector2(this.velocity.getX() + (0.01 * acceleration.getX()),
						(this.velocity.getY() + (0.01 * acceleration.getY()))));
		position.updateVelocity(velocity);
	}

	public void updateMove(Vector2 move) {
		this.move = move;
		velocity = ((this.onground.getOnground() && (move.getY() >= 0.0)) ? move : this.velocity);
		position.updateVelocity(velocity);
	}

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

	public Vector2 getVelocity() {
		return velocity;
	}
}