-
Notifications
You must be signed in to change notification settings - Fork 44
/
index.html
112 lines (95 loc) · 3.21 KB
/
index.html
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
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesmenu.css">
<script type="text/javascript" src="lib/keyboard.js"></script>
<script>
KeyboardJS.on("esc", function(event, keys, combo){
//Open console
}, function(event, keys, combo){});
function openNewGameMenu() {
var menu = document.getElementById("newGameMenu");
var menuHeight = screen.height / 2;
var menuWidth = screen.width / 4.2;
menu.style.height = menuHeight + "px";
menu.style.width = menuWidth + "px";
menu.style.marginTop = "-" + (menuHeight/2).toString() + "px";
menu.style.marginLeft = "-" + (menuWidth/2).toString() + "px";
menu.style.visibility = "visible";
}
function closeGameMenu() {
var menu = document.getElementById("newGameMenu");
console.log(menu);
menu.style.visibility = "hidden";
}
function webGLStart() {
var canvas = document.getElementById("canvas");
initGL(canvas);
download(cs.config.MAP_PATH, function(data) {
//Parse map
cs.map = new cs.Map(gl, data);
download(cs.config.PLAYER_PATH, function(data) {
//Hardcoded cs_assault position. TODO: Read this from the entity set
cs.player = new cs.Player(gl, -186, 2597, 165, data);
gl.clearColor(0.0, 0.0, 0.0, 1.0);
//Set event handler for resizing the screen every time
//the window changes size
var resizeCallback = function() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
gl.viewportWidth = window.innerWidth;
gl.viewportHeight = window.innerHeight;
};
resizeCallback();
window.addEventListener("resize", resizeCallback, false);
//Listen for clicks on the canvas
canvas.addEventListener("click", function() {
//is the mouse not currently locked?
if(!PointerLock.pointerLockElement()) {
//Nope. Request locking
PointerLock.requestPointerLock(canvas);
}
}, false);
//Listen for pointer locking
PointerLock.addPointerLockExchangeEventListener(document, function(e) {
//Did the pointer just go from unlocked to locked?
if(!!PointerLock.pointerLockElement()) {
//Yep! Add mousemove listener
PointerLock.addMouseMoveEventListener(document, rotatePlayer, false);
}
else { //Nope. Remove mouse move listener
PointerLock.removeMouseMoveEventListener(document, rotatePlayer);
}
}, false);
mainLoop();
});
});
}
function startGame() {
var e = document.getElementById("map");
var map = e.options[e.selectedIndex].value;
window.location = "game.html#" + map;
}
</script>
</head>
<body>
<table id="menu">
<tr>
<td><a href="#" onClick="openNewGameMenu()">New Game</a></td>
</tr>
<tr>
<td><a href="#">Find Servers</a></td>
</tr>
</table>
<div id="newGameMenu" style="visibility:hidden;">
Map
<select id="map">
<option value="">< Random Map ></option>
<option value="cs_assault.bsp">cs_assault</option>
<option value="cs_italy.bsp">cs_italy</option>
</select>
<hr />
<button id="menuStartButton" onclick="startGame()">Start</button>
<button id="menuCancelButton" onclick="closeGameMenu()">Cancel</button>
</div>
</body>
</html>