-
Notifications
You must be signed in to change notification settings - Fork 0
/
controls.js
64 lines (62 loc) · 1.7 KB
/
controls.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
export class Controls {
constructor(game) {
this.handleKeyUp = this.handleKeyUp.bind(this);
this.game = game;
this.handleKeyDown = this.handleKeyDown.bind(this);
this.fireballAudio = new Audio();
this.fireballAudio = new Audio();
this.fireballAudio.src =
"https://raw.githubusercontent.com/eric2523/survive-the-nights/main/sound/Fireball-Sharp-Whoosh-www.fesliyanstudios.com.mp3";
this.fireballAudio.loop = false;
this.fireballAudio.volume = 0.25;
}
handleKeyUp() {
if (!this.game.player.animatingDeath) {
this.game.player.stopMoving();
}
}
handleKeyDown() {
if (!this.game.player.animatingDeath) {
switch (event.keyCode) {
case 37:
this.game.player.fire("left");
if (this.game.playSound){
this.fireballAudio.play();
}
break;
case 38:
this.game.player.fire("up");
if (this.game.playSound){
this.fireballAudio.play();
}
break;
case 39:
this.game.player.fire("right");
if (this.game.playSound){
this.fireballAudio.play();
}
break;
case 40:
this.game.player.fire("down");
if (this.game.playSound){
this.fireballAudio.play();
}
break;
case 83:
this.game.player.changeDirection("down");
break;
case 87:
this.game.player.changeDirection("up");
break;
case 65:
this.game.player.changeDirection("left");
break;
case 68:
this.game.player.changeDirection("right");
break;
default:
break;
}
}
}
}