-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPolygonEntity.js
More file actions
34 lines (30 loc) · 928 Bytes
/
PolygonEntity.js
File metadata and controls
34 lines (30 loc) · 928 Bytes
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
function PolygonEntity( id, x, y,center,color, polys, dynamic) {
Entity.call(this, id,x,y,center,color, dynamic);
this.polys = polys;
this.type = "polygon";
}
PolygonEntity.prototype = new Entity();
PolygonEntity.prototype.constructor = PolygonEntity;
PolygonEntity.prototype.draw = function(ctx) {
ctx.save();
ctx.translate(this.x*SCALE, this.y*SCALE);
ctx.rotate(this.angle);
ctx.translate(-(this.x)*SCALE, -(this.y)*SCALE);
ctx.fillStyle = this.color;
for(var i=0; i< this.polys.length; i++) {
var points = this.polys[i];
ctx.beginPath();
ctx.moveTo( (this.x+points[0].x)*SCALE,
(this.y+points[0].y)*SCALE);
for (var j=1; j< points.length; j++) {
ctx.lineTo( (points[j].x+this.x)*SCALE,
(points[j].y+this.y)*SCALE);
}
ctx.lineTo( (this.x+points[0].x)*SCALE,
(this.y+points[0].y)*SCALE);
ctx.closePath();
ctx.fill();
}
ctx.restore();
// Entity.prototype.draw.call(this, ctx);
}