forked from Code-Bullet/NEAT-Template-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPeanutButter.js
More file actions
47 lines (37 loc) · 1.03 KB
/
PeanutButter.js
File metadata and controls
47 lines (37 loc) · 1.03 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
class PeanutButter {
static originalSpawnPoints = [
{ x: 400, y: 90 },
{ x: 730, y: 800 },
{ x: 200, y: 600 },
{ x: 985, y: 700 }
];
static spawnPoints = [...PeanutButter.originalSpawnPoints];
constructor() {
let spawn = random(PeanutButter.spawnPoints);
this.x = spawn.x;
this.y = spawn.y;
this.w = 25;
this.h = 25;
this.life = millis() + 20000;
this.idList = [];
}
show() {
image(peanut, this.x, this.y, this.w, this.h);
}
static resetSpawns() {
PeanutButter.spawnPoints = [...PeanutButter.originalSpawnPoints];
}
checkCollision(player) {
let thisLeft = this.x;
let thisRight = this.x + this.w;
let thisTop = this.y;
let thisBottom = this.y + this.h;
let playerLeft = player.x;
let playerRight = player.x + player.w;
let playerTop = player.y;
let playerBottom = player.y + player.h;
let overlapX = thisRight > playerLeft && thisLeft < playerRight;
let overlapY = thisBottom > playerTop && thisTop < playerBottom;
return overlapX && overlapY;
}
}