-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
451 lines (407 loc) · 15.6 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CS Student Job Quest</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="An interactive game about a CS student's journey to find a job">
<!-- Phaser & nipple.js -->
<script type="module" src="https://cdn.jsdelivr.net/npm/[email protected]/dist/phaser.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/nipplejs.min.js"></script>
<style>
/* Base styles */
body,
html {
margin: 0;
padding: 0;
height: 100%;
font-family: 'Orbitron', sans-serif;
background-color: #1a1a2e;
color: #ffffff;
}
.screen {
display: none;
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}
.screen.active {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#game-screen.active {
display: block;
background: none;
}
.container {
text-align: center;
max-width: 800px;
width: 90%;
}
#game-container {
width: 100%;
height: 100%;
max-width: 800px; /* For desktop */
margin: 0 auto;
}
/* Header controls (Menu, Restart, etc.) */
.game-controls {
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: rgba(26, 26, 46, 0.8);
padding: 10px 0;
z-index: 101;
display: none;
text-align: center;
}
.hud {
position: fixed;
top: 50px;
left: 0;
width: 100%;
background-color: rgba(255, 255, 255, 0.9);
color: #1a1a2e;
padding: 10px;
z-index: 100;
display: none;
font-family: 'Orbitron', sans-serif;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}
.btn {
background: linear-gradient(135deg, #283c86 0%, #45a247 100%);
border: 2px solid #fff;
border-radius: 8px;
color: #fff;
font-family: inherit;
font-size: 18px;
text-transform: uppercase;
text-align: center;
padding: 12px 30px;
margin: 10px;
cursor: pointer;
transition: transform 0.3s ease;
}
.btn:hover {
transform: translateY(-2px);
}
.game-title {
font-size: 2.5em;
margin-bottom: 30px;
text-transform: uppercase;
color: #e94560;
}
/* Mobile control styles (joystick/buttons) */
#joystick-zone {
position: fixed;
bottom: 20px;
left: 20px;
width: 120px;
height: 120px;
display: none;
z-index: 1000;
touch-action: none;
}
.action-buttons {
position: fixed;
bottom: 20px;
right: 20px;
display: none;
gap: 10px;
z-index: 1000;
}
.action-button {
width: 60px;
height: 60px;
background: rgba(69, 162, 71, 0.7);
border: 2px solid rgba(255, 255, 255, 0.4);
border-radius: 50%;
color: white;
font-size: 24px;
display: flex;
align-items: center;
justify-content: center;
touch-action: none;
}
/* Force the game and container to fill screen on mobile */
@media (max-width: 768px) {
#joystick-zone,
.action-buttons {
display: block;
}
#game-screen {
width: 100vw;
height: 100vh;
position: relative;
overflow: hidden;
}
#game-container {
max-width: none;
width: 100%;
height: 100%;
margin: 0;
}
}
</style>
</head>
<body>
<!-- Game Controls (fixed header) -->
<nav class="game-controls" id="game-controls">
<button class="btn" id="game-menu-button">Menu</button>
<button class="btn" id="game-restart-button">Restart</button>
<button class="btn" id="game-instructions-button">Instructions</button>
</nav>
<!-- HUD -->
<div class="hud" id="hud" aria-live="polite"></div>
<!-- Start Menu Screen -->
<div id="start-menu-screen" class="screen active">
<div class="container">
<h1 class="game-title">CS Student Job Quest</h1>
<button class="btn" id="play-button">Play</button>
<button class="btn" id="settings-button">Settings</button>
<button class="btn" id="instructions-button">Instructions</button>
</div>
</div>
<!-- Main Game Screen -->
<div id="game-screen" class="screen">
<div id="game-container"></div>
</div>
<!-- Settings Screen -->
<div id="settings-screen" class="screen">
<div class="container">
<h2>Settings</h2>
<button class="btn" id="settings-back-button">Back</button>
</div>
</div>
<!-- Instructions Screen -->
<div id="instructions-screen" class="screen">
<div class="container">
<h2>Instructions</h2>
<h3>How to Play:</h3>
<ul>
<li>Use arrow keys or joystick to move</li>
<li>Space or action button to interact</li>
<li>Collect skills and experience points</li>
</ul>
<button class="btn" id="instructions-back-button">Back</button>
</div>
</div>
<!-- Game Over Screen -->
<div id="game-over-screen" class="screen">
<div class="container">
<div id="game-over-message"></div>
<button class="btn" id="play-again-button">Play Again</button>
<button class="btn" id="main-menu-button">Main Menu</button>
</div>
</div>
<!-- Mobile Controls -->
<div id="joystick-zone"></div>
<div class="action-buttons">
<button class="action-button" id="jump-button">↑</button>
<button class="action-button" id="action-button">A</button>
</div>
<!-- Import Phaser game logic after DOM has loaded -->
<script type="module" src="js/game.js"></script>
<!-- UI & Joystick Setup -->
<script>
document.addEventListener('DOMContentLoaded', () => {
// UI Manager
class GameUI {
constructor() {
this.startMenuScreen = document.getElementById('start-menu-screen');
this.settingsScreen = document.getElementById('settings-screen');
this.instructionsScreen = document.getElementById('instructions-screen');
this.gameScreen = document.getElementById('game-screen');
this.gameOverScreen = document.getElementById('game-over-screen');
this.gameControls = document.getElementById('game-controls');
this.hud = document.getElementById('hud');
}
swapToScreen(screen) {
// Hide all
this.startMenuScreen.classList.remove('active');
this.settingsScreen.classList.remove('active');
this.instructionsScreen.classList.remove('active');
this.gameScreen.classList.remove('active');
this.gameOverScreen.classList.remove('active');
// Show target
if (screen.id !== 'game-screen') {
screen.classList.add('active');
this.gameControls.style.display = 'none';
this.hud.style.display = 'none';
} else {
screen.classList.add('active');
this.gameControls.style.display = 'block';
this.hud.style.display = 'block';
}
}
startGame() {
this.swapToScreen(this.gameScreen);
}
mainMenu() {
this.swapToScreen(this.startMenuScreen);
}
settings() {
this.swapToScreen(this.settingsScreen);
}
instructions() {
this.swapToScreen(this.instructionsScreen);
}
}
const gameUI = new GameUI();
// Main Menu Buttons
document.getElementById('play-button').addEventListener('click', () => gameUI.startGame());
document.getElementById('settings-button').addEventListener('click', () => gameUI.settings());
document.getElementById('instructions-button').addEventListener('click', () => gameUI.instructions());
// Settings / Instructions Back Buttons
document.getElementById('settings-back-button').addEventListener('click', () => gameUI.mainMenu());
document.getElementById('instructions-back-button').addEventListener('click', () => gameUI.mainMenu());
// In-Game Menu Buttons
document.getElementById('game-menu-button').addEventListener('click', () => gameUI.mainMenu());
document.getElementById('game-restart-button').addEventListener('click', () => gameUI.startGame());
document.getElementById('game-instructions-button').addEventListener('click', () => gameUI.instructions());
// Game Over Buttons
document.getElementById('play-again-button').addEventListener('click', () => gameUI.startGame());
document.getElementById('main-menu-button').addEventListener('click', () => gameUI.mainMenu());
// Joystick Initialization
let joystick = nipplejs.create({
zone: document.getElementById('joystick-zone'),
mode: 'semi',
position: { left: '50%', top: '50%' },
color: 'white',
size: 100
});
// Track which directions are currently active
let moveLeft = false;
let moveRight = false;
// Listen for "move" events
joystick.on('move', (evt, data) => {
// If there's no direction or only a vertical direction, release horizontal movement
if (!data.direction || !data.direction.x) {
if (moveLeft) {
window.dispatchEvent(new KeyboardEvent('keyup', {
key: 'ArrowLeft',
code: 'ArrowLeft',
keyCode: 37
}));
moveLeft = false;
}
if (moveRight) {
window.dispatchEvent(new KeyboardEvent('keyup', {
key: 'ArrowRight',
code: 'ArrowRight',
keyCode: 39
}));
moveRight = false;
}
return;
}
// If direction.x === 'left'
if (data.direction.x === 'left') {
// If we were moving right, release it first
if (moveRight) {
window.dispatchEvent(new KeyboardEvent('keyup', {
key: 'ArrowRight',
code: 'ArrowRight',
keyCode: 39
}));
moveRight = false;
}
// Then press left if not already moving left
if (!moveLeft) {
moveLeft = true;
window.dispatchEvent(new KeyboardEvent('keydown', {
key: 'ArrowLeft',
code: 'ArrowLeft',
keyCode: 37
}));
}
}
// If direction.x === 'right'
else if (data.direction.x === 'right') {
// If we were moving left, release it first
if (moveLeft) {
window.dispatchEvent(new KeyboardEvent('keyup', {
key: 'ArrowLeft',
code: 'ArrowLeft',
keyCode: 37
}));
moveLeft = false;
}
// Then press right if not already
if (!moveRight) {
moveRight = true;
window.dispatchEvent(new KeyboardEvent('keydown', {
key: 'ArrowRight',
code: 'ArrowRight',
keyCode: 39
}));
}
}
});
// When the joystick is completely released
joystick.on('end', () => {
// Release left if it's active
if (moveLeft) {
window.dispatchEvent(new KeyboardEvent('keyup', {
key: 'ArrowLeft',
code: 'ArrowLeft',
keyCode: 37
}));
moveLeft = false;
}
// Release right if it's active
if (moveRight) {
window.dispatchEvent(new KeyboardEvent('keyup', {
key: 'ArrowRight',
code: 'ArrowRight',
keyCode: 39
}));
moveRight = false;
}
});
// Jump Button
const jumpButton = document.getElementById('jump-button');
jumpButton.addEventListener('touchstart', (e) => {
e.preventDefault();
window.dispatchEvent(new KeyboardEvent('keydown', {
key: 'ArrowUp',
code: 'ArrowUp',
keyCode: 38
}));
});
jumpButton.addEventListener('touchend', (e) => {
e.preventDefault();
window.dispatchEvent(new KeyboardEvent('keyup', {
key: 'ArrowUp',
code: 'ArrowUp',
keyCode: 38
}));
});
// Action Button (Space)
const actionButton = document.getElementById('action-button');
actionButton.addEventListener('touchstart', (e) => {
e.preventDefault();
window.dispatchEvent(new KeyboardEvent('keydown', {
key: ' ',
code: 'Space',
keyCode: 32
}));
});
actionButton.addEventListener('touchend', (e) => {
e.preventDefault();
window.dispatchEvent(new KeyboardEvent('keyup', {
key: ' ',
code: 'Space',
keyCode: 32
}));
});
});
</script>
</body>
</html>