-
Notifications
You must be signed in to change notification settings - Fork 11
/
actor.js
36 lines (32 loc) · 841 Bytes
/
actor.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
var Actor = function(id) {
this.id = id;
this.x = 0;
this.y = 0;
this.myActor = false;
}
Actor.prototype.update = function(dt) {
this.x = this.x + this.speed.x * dt;
this.y = this.y + this.speed.y * dt;
if(this.x > SCREEN_WIDTH && this.speed.x > 0) {
this.speed.x = -this.speed.x;
} else if(this.x < 0 && this.speed.x < 0) {
this.speed.x = -this.speed.x;
}
if(this.y > SCREEN_HEIGHT && this.speed.y > 0) {
this.speed.y = -this.speed.y;
} else if(this.y < 0 && this.speed.y < 0) {
this.speed.y = -this.speed.y;
}
}
Actor.prototype.render = function(ctx) {
ctx.beginPath();
ctx.arc(this.x, this.y, 10, 0, 2 * Math.PI);
ctx.stroke();
gctx.font = "10px Arial";
if(this.myActor) {
gctx.fillStyle = "rgb(0, 255, 0)";
} else {
gctx.fillStyle = "rgb(255, 0, 0)";
}
gctx.fillText(""+this.id, this.x-7, this.y+2);
}