-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio.js
115 lines (111 loc) · 3.67 KB
/
audio.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
export class AudioControl{
constructor(game){
this.game = game;
this.buttonSound = this.game.assetManager.sounds[4];
this.coinSound = this.game.assetManager.sounds[0];
this.forestSong = this.game.assetManager.sounds[1];
this.menuSong = this.game.assetManager.sounds[2];
this.ruinsSong = this.game.assetManager.sounds[3];
this.playStateSongs = [this.forestSong, this.ruinsSong]
this.winSong = this.game.assetManager.sounds[5];
this.buttonHoverSound = this.game.assetManager.sounds[6];
//ARRAY OF ALL SONGS
this.songs = [this.menuSong, ...this.playStateSongs, this.winSong];
//ARRAY OF ALL SOUNDS
this.sounds = [this.buttonSound, this.buttonHoverSound, this.coinSound];
//loading state buttons?
this.game.ui.loadingBtns.forEach(btn=>{
//hover
btn.addEventListener("mouseover", ()=>{
this.play(this.buttonHoverSound);
})
//click
btn.addEventListener("click", ()=>{
this.play(this.buttonSound);
})
})
//menu state buttons
this.game.ui.menuBtns.forEach(btn=>{
//hover
btn.addEventListener("mouseover", ()=>{
this.play(this.buttonHoverSound);
})
//click
btn.addEventListener("click", ()=>{
this.play(this.buttonSound);
})
})
//level-select state buttons
this.game.ui.levelSelectBtns.forEach(btn=>{
//hover
btn.addEventListener("mouseover", ()=>{
this.play(this.buttonHoverSound);
})
//click
btn.addEventListener("click", () => {
this.play(this.buttonSound);
})
})
//pause state buttons
this.game.ui.pauseBtns.forEach(btn=>{
//hover
btn.addEventListener("mouseover", ()=>{
this.play(this.buttonHoverSound);
})
//click
btn.addEventListener("click", () => {
this.play(this.buttonSound);
})
})
//restart state buttons
this.game.ui.restartBtns.forEach(btn=>{
//hover
btn.addEventListener("mouseover", ()=>{
this.play(this.buttonHoverSound);
})
//click
btn.addEventListener("click", () => {
this.play(this.buttonSound);
})
})
//level complete state buttons
this.game.ui.levelCompleteBtns.forEach(btn=>{
//hover
btn.addEventListener("mouseover", ()=>{
this.play(this.buttonHoverSound);
})
//click
btn.addEventListener("click", () => {
this.play(this.buttonSound);
})
})
//options state buttons
this.game.ui.optionsBtns.forEach(btn=>{
//hover
btn.addEventListener("mouseover", ()=>{
this.play(this.buttonHoverSound);
})
//click
btn.addEventListener("click", () => {
this.play(this.buttonSound);
})
})
//volume controller
this.game.ui.volume_controllers.forEach(controller=>{
controller.addEventListener('change', ()=>{
this.play(this.buttonHoverSound);
})
})
}
play(audio){
audio.currentTime = 0;
audio.play();
}
pause(audio){
audio.pause();
}
stop(audio){
audio.currentTime = 0;
audio.pause();
}
}