-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboundary.js
45 lines (37 loc) · 1.35 KB
/
boundary.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
function rotatePointX(x, y, point, a) {
return (x - point.x) * cos(a) - (y - point.y) * sin(a);
}
function rotatePointY(x, y, point, a) {
return (x - point.x) * sin(a) + (y - point.y) * cos(a);
}
class Boundary {
constructor(x, y, w, h, a) {
//a *= -(PI / 180);
this.center = createVector(x, y);
this.vertices = [];
this.vertices.push(createVector(rotatePointX(x, y, this.center, a), rotatePointY(x, y, this.center, a)));
this.vertices.push(createVector(rotatePointX(x + w, y, this.center, a), rotatePointY(x + w, y, this.center, a)))
this.vertices.push(createVector(rotatePointX(x + w, y + h, this.center, a), rotatePointY(x + w, y + h, this.center, a)));
this.vertices.push(createVector(rotatePointX(x, y + h, this.center, a), rotatePointY(x, y + h, this.center, a)));
this.vertices.map(v => v.add(this.center));
this.reward = 0.1;
}
show() {
fill(255);
noStroke();
beginShape(QUADS);
for(var i = 0; i < this.vertices.length; ++i) {
vertex(this.vertices[i].x, this.vertices[i].y);
}
endShape(CLOSE);
}
collidesWith(x, y) {
return collidePointPoly(x, y, this.vertices);
}
}
class Target extends Boundary {
constructor(x, y, w, h) {
super(x, y, w, h, 0);
this.reward = 10;
}
}