-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.js
111 lines (95 loc) · 2.47 KB
/
menu.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
/**
* Menu controls for interfacting with the index.html HTML document.
*/
/**
* Setup menu controls
*/
var Menu = function(){
//Setup lobby client.
this.lobby = new LobbyClient(this);
//Setup lobby socket io.
this.lobby.newSocket();
};
/**
* Code to execute when player enters game lobby.
*/
Menu.prototype.join = function(){
var scenarioMenu = document.getElementById('scenario');
var scenarioName = scenarioMenu.options[scenarioMenu.selectedIndex].value;
//Setup lobby client.
this.lobby.joinGame(scenarioName);
mainMenu.style.visibility="hidden";
waiting.style.visibility="visible";
game.style.visibility="hidden";
score.style.visibility="hidden";
}
Menu.prototype.start = function(){
mainMenu.style.visibility="hidden";
waiting.style.visibility="hidden";
game.style.visibility="visible";
score.style.visibility="hidden";
}
Menu.prototype.trwin = function(){
mainMenu.style.visibility="hidden";
waiting.style.visibility="hidden";
game.style.visibility="hidden";
trwin.style.visibility="visible";
pikachuwin.style.visibility="hidden";
}
Menu.prototype.pikachuwin = function(){
mainMenu.style.visibility="hidden";
waiting.style.visibility="hidden";
game.style.visibility="hidden";
pikachuwin.style.visibility="visible";
trwin.style.visibility="hidden";
}
Menu.prototype.back = function(){
location.reload();
}
var menu = new Menu();
/**
* Sound manager setup.
*/
//Data structure for sound Assets.
var soundAssets = {};
//Load sounds
soundManager.setup({
url: '/lib/',
flashVersion: 8, // optional: shiny features (default = 8)
useFlashBlock: true, // optionally, enable when you're ready to dive in
// * read up on HTML5 audio support, if you're feeling adventurous.
// * iPad/iPhone and devices without flash installed will always attempt to use it.
//
onready: function() {
soundAssets.background = soundManager.createSound({
id: 'background',
url: './sounds/background.mp3',
onfinish: function(){soundAssets.background.play();},
volume: 30
});
soundAssets.background.play();
soundAssets.pika = soundManager.createSound({
id: 'pika',
url: './sounds/pikachu.mp3',
volume: 30
});
},
ontimeout: function() {
alert("soundManager failed to load");
}
});
var blurred = false;
var onBlur = function() {
if(!blurred){
soundManager.mute();
blurred = true;
}
};
var onFocus = function() {
if(blurred){
soundManager.unmute();
blurred = false;
}
};
window.onfocus = onFocus;
window.onblur = onBlur;