forked from Code-Bullet/NEAT-Template-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDogBed.js
More file actions
52 lines (42 loc) · 1.06 KB
/
DogBed.js
File metadata and controls
52 lines (42 loc) · 1.06 KB
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
class DogBed {
static originalSpawnPoints = [
{ x: 200, y: 240 },
{ x: 750, y: 100 },
{ x: 800, y: 570 },
{ x: 102, y: 830 }
];
static spawnPoints = [...DogBed.originalSpawnPoints];
constructor() {
let spawn = random(DogBed.spawnPoints);
this.x = spawn.x;
this.y = spawn.y;
this.r = 20;
this.life = millis() + 15000;
this.idList = [];
}
show() {
imageMode(CENTER);
image(bed, this.x, this.y, this.r * 2, this.r * 2);
imageMode(CORNER);
}
static resetSpawns() {
DogBed.spawnPoints = [...DogBed.originalSpawnPoints];
}
checkCollision(player) {
let playerLeft = player.x;
let playerRight = player.x + player.w;
let playerTop = player.y;
let playerBottom = player.y + player.h;
let closestX = constrain(this.x, playerLeft, playerRight);
let closestY = constrain(this.y, playerTop, playerBottom);
let dx = this.x - closestX;
let dy = this.y - closestY;
let distanceSq = dx * dx + dy * dy;
if (distanceSq < this.r * this.r) {
this.collected = true;
return true;
}
return false;
}
A
}