-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRectangleEntity.js
More file actions
26 lines (24 loc) · 857 Bytes
/
RectangleEntity.js
File metadata and controls
26 lines (24 loc) · 857 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
//sub-class of Entity
function RectangleEntity(id, x, y,center, color, halfWidth, halfHeight, dynamic, angle) {
Entity.call(this, id, x, y,center,color, dynamic);
this.halfWidth = halfWidth;
this.halfHeight = halfHeight;
this.angle = angle || 0.0;
this.type = "rectangle";
}
//Inherit from Entity and override constructor
RectangleEntity.prototype = new Entity();
RectangleEntity.prototype.constructor = RectangleEntity;
RectangleEntity.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;
ctx.fillRect((this.x-this.halfWidth) * SCALE,
(this.y-this.halfHeight) * SCALE,
(this.halfWidth*2) * SCALE,
(this.halfHeight*2) * SCALE);
ctx.restore();
//Entity.prototype.draw.call(this, ctx);
}