-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMover.pde
39 lines (32 loc) · 1.05 KB
/
Mover.pde
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
/**
* Representation of an entity that lives in this world and moves.
*/
abstract class Mover {
import toxi.geom.*;
protected Vec2D position; // Our current position.
protected Vec2D velocity; // Our current vector velocity.
protected Vec2D acceleration; // Our current vector of acceleration.
protected float maxSpeed;
protected float maxForce;
/**
* Update our position based on the current velocity,
* and our velocity based on the current acceleration.
* Reset the acceleration to 0 on every cycle.
*/
public void update() {
// Update our velocity based on our current acceleration.
velocity.addSelf(acceleration);
// Limit our speed.
velocity.limit(maxSpeed);
// Update our position based on our current velocity.
position.addSelf(velocity);
// Reset acceleration to 0 each cycle.
acceleration.scaleSelf(0);
}
/**
* Translate force on this Person into acceleration.
*/
protected void applyForce(Vec2D force) {
acceleration.addSelf(force.limit(maxForce));
}
}