-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensor.js
More file actions
34 lines (26 loc) · 958 Bytes
/
Copy pathsensor.js
File metadata and controls
34 lines (26 loc) · 958 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
34
class Sensor {
constructor(dirX, dirY) {
this.direction = createVector(dirX, dirY);
this.position = createVector();
this.collisionPoint = createVector();
this.distance = 0;
}
show() {
stroke(210, 210, 210);
strokeWeight(1);
line(this.position.x, this.position.y, this.collisionPoint.x, this.collisionPoint.y);
fill(230, 170, 170);
noStroke();
ellipse(this.collisionPoint.x, this.collisionPoint.y, 7, 7);
}
update(posX, posY) {
this.position.x = posX;
this.position.y = posY;
this.collisionPoint.x = posX;
this.collisionPoint.y = posY;
while (!gTerrain.collidesCircle(this.collisionPoint.x, this.collisionPoint.y, 1)) {
this.collisionPoint.add(this.direction.x, this.direction.y);
}
this.distance = dist(posX, posY, this.collisionPoint.x, this.collisionPoint.y);
}
}