-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity.js
43 lines (40 loc) · 838 Bytes
/
entity.js
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
function Entity(x, y, color) {
this.x = x;
this.y = y;
this.x_v = 0;
this.y_v = 0;
this.color = color;
this.radius = 1;
this.active = true;
this.clip = true;
this.updaters = [
];
this.addUpdater = function(u) {
this.updaters.push(u);
};
this.update = function(time) {
for (var i=0 ; i<this.updaters.length ; ++i) {
this.updaters[i](this,time);
}
}
this.collide = function(otherP) {
this.active = false;
}
this.draw = function(ctx, time) {
ctx.fillStyle = this.color;
ctx.beginPath();
ctx.arc(this.x, this.y, this.radius, 0, 2 * Math.PI, true);
ctx.fill();
}
}
function drawentities(time, entities) {
ctx.save();
ctx.translate(offset.x, offset.y);
for(var i=0 ; i<entities.length ; ++i) {
var p = entities[i];
if (p.active) {
entities[i].draw(ctx, time);
}
}
ctx.restore();
}