forked from Lukas-Bloom/N-igma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
powerUp.js
77 lines (72 loc) · 1.8 KB
/
powerUp.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { PLAYER, COL } from "./constants.js";
import { spawnParticles } from "./collisionEvents/powerUpCollisions.js";
import { socket } from "./socket.js";
export default function powerUp() {
return {
update() {},
changePowerUp(powerUp, obj) {
if (this.currentPowerUp === powerUp) {
return;
}
play("sound-powerup2");
spawnParticles(this, COL.BLUE);
destroy(obj);
this.clearPowerUps();
this.currentPowerUp = powerUp;
switch (powerUp) {
case "grow": {
this.scale = vec2(2);
this.width = PLAYER.WIDTH;
this.height = PLAYER.HEIGHT;
break;
}
case "doublejump": {
this.jumpsAmount = 2;
break;
}
case "ghost": {
break;
}
case "shrink": {
this.scale = vec2(0.5);
this.width = PLAYER.WIDTH;
this.height = PLAYER.HEIGHT;
break;
}
case "dash": {
break;
}
case "barrier": {
this.tempColor = this.color
this.color = {r:0, g:225, b:225}
break;
}
default: {
}
}
},
// Add more things that should be cleared
clearPowerUps() {
this.currentPowerUp = "";
this.scale = vec2(1);
this.jumpsAmount = 1;
this.color = this.tempColor || this.color
},
};
}
export const loseBarrier = (counter, player) => {
if (counter === 7) {
socket.emit("powerUp")
player.clearPowerUps()
player.jump(1)
return
}
setTimeout(function () {
if (player.color.r == 0 && player.color.g == 225 && player.color.b == 225) {
player.color = player.tempColor
} else {
player.color = { r: 0, g: 225, b: 225 }
}
loseBarrier(++counter, player)
}, counter * 50)
}