-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.js
111 lines (107 loc) · 3.94 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
var Menu = {
showMenu: function(whichMenu) {
var overlayEle = Menu.createOverlay();
if("new" == whichMenu)
{
var newGameButton = Menu.createButton(overlayEle, (window.innerHeight - 100) / 2, "New Game", Menu.newGameClicked);
newGameButton.focus();
var hints = [
"Now with mouse support",
"Now with homogenous Enemy Waves",
"Now playable on mobile",
"Now with energy shield"
];
var hintText = Menu.createHintText(overlayEle, (window.innerHeight - 200) / 2, hints[Math.floor(Math.random() * hints.length)]);
} else if("end" == whichMenu)
{
var gameOverText = Menu.createText(overlayEle, (window.innerHeight) / 2 - 200, "Game Over");
gameOverText.style.color = "#ffffff";
gameOverText.style.fontFamily = "Open Sans, Sans, Georgia";
gameOverText.style.fontSize = "64pt";
gameOverText.style.fontWeight = "bold";
gameOverText.style.letterSpacing = "3px";
gameOverText.style.wordSpacing = "5px";
gameOverText.style.textShadow = "#d0d0d0 0px 2px 5px";
Menu.createButton(overlayEle, 100, "Reload", Menu.reloadClicked);
}
},
createOverlay: function ()
{
var BODY = document.getElementsByTagName("body")[0];
var overlays = [ undefined, undefined ];
for (var i = 0; i < 2; i++)
{
overlays[i] = document.createElement("div");
overlays[i].setAttribute("class", "overlay");
overlays[i].style.zIndex = "99" + i;
overlays[i].style.width = window.innerWidth + "px";
overlays[i].style.height = window.innerHeight + "px";
overlays[i].style.position= "absolute";
overlays[i].style.left = "0px";
overlays[i].style.top = "0px";
if(0 == i)
{
overlays[i].style.backgroundColor = "#606060";
overlays[i].style.opacity = "0.5";
} else if (1 == i)
{
overlays[i].style.textAlign = "center";
}
BODY.appendChild(overlays[i]);
}
return overlays[1];
},
createButton: function (parentNode, marginTop, buttonText, buttonCallback)
{
var buttonEle = document.createElement("button");
buttonEle.setAttribute("class", "menu_button");
buttonEle.style.zIndex = "992";
buttonEle.style.margin = marginTop + "px auto 0px auto";
parentNode.appendChild(buttonEle);
buttonEle.appendChild(document.createTextNode(buttonText));
buttonEle.addEventListener("click", buttonCallback);
return buttonEle;
},
createText: function(parentNode, marginTop, text)
{
var textEle = document.createElement("div");
textEle.setAttribute("class", "menu_text");
textEle.style.zIndex = "991";
textEle.style.margin = marginTop + "px auto 0px auto";
parentNode.appendChild(textEle);
textEle.appendChild(document.createTextNode(text));
return textEle;
},
createHintText: function(parentNode, marginTop, text)
{
var textEle = document.createElement("div");
textEle.setAttribute("class", "menu_text");
textEle.style.zIndex = "991";
textEle.style.position = "absolute";
textEle.style.left = window.innerWidth / 2 + "px";
textEle.style.top = marginTop + "px";
textEle.style.transform = "rotate(10deg)";
textEle.style.fontSize = "16pt";
parentNode.appendChild(textEle);
textEle.appendChild(document.createTextNode(text));
return textEle;
},
newGameClicked: function ()
{
Menu.clearMenu();
ProgramExecuter.initGame();
},
reloadClicked: function ()
{
location.reload();
},
clearMenu: function ()
{
var BODY = document.getElementsByTagName("body")[0];
var overlays = document.querySelectorAll(".overlay");
for (var i = 0; i < overlays.length; i++)
{
BODY.removeChild(overlays[i]);
}
}
};