-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquad.js
86 lines (84 loc) · 1.7 KB
/
quad.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
module.exports = Quad;
function Quad() { }
Quad.prototype = {
solid: false,
color: "#000000",
Ax: 0,
Ay: 0,
Bx: 0,
By: 0,
Cx: 0,
Cy: 0,
Dx: 0,
Dy: 0,
_x: 0,
_y: 0,
_width: 0,
_height: 0,
get x(){
return this._x;
},
set x(value) {
this._x = value;
this.Ax = value;
this.Bx = value + this.width;
this.Cx = value + this.width;
this.Dx = value;
},
get y(){
return this._y;
},
set y(value) {
this._y = value;
this.Ay = value;
this.By = value;
this.Cy = value + this.height;
this.Dy = value + this.height;
},
get width(){
return this._width;
},
set width(value) {
this._width = value;
this.Bx = value + this.x;
this.Cx = value + this.x;
},
get height(){
return this._height;
},
set height(value) {
this._height = value;
this.Cy = value + this.y;
this.Dy = value + this.y;
},
retangle_definition: function() {
var ret = new Retangle();
ret.Ax = this.Ax;
ret.Bx = this.Bx;
ret.Cx = this.Cx;
ret.Dx = this.Dx;
ret.Ay = this.Ay;
ret.By = this.By;
ret.Cy = this.Cy;
ret.Dy = this.Dy;
return ret;
},
clone: function() {
var clone = new Retangle();
for(var attr in this) {
if(this[attr].clone != null) clone[attr] = this[attr].clone();
else clone[attr] = this[attr];
}
return clone;
},
draw: function(screen) {
screen.ctx.moveTo(0, 0);
screen.ctx.lineTo(this.width, 0);
//screen.ctx.moveTo(this.width, 0);
screen.ctx.lineTo(this.width, this.height);
//screen.ctx.moveTo(this.width, this.height);
screen.ctx.lineTo(0, this.height);
//screen.ctx.moveTo(0, this.height);
screen.ctx.lineTo(0, 0);
},
};