forked from Code-Bullet/NEAT-Template-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPickup.js
More file actions
52 lines (47 loc) · 1.44 KB
/
Pickup.js
File metadata and controls
52 lines (47 loc) · 1.44 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 Pickup {
constructor(location, sprite, type, width, height) {
this.location = location;
this.x = this.location.x * gridWidth;
this.y = this.location.y * gridHeight;
this.width = width;
this.height = height;
this.sprite = sprite;
this.type = type;
this.idList = [];
this.uuid = crypto.randomUUID();
this.registerLocation();
this.show();
}
show() {
imageMode(CENTER);
image(this.sprite, this.x, this.y, this.width, this.height)
}
registerLocation() {
mapGrid[this.location.y][this.location.x].occupants.push({type: this.type, id: this.uuid})
}
deregisterLocation() {
mapGrid[this.location.y][this.location.x].occupants = mapGrid[this.location.y][this.location.x].occupants.filter(value => {
return value.id !== this.uuid;
})
}
static inList(pickupId, type, playerId) {
switch(type) {
case 2:
let treat = treats.find((treat) => treat.uuid === pickupId);
return treat?.idList.includes(playerId);
break;
case 3:
let peanut = pb.find((peanut) => peanut.uuid === pickupId);
return peanut?.idList.includes(playerId);
break;
case 4:
let ball = balls.find((ball) => ball.uuid === pickupId);
return ball?.idList.includes(playerId);
break;
case 5:
let bed = beds.find((bed) => bed.uuid === pickupId);
return bed?.idList.includes(playerId);
break;
}
}
}