-
Notifications
You must be signed in to change notification settings - Fork 0
/
Position.java
41 lines (38 loc) · 949 Bytes
/
Position.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Class representing the position vector
*
* @author Austin
* @version 0
*/
public class Position extends Vector {
/**
* Constructor for Position with starting values
*
* @param x The x component of position
* @param y The y component of position
*/
public Position(double x, double y) {
super(x, y);
}
/**
* Constructor for a 0 Position
*/
public Position() {
super(0, 0);
}
/**
* Updates the position with a velocity over some time
*
* @param vel The velocity of the object with the position
* @param dt The time since the last update
*/
public void updateWithVelocity(Velocity vel, double dt) {
x += vel.getX() * dt;
y += vel.getY() * dt;
// Causes the object to bounce
if (y <= 0) {
y = 0;
vel.setY(vel.getY() * -0.5);
}
}
}