-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Entity.pde
48 lines (41 loc) · 1002 Bytes
/
Entity.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
40
41
42
43
44
45
46
47
48
class Entity {
PVector pos;
PVector vel;
PVector acc;
//float mass;
PVector size;
color debugCol;
int TYPE;
Entity(PVector p, PVector s, int t) {
constructor(p, s, t);
}
Entity(float x, float y, float sx, float sy, int t) {
constructor(new PVector(x, y), new PVector(sx, sy), t);
}
void constructor(PVector p, PVector s, int t) {
pos = p.copy();
vel = new PVector(0, 0);
acc = new PVector(0, 0);
//mass = 1;
size = s.copy();
debugCol = color(random(100, 255), random(100, 255), random(100, 255));
TYPE = t;
}
void applyForce(PVector f) {
//f.div(mass); //Do take the mass into account in F = m * a ==> a = F / m
acc.add(f);
}
void update() {
//Newtonian Physics Calculation -->
vel.add(acc);
pos.add(vel);
acc.mult(0);
}
void render() {
canvas.noFill();
canvas.stroke(debugCol);
canvas.strokeWeight(1);
canvas.rectMode(CORNER);
canvas.rect(pos.x, pos.y, size.x, size.y);
}
}