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
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
6
+ <title>SPACE ZOMBIES RL - Mouse Behavior Dataset Gym</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ overflow: hidden;
11
+ background: #000;
12
+ font-family: 'Courier New', monospace;
13
+ display: flex;
14
+ flex-direction: column;
15
+ align-items: center;
16
+ justify-content: center;
17
+ height: 100vh;
18
+ color: #00ff00;
19
+ image-rendering: pixelated;
20
+ touch-action: none;
21
+ }
22
+
23
+ #gameContainer {
24
+ position: relative;
25
+ width: 800px;
26
+ height: 450px;
27
+ border: 2px solid #00ff00;
28
+ box-shadow: 0 0 20px #00ff00;
29
+ max-width: 100%;
30
+ max-height: 70vh;
31
+ }
32
+
33
+ canvas {
34
+ display: block;
35
+ width: 100%;
36
+ height: 100%;
37
+ }
38
+
39
+ #ui {
40
+ position: absolute;
41
+ top: 10px;
42
+ left: 10px;
43
+ z-index: 10;
44
+ background: rgba(0, 0, 0, 0.7);
45
+ padding: 10px;
46
+ border: 1px solid #00ff00;
47
+ font-size: 14px;
48
+ }
49
+
50
+ #healthBar {
51
+ width: 200px;
52
+ height: 20px;
53
+ background: #333;
54
+ border: 1px solid #00ff00;
55
+ margin-bottom: 10px;
56
+ position: relative;
57
+ }
58
+
59
+ #healthFill {
60
+ width: 100%;
61
+ height: 100%;
62
+ background: #00ff00;
63
+ transition: width 0.3s;
64
+ }
65
+
66
+ #healthText {
67
+ position: absolute;
68
+ top: 0;
69
+ left: 0;
70
+ width: 100%;
71
+ text-align: center;
72
+ line-height: 20px;
73
+ font-weight: bold;
74
+ }
75
+
76
+ #datasetBar {
77
+ width: 200px;
78
+ height: 20px;
79
+ background: #333;
80
+ border: 1px solid #00aaff;
81
+ margin-top: 10px;
82
+ position: relative;
83
+ }
84
+
85
+ #datasetFill {
86
+ width: 0%;
87
+ height: 100%;
88
+ background: #00aaff;
89
+ transition: width 0.3s;
90
+ }
91
+
92
+ #datasetText {
93
+ position: absolute;
94
+ top: 0;
95
+ left: 0;
96
+ width: 100%;
97
+ text-align: center;
98
+ line-height: 20px;
99
+ font-weight: bold;
100
+ color: #fff;
101
+ }
102
+
103
+ #bombCooldown {
104
+ width: 200px;
105
+ height: 10px;
106
+ background: #333;
107
+ border: 1px solid #00ff00;
108
+ margin-top: 5px;
109
+ }
110
+
111
+ #bombFill {
112
+ width: 0%;
113
+ height: 100%;
114
+ background: #ff5500;
115
+ transition: width 0.1s;
116
+ }
117
+
118
+ #gameOver {
119
+ display: none;
120
+ position: absolute;
121
+ top: 50%;
122
+ left: 50%;
123
+ transform: translate(-50%, -50%);
124
+ background: rgba(0, 0, 0, 0.9);
125
+ padding: 30px;
126
+ border: 3px solid #00ff00;
127
+ text-align: center;
128
+ z-index: 20;
129
+ width: 300px;
130
+ }
131
+
132
+ #menu {
133
+ display: none;
134
+ position: absolute;
135
+ top: 50%;
136
+ left: 50%;
137
+ transform: translate(-50%, -50%);
138
+ background: rgba(0, 0, 0, 0.95);
139
+ padding: 20px;
140
+ border: 3px solid #00ff00;
141
+ z-index: 20;
142
+ width: 500px;
143
+ max-height: 80vh;
144
+ overflow-y: auto;
145
+ }
146
+
147
+ .menu-section {
148
+ margin-bottom: 20px;
149
+ border-bottom: 1px solid #00ff00;
150
+ padding-bottom: 10px;
151
+ }
152
+
153
+ .stat-row {
154
+ display: flex;
155
+ justify-content: space-between;
156
+ margin: 5px 0;
157
+ }
158
+
159
+ button {
160
+ background: #00ff00;
161
+ color: #000;
162
+ border: none;
163
+ padding: 10px 20px;
164
+ margin-top: 10px;
165
+ cursor: pointer;
166
+ font-weight: bold;
167
+ font-family: 'Courier New', monospace;
168
+ }
169
+
170
+ button:hover {
171
+ background: #22ff22;
172
+ }
173
+
174
+ button:disabled {
175
+ background: #555;
176
+ cursor: not-allowed;
177
+ }
178
+
179
+ #instructions {
180
+ margin-top: 20px;
181
+ text-align: center;
182
+ max-width: 800px;
183
+ line-height: 1.5;
184
+ font-size: 14px;
185
+ color: #00aaff;
186
+ }
187
+
188
+ .crosshair {
189
+ position: absolute;
190
+ width: 20px;
191
+ height: 20px;
192
+ pointer-events: none;
193
+ z-index: 15;
194
+ transform: translate(-50%, -50%);
195
+ color: #00ff00;
196
+ font-size: 20px;
197
+ text-align: center;
198
+ line-height: 20px;
199
+ }
200
+
201
+ #movementIndicator {
202
+ position: absolute;
203
+ width: 20px;
204
+ height: 20px;
205
+ border-radius: 50%;
206
+ background: rgba(0, 255, 255, 0.5);
207
+ border: 2px solid #00ffff;
208
+ pointer-events: none;
209
+ z-index: 5;
210
+ display: none;
211
+ transform: translate(-50%, -50%);
212
+ }
213
+
214
+ #exportPanel {
215
+ display: none;
216
+ position: absolute;
217
+ top: 50%;
218
+ left: 50%;
219
+ transform: translate(-50%, -50%);
220
+ background: rgba(0, 0, 0, 0.95);
221
+ padding: 30px;
222
+ border: 3px solid #00aaff;
223
+ z-index: 25;
224
+ width: 400px;
225
+ text-align: center;
226
+ }
227
+
228
+ .data-point {
229
+ position: absolute;
230
+ width: 8px;
231
+ height: 8px;
232
+ border-radius: 50%;
233
+ z-index: 3;
234
+ pointer-events: none;
235
+ }
236
+
237
+ .lmb-point {
238
+ background: rgba(255, 0, 0, 0.7);
239
+ box-shadow: 0 0 8px rgba(255, 0, 0, 0.9);
240
+ }
241
+
242
+ .rmb-point {
243
+ background: rgba(255, 165, 0, 0.7);
244
+ box-shadow: 0 0 8px rgba(255, 165, 0, 0.9);
245
+ }
246
+
247
+ .move-point {
248
+ background: rgba(0, 255, 255, 0.5);
249
+ box-shadow: 0 0 5px rgba(0, 255, 255, 0.7);
250
+ }
251
+
252
+ #dataStats {
253
+ position: absolute;
254
+ top: 10px;
255
+ right: 10px;
256
+ z-index: 10;
257
+ background: rgba(0, 0, 0, 0.7);
258
+ padding: 10px;
259
+ border: 1px solid #00aaff;
260
+ font-size: 12px;
261
+ max-width: 200px;
262
+ }
263
+
264
+ #waveAlert {
265
+ position: absolute;
266
+ top: 50%;
267
+ left: 50%;
268
+ transform: translate(-50%, -50%);
269
+ font-size: 24px;
270
+ font-weight: bold;
271
+ text-shadow: 0 0 10px #00ff00;
272
+ z-index: 15;
273
+ display: none;
274
+ }
275
+
276
+ #completionMessage {
277
+ display: none;
278
+ position: absolute;
279
+ top: 50%;
280
+ left: 50%;
281
+ transform: translate(-50%, -50%);
282
+ background: rgba(0, 0, 0, 0.9);
283
+ padding: 30px;
284
+ border: 3px solid #00ff00;
285
+ text-align: center;
286
+ z-index: 20;
287
+ width: 400px;
288
+ }
289
+
290
+ @media (max-width: 768px) {
291
+ #gameContainer {
292
+ width: 100%;
293
+ height: 60vh;
294
+ }
295
+
296
+ #ui {
297
+ font-size: 12px;
298
+ padding: 5px;
299
+ }
300
+
301
+ #healthBar, #datasetBar, #bombCooldown {
302
+ width: 150px;
303
+ }
304
+
305
+ #dataStats {
306
+ font-size: 10px;
307
+ padding: 5px;
308
+ max-width: 150px;
309
+ }
310
+ }
311
+ </style>
312
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
313
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
314
+ </head>
315
+ <body>
316
+ <h1>SPACE ZOMBIES RL GYM by webXOS 2026</h1>
317
+ <div id="gameContainer">
318
+ <div id="ui">
319
+ <div class="stat-row">
320
+ <div>Wave: <span id="waveNumber">1</span>/10</div>
321
+ <div>Dataset Level: <span id="datasetLevel">1</span></div>
322
+ </div>
323
+ <div class="stat-row">
324
+ <div>Zombies: <span id="zombieCountValue">0</span></div>
325
+ <div>Data Points: <span id="dataPoints">0</span>/<span id="dataNeeded">100</span></div>
326
+ </div>
327
+ <div>HEALTH</div>
328
+ <div id="healthBar">
329
+ <div id="healthFill"></div>
330
+ <div id="healthText">100%</div>
331
+ </div>
332
+ <div class="stat-row">
333
+ <div>Bomb Ready</div>
334
+ <div id="bombTimer">10s</div>
335
+ </div>
336
+ <div id="bombCooldown">
337
+ <div id="bombFill"></div>
338
+ </div>
339
+ <div>DATASET PROGRESS</div>
340
+ <div id="datasetBar">
341
+ <div id="datasetFill"></div>
342
+ <div id="datasetText">0%</div>
343
+ </div>
344
+ </div>
345
+
346
+ <div id="dataStats">
347
+ <div>Mouse Data Collection</div>
348
+ <div>LMB Clicks: <span id="lmbCount">0</span></div>
349
+ <div>RMB Clicks: <span id="rmbCount">0</span></div>
350
+ <div>Movement: <span id="moveCount">0</span></div>
351
+ <div>Session Time: <span id="sessionTime">0</span>s</div>
352
+ </div>
353
+
354
+ <div id="waveAlert">Wave <span id="waveAlertNumber">1</span></div>
355
+
356
+ <div id="gameOver">
357
+ <h2>MISSION TERMINATED</h2>
358
+ <p>You survived <span id="finalWave">0</span> waves</p>
359
+ <p>Dataset Level: <span id="finalDatasetLevel">1</span></p>
360
+ <p>Total Data Points: <span id="finalDataPoints">0</span></p>
361
+ <button id="exportButton">EXPORT DATASET</button>
362
+ <button id="restartButton">NEW SESSION</button>
363
+ </div>
364
+
365
+ <div id="completionMessage">
366
+ <h2>DATASET COMPLETE!</h2>
367
+ <p>You cleared all 10 waves and collected valuable RL data!</p>
368
+ <p>Final Dataset Level: <span id="completionDatasetLevel">1</span></p>
369
+ <p>Total Samples: <span id="completionSamples">0</span></p>
370
+ <button id="completionExport">EXPORT TO HUGGING FACE</button>
371
+ <button id="completionRestart">NEW COLLECTION</button>
372
+ </div>
373
+
374
+ <div id="menu">
375
+ <h2>RL DATASET COLLECTOR</h2>
376
+ <div class="menu-section">
377
+ <h3>DATASET STATS</h3>
378
+ <div class="stat-row">
379
+ <div>Dataset Level:</div>
380
+ <div id="menuDatasetLevel">1</div>
381
+ </div>
382
+ <div class="stat-row">
383
+ <div>Data Points:</div>
384
+ <div id="menuDataPoints">0/100</div>
385
+ </div>
386
+ <div class="stat-row">
387
+ <div>Mouse Clicks (LMB):</div>
388
+ <div id="menuLMB">0</div>
389
+ </div>
390
+ <div class="stat-row">
391
+ <div>Bomb Clicks (RMB):</div>
392
+ <div id="menuRMB">0</div>
393
+ </div>
394
+ <div class="stat-row">
395
+ <div>Movement Samples:</div>
396
+ <div id="menuMovement">0</div>
397
+ </div>
398
+ <div class="stat-row">
399
+ <div>Session Duration:</div>
400
+ <div id="menuSessionTime">0s</div>
401
+ </div>
402
+ </div>
403
+
404
+ <div class="menu-section">
405
+ <h3>RL RESEARCH PARAMETERS</h3>
406
+ <div class="stat-row">
407
+ <div>Sampling Rate:</div>
408
+ <div>50ms</div>
409
+ </div>
410
+ <div class="stat-row">
411
+ <div>Features Collected:</div>
412
+ <div>18</div>
413
+ </div>
414
+ <div class="stat-row">
415
+ <div>Export Format:</div>
416
+ <div>JSON + CSV</div>
417
+ </div>
418
+ <div class="stat-row">
419
+ <div>HF Compatible:</div>
420
+ <div style="color: #00ff00">✓</div>
421
+ </div>
422
+ </div>
423
+
424
+ <button id="resumeButton">RESUME COLLECTION</button>
425
+ <button id="manualExport" style="background: #00aaff; margin-left: 10px;">EXPORT NOW</button>
426
+ </div>
427
+
428
+ <div id="exportPanel">
429
+ <h2>DATASET EXPORT</h2>
430
+ <p>Your mouse behavior data is ready for Hugging Face!</p>
431
+ <div id="exportStats" style="text-align: left; margin: 15px 0; padding: 10px; background: rgba(0,0,0,0.5);">
432
+ <!-- Filled by JavaScript -->
433
+ </div>
434
+ <p>Files included in export:</p>
435
+ <ul style="text-align: left; font-size: 14px;">
436
+ <li>mouse_behavior.json (raw data)</li>
437
+ <li>rl_transitions.csv (state-action pairs)</li>
438
+ <li>metadata.yaml (HF dataset card)</li>
439
+ <li>README.md (usage instructions)</li>
440
+ </ul>
441
+ <button id="downloadButton">DOWNLOAD ZIP</button>
442
+ <button id="closeExport" style="background: #555; margin-left: 10px;">CLOSE</button>
443
+ </div>
444
+
445
+ <div class="crosshair">+</div>
446
+ <div id="movementIndicator"></div>
447
+ <canvas id="gameCanvas"></canvas>
448
+ </div>
449
+ <div id="instructions">
450
+ <p><strong>RL RESEARCH MODE:</strong> CLICK to move | AUTO-AIM at nearest zombie | RIGHT CLICK or BOMB button (10s cooldown) | ESC for menu</p>
451
+ <p>Every mouse action collects data for RL training. Survive waves to level up your dataset. Export to Hugging Face for research!</p>
452
+ </div>
453
+
454
+ <script>
455
+ // Game variables
456
+ let scene, camera, renderer;
457
+ let player, playerModel, zombies = [];
458
+ let walls = [];
459
+ let doors = [];
460
+ let projectiles = [];
461
+ let explosions = [];
462
+ let itemDrops = [];
463
+ let playerHealth = 100;
464
+ let playerMaxHealth = 100;
465
+ let datasetLevel = 1;
466
+ let datasetPoints = 0;
467
+ let pointsToNextLevel = 100;
468
+ let playerSpeed = 0.1;
469
+ let playerDamage = 10;
470
+ let currentWave = 1;
471
+ let maxWaves = 10;
472
+ let zombiesInWave = 0;
473
+ let zombiesRemaining = 0;
474
+ let zombiesKilled = 0;
475
+ let gameOver = false;
476
+ let gameCompleted = false;
477
+ let lastSpawnTime = 0;
478
+ let lastWaveTime = 0;
479
+ let lastShotTime = 0;
480
+ let bombCooldown = 0;
481
+ let bombMaxCooldown = 10;
482
+ let mouse = { x: 0, y: 0, leftDown: false, rightDown: false };
483
+ let playerTarget = { x: 0, y: 0, z: 0 };
484
+ let isMenuOpen = false;
485
+ let raycaster = new THREE.Raycaster();
486
+
487
+ // RL Dataset variables
488
+ let mouseDataset = [];
489
+ let sessionStartTime = Date.now();
490
+ let lmbCount = 0;
491
+ let rmbCount = 0;
492
+ let movementSamples = 0;
493
+ let lastMouseMoveTime = 0;
494
+ let lastMousePosition = { x: 0, y: 0 };
495
+ let mouseMoveThreshold = 5;
496
+ let samplingInterval = 50;
497
+
498
+ // Movement system - FIXED to match original
499
+ let moveToTarget = null;
500
+ let isMoving = false;
501
+
502
+ // Shooting system - AUTO SHOOT like original
503
+ let autoShoot = true;
504
+
505
+ // Initialize the game
506
+ function init() {
507
+ // Create scene
508
+ scene = new THREE.Scene();
509
+ scene.background = new THREE.Color(0x000011);
510
+
511
+ // Create starfield background
512
+ createStarfield();
513
+
514
+ // Create camera (orthographic for isometric view)
515
+ const frustumSize = 50;
516
+ const aspect = 800 / 450;
517
+ camera = new THREE.OrthographicCamera(
518
+ frustumSize * aspect / -2,
519
+ frustumSize * aspect / 2,
520
+ frustumSize / 2,
521
+ frustumSize / -2,
522
+ 0.1,
523
+ 1000
524
+ );
525
+ camera.position.set(35, 35, 35);
526
+ camera.lookAt(0, 0, 0);
527
+
528
+ // Create renderer
529
+ renderer = new THREE.WebGLRenderer({
530
+ canvas: document.getElementById('gameCanvas'),
531
+ antialias: false
532
+ });
533
+ renderer.setSize(800, 450);
534
+ renderer.setPixelRatio(1);
535
+
536
+ // Lighting
537
+ const ambientLight = new THREE.AmbientLight(0x404040, 1);
538
+ scene.add(ambientLight);
539
+
540
+ const pointLight = new THREE.PointLight(0xffffff, 1, 50);
541
+ pointLight.position.set(0, 0, 10);
542
+ scene.add(pointLight);
543
+
544
+ // Create environment
545
+ createEnvironment();
546
+
547
+ // Create player
548
+ createPlayer();
549
+
550
+ // Start game loop
551
+ animate();
552
+
553
+ // Event listeners - FIXED to match original controls
554
+ window.addEventListener('keydown', (e) => {
555
+ if (e.code === 'Escape') {
556
+ toggleMenu();
557
+ e.preventDefault();
558
+ }
559
+ });
560
+
561
+ document.getElementById('restartButton').addEventListener('click', restartGame);
562
+ document.getElementById('completionRestart').addEventListener('click', restartGame);
563
+ document.getElementById('completionExport').addEventListener('click', showExportPanel);
564
+ document.getElementById('exportButton').addEventListener('click', showExportPanel);
565
+ document.getElementById('resumeButton').addEventListener('click', toggleMenu);
566
+ document.getElementById('manualExport').addEventListener('click', showExportPanel);
567
+ document.getElementById('closeExport').addEventListener('click', () => {
568
+ document.getElementById('exportPanel').style.display = 'none';
569
+ });
570
+ document.getElementById('downloadButton').addEventListener('click', exportDataset);
571
+
572
+ const gameContainer = document.getElementById('gameContainer');
573
+
574
+ // Mouse move tracking - UPDATED to work like original
575
+ gameContainer.addEventListener('mousemove', (e) => {
576
+ if (isMenuOpen || gameOver || gameCompleted) return;
577
+
578
+ const rect = gameContainer.getBoundingClientRect();
579
+ const x = e.clientX - rect.left;
580
+ const y = e.clientY - rect.top;
581
+
582
+ mouse.x = (x / rect.width) * 2 - 1;
583
+ mouse.y = -(y / rect.height) * 2 + 1;
584
+
585
+ // Update crosshair position
586
+ const crosshair = document.querySelector('.crosshair');
587
+ crosshair.style.left = x + 'px';
588
+ crosshair.style.top = y + 'px';
589
+
590
+ // Record mouse movement for RL dataset
591
+ recordMouseMovement(x, y, rect.width, rect.height);
592
+ });
593
+
594
+ // Click to move - FIXED: Like original, click moves player
595
+ gameContainer.addEventListener('mousedown', (e) => {
596
+ if (isMenuOpen || gameOver || gameCompleted) return;
597
+
598
+ const rect = gameContainer.getBoundingClientRect();
599
+ const clientX = e.clientX;
600
+ const clientY = e.clientY;
601
+
602
+ // Right click for bomb (like original)
603
+ if (e.button === 2) {
604
+ e.preventDefault();
605
+ useBomb();
606
+ recordMouseAction('rmb', clientX - rect.left, clientY - rect.top);
607
+ return;
608
+ }
609
+
610
+ // Left click for movement ONLY (like original)
611
+ if (e.button === 0) {
612
+ // Record movement click
613
+ recordMouseAction('move_click', clientX - rect.left, clientY - rect.top);
614
+
615
+ // Handle movement (exactly like original)
616
+ handleMoveInput(e);
617
+ }
618
+ });
619
+
620
+ // Prevent context menu - FIXED: Right click for bomb
621
+ gameContainer.addEventListener('contextmenu', (e) => {
622
+ e.preventDefault();
623
+ if (!isMenuOpen && !gameOver && !gameCompleted) {
624
+ useBomb();
625
+ const rect = gameContainer.getBoundingClientRect();
626
+ recordMouseAction('rmb', e.clientX - rect.left, e.clientY - rect.top);
627
+ }
628
+ });
629
+
630
+ // Update session timer every second
631
+ setInterval(updateSessionTimer, 1000);
632
+
633
+ // Start first wave
634
+ startWave();
635
+ }
636
+
637
+ // Record mouse movement for RL dataset
638
+ function recordMouseMovement(x, y, containerWidth, containerHeight) {
639
+ const now = Date.now();
640
+ const gameRect = document.getElementById('gameContainer').getBoundingClientRect();
641
+
642
+ // Only record if enough time has passed
643
+ if (now - lastMouseMoveTime > samplingInterval) {
644
+ // Calculate normalized position (0-1)
645
+ const normalizedX = x / containerWidth;
646
+ const normalizedY = y / containerHeight;
647
+
648
+ // Calculate velocity
649
+ let velocityX = 0, velocityY = 0;
650
+ if (lastMousePosition.x !== 0 || lastMousePosition.y !== 0) {
651
+ velocityX = (x - lastMousePosition.x) / ((now - lastMouseMoveTime) || 1);
652
+ velocityY = (y - lastMousePosition.y) / ((now - lastMouseMoveTime) || 1);
653
+ }
654
+
655
+ // Create data point
656
+ const dataPoint = {
657
+ timestamp: now,
658
+ type: 'move',
659
+ position: { x: normalizedX, y: normalizedY },
660
+ velocity: { x: velocityX, y: velocityY },
661
+ gameState: {
662
+ playerHealth: playerHealth,
663
+ playerPosition: { x: player.position.x, z: player.position.z },
664
+ zombiesCount: zombies.length,
665
+ wave: currentWave,
666
+ datasetLevel: datasetLevel
667
+ },
668
+ action: 'mouse_move'
669
+ };
670
+
671
+ mouseDataset.push(dataPoint);
672
+ movementSamples++;
673
+
674
+ // Add visual indicator (faint)
675
+ const point = document.createElement('div');
676
+ point.className = 'data-point move-point';
677
+ point.style.left = (x + gameRect.left) + 'px';
678
+ point.style.top = (y + gameRect.top) + 'px';
679
+ document.body.appendChild(point);
680
+
681
+ // Remove after animation
682
+ setTimeout(() => {
683
+ if (point.parentNode) {
684
+ point.parentNode.removeChild(point);
685
+ }
686
+ }, 1000);
687
+
688
+ // Add dataset points
689
+ addDatasetPoints(1);
690
+
691
+ // Update last position and time
692
+ lastMousePosition = { x: x, y: y };
693
+ lastMouseMoveTime = now;
694
+
695
+ // Update UI
696
+ document.getElementById('moveCount').textContent = movementSamples;
697
+ }
698
+ }
699
+
700
+ // Record mouse action
701
+ function recordMouseAction(type, x, y) {
702
+ const now = Date.now();
703
+ const gameRect = document.getElementById('gameContainer').getBoundingClientRect();
704
+ const containerWidth = gameRect.width;
705
+ const containerHeight = gameRect.height;
706
+
707
+ // Calculate normalized position
708
+ const normalizedX = x / containerWidth;
709
+ const normalizedY = y / containerHeight;
710
+
711
+ // Create data point
712
+ const dataPoint = {
713
+ timestamp: now,
714
+ type: type,
715
+ position: { x: normalizedX, y: normalizedY },
716
+ gameState: {
717
+ playerHealth: playerHealth,
718
+ playerPosition: { x: player.position.x, z: player.position.z },
719
+ zombiesCount: zombies.length,
720
+ wave: currentWave,
721
+ datasetLevel: datasetLevel
722
+ },
723
+ action: type === 'rmb' ? 'bomb' : 'move'
724
+ };
725
+
726
+ mouseDataset.push(dataPoint);
727
+
728
+ // Update counts
729
+ if (type === 'move_click') {
730
+ lmbCount++;
731
+ document.getElementById('lmbCount').textContent = lmbCount;
732
+ } else if (type === 'rmb') {
733
+ rmbCount++;
734
+ document.getElementById('rmbCount').textContent = rmbCount;
735
+ }
736
+
737
+ // Add visual indicator
738
+ const point = document.createElement('div');
739
+ point.className = `data-point ${type === 'move_click' ? 'lmb-point' : 'rmb-point'}`;
740
+ point.style.left = (x + gameRect.left) + 'px';
741
+ point.style.top = (y + gameRect.top) + 'px';
742
+ document.body.appendChild(point);
743
+
744
+ // Remove after animation
745
+ setTimeout(() => {
746
+ if (point.parentNode) {
747
+ point.parentNode.removeChild(point);
748
+ }
749
+ }, 1500);
750
+
751
+ // Add dataset points for actions
752
+ addDatasetPoints(type === 'move_click' ? 3 : 10);
753
+ }
754
+
755
+ // Add points to dataset and level up if needed
756
+ function addDatasetPoints(points) {
757
+ datasetPoints += points;
758
+
759
+ // Check for level up
760
+ if (datasetPoints >= pointsToNextLevel) {
761
+ datasetLevel++;
762
+ datasetPoints = datasetPoints - pointsToNextLevel;
763
+ pointsToNextLevel = Math.floor(pointsToNextLevel * 1.5);
764
+
765
+ // Level up benefits
766
+ playerMaxHealth += 10;
767
+ playerHealth = Math.min(playerMaxHealth, playerHealth + 20);
768
+ playerDamage += 2;
769
+
770
+ // Show level up notification
771
+ showNotification(`Dataset Level ${datasetLevel}!`, '#00aaff');
772
+ }
773
+
774
+ updateDatasetUI();
775
+ }
776
+
777
+ // Update dataset UI
778
+ function updateDatasetUI() {
779
+ const datasetPercent = (datasetPoints / pointsToNextLevel) * 100;
780
+ document.getElementById('datasetFill').style.width = datasetPercent + '%';
781
+ document.getElementById('datasetText').textContent = Math.floor(datasetPercent) + '%';
782
+
783
+ document.getElementById('datasetLevel').textContent = datasetLevel;
784
+ document.getElementById('dataPoints').textContent = datasetPoints;
785
+ document.getElementById('dataNeeded').textContent = pointsToNextLevel;
786
+
787
+ // Update menu if open
788
+ if (isMenuOpen) {
789
+ updateMenu();
790
+ }
791
+ }
792
+
793
+ // Show notification
794
+ function showNotification(message, color) {
795
+ const notification = document.createElement('div');
796
+ notification.textContent = message;
797
+ notification.style.position = 'absolute';
798
+ notification.style.top = '50%';
799
+ notification.style.left = '50%';
800
+ notification.style.transform = 'translate(-50%, -50%)';
801
+ notification.style.background = 'rgba(0,0,0,0.8)';
802
+ notification.style.color = color || '#00ff00';
803
+ notification.style.padding = '10px 20px';
804
+ notification.style.border = `2px solid ${color || '#00ff00'}`;
805
+ notification.style.zIndex = '100';
806
+ notification.style.fontWeight = 'bold';
807
+ notification.style.fontSize = '18px';
808
+
809
+ document.getElementById('gameContainer').appendChild(notification);
810
+
811
+ setTimeout(() => {
812
+ if (notification.parentNode) {
813
+ notification.parentNode.removeChild(notification);
814
+ }
815
+ }, 2000);
816
+ }
817
+
818
+ // Update session timer
819
+ function updateSessionTimer() {
820
+ if (gameOver || gameCompleted) return;
821
+
822
+ const sessionTime = Math.floor((Date.now() - sessionStartTime) / 1000);
823
+ document.getElementById('sessionTime').textContent = sessionTime;
824
+ }
825
+
826
+ // Create starfield background
827
+ function createStarfield() {
828
+ const starGeometry = new THREE.BufferGeometry();
829
+ const starCount = 2000;
830
+ const positions = new Float32Array(starCount * 3);
831
+
832
+ for (let i = 0; i < starCount * 3; i += 3) {
833
+ positions[i] = (Math.random() - 0.5) * 3000;
834
+ positions[i + 1] = (Math.random() - 0.5) * 3000;
835
+ positions[i + 2] = (Math.random() - 0.5) * 3000;
836
+ }
837
+
838
+ starGeometry.setAttribute('position', new THREE.BufferAttribute(positions, 3));
839
+
840
+ const starMaterial = new THREE.PointsMaterial({
841
+ color: 0xFFFFFF,
842
+ size: 2,
843
+ sizeAttenuation: false
844
+ });
845
+
846
+ const starField = new THREE.Points(starGeometry, starMaterial);
847
+ scene.add(starField);
848
+ }
849
+
850
+ // Handle move input (click or tap) - FIXED: Exactly like original
851
+ function handleMoveInput(e) {
852
+ if (isMenuOpen || gameOver || gameCompleted) return;
853
+
854
+ e.preventDefault();
855
+
856
+ const rect = e.currentTarget.getBoundingClientRect();
857
+ let clientX, clientY;
858
+
859
+ if (e.type === 'touchstart') {
860
+ clientX = e.touches[0].clientX;
861
+ clientY = e.touches[0].clientY;
862
+ } else {
863
+ clientX = e.clientX;
864
+ clientY = e.clientY;
865
+
866
+ // Right click is for bomb, handled separately
867
+ if (e.button === 2) return;
868
+ }
869
+
870
+ const x = ((clientX - rect.left) / rect.width) * 2 - 1;
871
+ const y = -((clientY - rect.top) / rect.height) * 2 + 1;
872
+
873
+ // Calculate target position in 3D space using raycaster
874
+ raycaster.setFromCamera(new THREE.Vector2(x, y), camera);
875
+ const plane = new THREE.Plane(new THREE.Vector3(0, 1, 0), 0);
876
+ const targetPoint = new THREE.Vector3();
877
+ raycaster.ray.intersectPlane(plane, targetPoint);
878
+
879
+ // Set move target
880
+ moveToTarget = {
881
+ x: Math.max(-24, Math.min(24, targetPoint.x)),
882
+ z: Math.max(-24, Math.min(24, targetPoint.z))
883
+ };
884
+
885
+ isMoving = true;
886
+
887
+ // Show movement indicator
888
+ const indicator = document.getElementById('movementIndicator');
889
+ indicator.style.display = 'block';
890
+ indicator.style.left = (clientX - rect.left) + 'px';
891
+ indicator.style.top = (clientY - rect.top) + 'px';
892
+
893
+ // Hide indicator after a moment
894
+ setTimeout(() => {
895
+ indicator.style.display = 'none';
896
+ }, 500);
897
+ }
898
+
899
+ // Create the space station environment
900
+ function createEnvironment() {
901
+ // Create central platform
902
+ const platformGeometry = new THREE.CylinderGeometry(30, 30, 0.5, 32);
903
+ const platformMaterial = new THREE.MeshPhongMaterial({
904
+ color: 0x111111,
905
+ shininess: 30,
906
+ emissive: 0x001100
907
+ });
908
+ const platform = new THREE.Mesh(platformGeometry, platformMaterial);
909
+ platform.position.y = -0.25;
910
+ scene.add(platform);
911
+
912
+ // Create perimeter walls
913
+ const wallHeight = 3;
914
+ const wallThickness = 0.5;
915
+
916
+ // Create circular wall around platform
917
+ const wallSegments = 32;
918
+ for (let i = 0; i < wallSegments; i++) {
919
+ const angle = (i / wallSegments) * Math.PI * 2;
920
+ const x = Math.cos(angle) * 29;
921
+ const z = Math.sin(angle) * 29;
922
+
923
+ const wallSegment = new THREE.Mesh(
924
+ new THREE.BoxGeometry(wallThickness, wallHeight, 5),
925
+ new THREE.MeshPhongMaterial({
926
+ color: 0x002200,
927
+ emissive: 0x00ff00,
928
+ shininess: 100
929
+ })
930
+ );
931
+
932
+ wallSegment.position.set(x, wallHeight/2, z);
933
+ wallSegment.rotation.y = -angle;
934
+ scene.add(wallSegment);
935
+ walls.push(wallSegment);
936
+ }
937
+
938
+ // Create interior structures
939
+ createInteriorStructures();
940
+
941
+ // Create doors
942
+ const doorPositions = [
943
+ { x: 0, z: 29, rotation: 0 },
944
+ { x: 29, z: 0, rotation: Math.PI/2 },
945
+ { x: 0, z: -29, rotation: Math.PI },
946
+ { x: -29, z: 0, rotation: -Math.PI/2 }
947
+ ];
948
+
949
+ doorPositions.forEach(pos => {
950
+ const door = createDoor(pos.x, 1.5, pos.z, pos.rotation);
951
+ scene.add(door);
952
+ doors.push(door);
953
+ });
954
+ }
955
+
956
+ // Create interior structures
957
+ function createInteriorStructures() {
958
+ const obstaclePositions = [
959
+ { x: 10, z: 10, rotation: 0 },
960
+ { x: -10, z: 10, rotation: Math.PI/4 },
961
+ { x: 10, z: -10, rotation: Math.PI/2 },
962
+ { x: -10, z: -10, rotation: Math.PI }
963
+ ];
964
+
965
+ obstaclePositions.forEach(pos => {
966
+ const obstacle = createCyberObstacle(pos.x, 1, pos.z, pos.rotation);
967
+ scene.add(obstacle);
968
+ walls.push(obstacle);
969
+ });
970
+ }
971
+
972
+ // Create a cyber-themed obstacle
973
+ function createCyberObstacle(x, y, z, rotation) {
974
+ const obstacleGroup = new THREE.Group();
975
+
976
+ const baseGeometry = new THREE.BoxGeometry(3, 2, 3);
977
+ const baseMaterial = new THREE.MeshPhongMaterial({
978
+ color: 0x002200,
979
+ emissive: 0x004400
980
+ });
981
+ const base = new THREE.Mesh(baseGeometry, baseMaterial);
982
+ base.position.y = 1;
983
+ obstacleGroup.add(base);
984
+
985
+ const detailGeometry = new THREE.BoxGeometry(2.8, 0.2, 0.2);
986
+ const detailMaterial = new THREE.MeshPhongMaterial({
987
+ color: 0x00ff00,
988
+ emissive: 0x00aa00
989
+ });
990
+
991
+ for (let i = 0; i < 3; i++) {
992
+ const detail = new THREE.Mesh(detailGeometry, detailMaterial);
993
+ detail.position.set(0, 0.5 + i * 0.7, 1.4);
994
+ base.add(detail);
995
+ }
996
+
997
+ const lightGeometry = new THREE.CylinderGeometry(0.5, 0.5, 0.3, 8);
998
+ const lightMaterial = new THREE.MeshPhongMaterial({
999
+ color: 0x00ff00,
1000
+ emissive: 0x00ff00
1001
+ });
1002
+ const light = new THREE.Mesh(lightGeometry, lightMaterial);
1003
+ light.position.set(0, 2.1, 0);
1004
+ obstacleGroup.add(light);
1005
+
1006
+ obstacleGroup.position.set(x, y, z);
1007
+ obstacleGroup.rotation.y = rotation;
1008
+
1009
+ return obstacleGroup;
1010
+ }
1011
+
1012
+ // Create a door
1013
+ function createDoor(x, y, z, rotation) {
1014
+ const doorGeometry = new THREE.BoxGeometry(4, 3, 0.2);
1015
+ const doorMaterial = new THREE.MeshPhongMaterial({
1016
+ color: 0x00ff00,
1017
+ emissive: 0x004400
1018
+ });
1019
+
1020
+ const door = new THREE.Mesh(doorGeometry, doorMaterial);
1021
+ door.position.set(x, y, z);
1022
+ door.rotation.y = rotation;
1023
+
1024
+ return door;
1025
+ }
1026
+
1027
+ // Create the player character
1028
+ function createPlayer() {
1029
+ playerModel = new THREE.Group();
1030
+
1031
+ // Body
1032
+ const bodyGeometry = new THREE.CylinderGeometry(0.5, 0.5, 1.2, 8);
1033
+ const bodyMaterial = new THREE.MeshPhongMaterial({
1034
+ color: 0xffffff,
1035
+ shininess: 100
1036
+ });
1037
+ const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
1038
+ body.position.y = 0.6;
1039
+ playerModel.add(body);
1040
+
1041
+ // Helmet
1042
+ const helmetGeometry = new THREE.SphereGeometry(0.4, 12, 12);
1043
+ const helmetMaterial = new THREE.MeshPhongMaterial({
1044
+ color: 0xffffff,
1045
+ shininess: 100,
1046
+ transparent: true,
1047
+ opacity: 0.7
1048
+ });
1049
+ const helmet = new THREE.Mesh(helmetGeometry, helmetMaterial);
1050
+ helmet.position.y = 1.5;
1051
+ playerModel.add(helmet);
1052
+
1053
+ // Visor
1054
+ const visorGeometry = new THREE.BoxGeometry(0.3, 0.15, 0.05);
1055
+ const visorMaterial = new THREE.MeshPhongMaterial({
1056
+ color: 0x00aaff,
1057
+ emissive: 0x002244
1058
+ });
1059
+ const visor = new THREE.Mesh(visorGeometry, visorMaterial);
1060
+ visor.position.set(0, 1.5, 0.35);
1061
+ playerModel.add(visor);
1062
+
1063
+ player = new THREE.Group();
1064
+ player.add(playerModel);
1065
+ player.position.set(0, 0, 0);
1066
+ scene.add(player);
1067
+ }
1068
+
1069
+ // Create a zombie
1070
+ function createZombie(type, spawnPoint) {
1071
+ const baseHealth = 50 + (currentWave * 15);
1072
+ const baseSpeed = 0.05 + (currentWave * 0.005);
1073
+ const baseDamage = 5 + (currentWave * 1);
1074
+
1075
+ const zombieModel = new THREE.Group();
1076
+
1077
+ // Body
1078
+ const bodyGeometry = new THREE.CylinderGeometry(0.5, 0.5, 1.2, 8);
1079
+ const bodyMaterial = new THREE.MeshPhongMaterial({
1080
+ color: 0xff0000,
1081
+ shininess: 50
1082
+ });
1083
+ const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
1084
+ body.position.y = 0.6;
1085
+ body.rotation.x = Math.PI / 8;
1086
+ zombieModel.add(body);
1087
+
1088
+ // Head
1089
+ const headGeometry = new THREE.SphereGeometry(0.4, 12, 12);
1090
+ const headMaterial = new THREE.MeshPhongMaterial({
1091
+ color: 0xff0000,
1092
+ shininess: 50
1093
+ });
1094
+ const head = new THREE.Mesh(headGeometry, headMaterial);
1095
+ head.position.y = 1.5;
1096
+ zombieModel.add(head);
1097
+
1098
+ const zombie = new THREE.Group();
1099
+ zombie.add(zombieModel);
1100
+
1101
+ // Position at one of the doors
1102
+ const door = doors[spawnPoint];
1103
+ zombie.position.copy(door.position);
1104
+ zombie.position.y = 0;
1105
+
1106
+ zombie.type = type;
1107
+ zombie.speed = baseSpeed;
1108
+ zombie.health = baseHealth;
1109
+ zombie.maxHealth = baseHealth;
1110
+ zombie.damage = baseDamage;
1111
+ zombie.lastDirectionChange = 0;
1112
+ zombie.wobbleOffset = Math.random() * Math.PI * 2;
1113
+
1114
+ scene.add(zombie);
1115
+ zombies.push(zombie);
1116
+
1117
+ return zombie;
1118
+ }
1119
+
1120
+ // Create a projectile
1121
+ function createProjectile(startX, startZ, targetX, targetZ) {
1122
+ const geometry = new THREE.SphereGeometry(0.1, 6, 6);
1123
+ const material = new THREE.MeshBasicMaterial({
1124
+ color: 0x00ffff,
1125
+ emissive: 0x004444
1126
+ });
1127
+
1128
+ const projectile = new THREE.Mesh(geometry, material);
1129
+ projectile.position.set(startX, 0.5, startZ);
1130
+
1131
+ // Calculate direction
1132
+ const dx = targetX - startX;
1133
+ const dz = targetZ - startZ;
1134
+ const distance = Math.sqrt(dx * dx + dz * dz);
1135
+
1136
+ projectile.direction = {
1137
+ x: dx / distance,
1138
+ z: dz / distance
1139
+ };
1140
+
1141
+ projectile.speed = 0.5;
1142
+ projectile.damage = playerDamage;
1143
+
1144
+ scene.add(projectile);
1145
+ projectiles.push(projectile);
1146
+
1147
+ return projectile;
1148
+ }
1149
+
1150
+ // Create an explosion effect
1151
+ function createExplosion(x, z, radius, damage) {
1152
+ const explosion = {
1153
+ x: x,
1154
+ z: z,
1155
+ radius: radius * 3,
1156
+ damage: damage,
1157
+ time: 0,
1158
+ maxTime: 0.5
1159
+ };
1160
+
1161
+ const geometry = new THREE.SphereGeometry(explosion.radius, 16, 16);
1162
+ const material = new THREE.MeshBasicMaterial({
1163
+ color: 0xff5500,
1164
+ transparent: true,
1165
+ opacity: 0.7
1166
+ });
1167
+
1168
+ const explosionMesh = new THREE.Mesh(geometry, material);
1169
+ explosionMesh.position.set(x, 0.1, z);
1170
+ scene.add(explosionMesh);
1171
+
1172
+ explosion.mesh = explosionMesh;
1173
+ explosions.push(explosion);
1174
+
1175
+ return explosion;
1176
+ }
1177
+
1178
+ // Create an item drop
1179
+ function createItemDrop(x, z, type) {
1180
+ const drop = {
1181
+ x: x,
1182
+ z: z,
1183
+ type: type,
1184
+ mesh: null,
1185
+ time: 0
1186
+ };
1187
+
1188
+ if (type === 'exp') {
1189
+ // XP orb
1190
+ const geometry = new THREE.OctahedronGeometry(0.3, 0);
1191
+ const material = new THREE.MeshPhongMaterial({
1192
+ color: 0x00ff00,
1193
+ emissive: 0x004400,
1194
+ shininess: 100
1195
+ });
1196
+
1197
+ const dropMesh = new THREE.Mesh(geometry, material);
1198
+ dropMesh.position.set(x, 0.5, z);
1199
+ scene.add(dropMesh);
1200
+
1201
+ drop.mesh = dropMesh;
1202
+ } else {
1203
+ // Health pack
1204
+ const crossGroup = new THREE.Group();
1205
+
1206
+ const verticalGeometry = new THREE.BoxGeometry(0.2, 0.6, 0.1);
1207
+ const horizontalGeometry = new THREE.BoxGeometry(0.6, 0.2, 0.1);
1208
+
1209
+ const crossMaterial = new THREE.MeshPhongMaterial({
1210
+ color: 0xff0000,
1211
+ emissive: 0x440000,
1212
+ shininess: 100
1213
+ });
1214
+
1215
+ const vertical = new THREE.Mesh(verticalGeometry, crossMaterial);
1216
+ const horizontal = new THREE.Mesh(horizontalGeometry, crossMaterial);
1217
+
1218
+ crossGroup.add(vertical);
1219
+ crossGroup.add(horizontal);
1220
+ crossGroup.position.set(x, 0.5, z);
1221
+
1222
+ scene.add(crossGroup);
1223
+ drop.mesh = crossGroup;
1224
+ }
1225
+
1226
+ itemDrops.push(drop);
1227
+ return drop;
1228
+ }
1229
+
1230
+ // Start a new wave
1231
+ function startWave() {
1232
+ if (currentWave > maxWaves) {
1233
+ gameCompleted = true;
1234
+ document.getElementById('completionMessage').style.display = 'block';
1235
+ document.getElementById('completionDatasetLevel').textContent = datasetLevel;
1236
+ document.getElementById('completionSamples').textContent = mouseDataset.length;
1237
+ return;
1238
+ }
1239
+
1240
+ // Calculate zombies for this wave
1241
+ zombiesInWave = 2 + (currentWave - 1) * 2;
1242
+ zombiesRemaining = zombiesInWave;
1243
+
1244
+ // Show wave alert
1245
+ const waveAlert = document.getElementById('waveAlert');
1246
+ const waveAlertNumber = document.getElementById('waveAlertNumber');
1247
+ waveAlertNumber.textContent = currentWave;
1248
+ waveAlert.style.display = 'block';
1249
+
1250
+ setTimeout(() => {
1251
+ waveAlert.style.display = 'none';
1252
+ }, 2000);
1253
+
1254
+ // Update UI
1255
+ document.getElementById('waveNumber').textContent = currentWave;
1256
+ document.getElementById('zombieCountValue').textContent = zombiesRemaining;
1257
+
1258
+ lastWaveTime = Date.now();
1259
+ }
1260
+
1261
+ // Spawn a zombie
1262
+ function spawnZombie() {
1263
+ if (zombiesRemaining <= 0) return;
1264
+
1265
+ const zombieTypes = ['engineer', 'security', 'cargo', 'scientist'];
1266
+ const type = zombieTypes[Math.floor(Math.random() * zombieTypes.length)];
1267
+ const spawnPoint = Math.floor(Math.random() * doors.length);
1268
+
1269
+ createZombie(type, spawnPoint);
1270
+ zombiesRemaining--;
1271
+
1272
+ document.getElementById('zombieCountValue').textContent = zombiesRemaining;
1273
+ }
1274
+
1275
+ // Player shooting - AUTO SHOOT like original
1276
+ function shoot() {
1277
+ const now = Date.now();
1278
+ if (now - lastShotTime < 100) return; // Rate of fire limit
1279
+
1280
+ // Find nearest zombie to shoot at
1281
+ let nearestZombie = null;
1282
+ let minDistance = Infinity;
1283
+
1284
+ zombies.forEach(zombie => {
1285
+ const dx = zombie.position.x - player.position.x;
1286
+ const dz = zombie.position.z - player.position.z;
1287
+ const distance = Math.sqrt(dx * dx + dz * dz);
1288
+
1289
+ if (distance < minDistance) {
1290
+ minDistance = distance;
1291
+ nearestZombie = zombie;
1292
+ }
1293
+ });
1294
+
1295
+ if (nearestZombie) {
1296
+ createProjectile(
1297
+ player.position.x,
1298
+ player.position.z,
1299
+ nearestZombie.position.x,
1300
+ nearestZombie.position.z
1301
+ );
1302
+
1303
+ // Record auto-shoot for dataset
1304
+ recordAutoShoot(nearestZombie);
1305
+
1306
+ lastShotTime = now;
1307
+ }
1308
+ }
1309
+
1310
+ // Record auto-shoot for dataset
1311
+ function recordAutoShoot(targetZombie) {
1312
+ const now = Date.now();
1313
+ const gameRect = document.getElementById('gameContainer').getBoundingClientRect();
1314
+
1315
+ // Get crosshair position
1316
+ const crosshair = document.querySelector('.crosshair');
1317
+ const x = parseFloat(crosshair.style.left) || gameRect.width / 2;
1318
+ const y = parseFloat(crosshair.style.top) || gameRect.height / 2;
1319
+
1320
+ const normalizedX = x / gameRect.width;
1321
+ const normalizedY = y / gameRect.height;
1322
+
1323
+ const dataPoint = {
1324
+ timestamp: now,
1325
+ type: 'auto_shoot',
1326
+ position: { x: normalizedX, y: normalizedY },
1327
+ gameState: {
1328
+ playerHealth: playerHealth,
1329
+ playerPosition: { x: player.position.x, z: player.position.z },
1330
+ zombiesCount: zombies.length,
1331
+ wave: currentWave,
1332
+ datasetLevel: datasetLevel
1333
+ },
1334
+ action: 'auto_shoot',
1335
+ target: {
1336
+ x: targetZombie.position.x,
1337
+ z: targetZombie.position.z,
1338
+ health: targetZombie.health
1339
+ }
1340
+ };
1341
+
1342
+ mouseDataset.push(dataPoint);
1343
+ addDatasetPoints(2); // Less points for auto-shoot
1344
+ }
1345
+
1346
+ // Use bomb (right click)
1347
+ function useBomb() {
1348
+ if (bombCooldown > 0) return;
1349
+
1350
+ // Create explosion at player's position
1351
+ createExplosion(player.position.x, player.position.z, 3, 50);
1352
+
1353
+ // Set cooldown
1354
+ bombCooldown = bombMaxCooldown;
1355
+ document.getElementById('bombFill').style.width = '0%';
1356
+ document.getElementById('bombTimer').textContent = bombCooldown.toFixed(1) + 's';
1357
+ }
1358
+
1359
+ // Toggle menu
1360
+ function toggleMenu() {
1361
+ isMenuOpen = !isMenuOpen;
1362
+ document.getElementById('menu').style.display = isMenuOpen ? 'block' : 'none';
1363
+
1364
+ if (isMenuOpen) {
1365
+ updateMenu();
1366
+ }
1367
+ }
1368
+
1369
+ // Update menu with current stats
1370
+ function updateMenu() {
1371
+ document.getElementById('menuDatasetLevel').textContent = datasetLevel;
1372
+ document.getElementById('menuDataPoints').textContent = datasetPoints + '/' + pointsToNextLevel;
1373
+ document.getElementById('menuLMB').textContent = lmbCount;
1374
+ document.getElementById('menuRMB').textContent = rmbCount;
1375
+ document.getElementById('menuMovement').textContent = movementSamples;
1376
+
1377
+ const sessionTime = Math.floor((Date.now() - sessionStartTime) / 1000);
1378
+ document.getElementById('menuSessionTime').textContent = sessionTime + 's';
1379
+ }
1380
+
1381
+ // Show export panel
1382
+ function showExportPanel() {
1383
+ // Update export stats
1384
+ const exportStats = document.getElementById('exportStats');
1385
+ exportStats.innerHTML = `
1386
+ <div class="stat-row"><div>Total Samples:</div><div>${mouseDataset.length}</div></div>
1387
+ <div class="stat-row"><div>Movement Clicks (LMB):</div><div>${lmbCount}</div></div>
1388
+ <div class="stat-row"><div>Bomb Clicks (RMB):</div><div>${rmbCount}</div></div>
1389
+ <div class="stat-row"><div>Movement Samples:</div><div>${movementSamples}</div></div>
1390
+ <div class="stat-row"><div>Auto-Shots:</div><div>${mouseDataset.filter(d => d.type === 'auto_shoot').length}</div></div>
1391
+ <div class="stat-row"><div>Dataset Level:</div><div>${datasetLevel}</div></div>
1392
+ <div class="stat-row"><div>Session Duration:</div><div>${Math.floor((Date.now() - sessionStartTime) / 1000)}s</div></div>
1393
+ <div class="stat-row"><div>Waves Completed:</div><div>${currentWave - 1}</div></div>
1394
+ `;
1395
+
1396
+ document.getElementById('exportPanel').style.display = 'block';
1397
+ if (isMenuOpen) toggleMenu();
1398
+ if (gameOver) document.getElementById('gameOver').style.display = 'none';
1399
+ if (gameCompleted) document.getElementById('completionMessage').style.display = 'none';
1400
+ }
1401
+
1402
+ // Export dataset to Hugging Face compatible format
1403
+ function exportDataset() {
1404
+ if (mouseDataset.length === 0) {
1405
+ alert('No data collected yet! Play the game to collect mouse behavior data.');
1406
+ return;
1407
+ }
1408
+
1409
+ // Create RL transitions from mouse data
1410
+ const rlTransitions = mouseDataset.map((point, index) => {
1411
+ const nextPoint = mouseDataset[index + 1] || point;
1412
+ return {
1413
+ state: point.gameState,
1414
+ action: point.action,
1415
+ reward: calculateReward(point),
1416
+ next_state: nextPoint.gameState,
1417
+ done: index === mouseDataset.length - 1,
1418
+ timestamp: point.timestamp
1419
+ };
1420
+ });
1421
+
1422
+ // Create metadata YAML for Hugging Face
1423
+ const metadataYaml = `---
1424
+ license: mit
1425
+ task_categories:
1426
+ - reinforcement-learning
1427
+ - human-computer-interaction
1428
+ task_ids:
1429
+ - mouse-behavior-modeling
1430
+ - rl-from-demonstration
1431
+ language:
1432
+ - en
1433
+ size_categories:
1434
+ - ${mouseDataset.length < 1000 ? 'n<1K' : mouseDataset.length < 10000 ? '1K<n<10K' : '10K<n<100K'}
1435
+ tags:
1436
+ - mouse-input
1437
+ - human-in-the-loop
1438
+ - reinforcement-learning
1439
+ - webxos-2026
1440
+ - space-zombies-rl
1441
+ pretty_name: "Space Zombies RL Mouse Behavior Dataset"
1442
+ dataset_info:
1443
+ features:
1444
+ - name: state
1445
+ dtype:
1446
+ playerHealth: float32
1447
+ playerPosition:
1448
+ x: float32
1449
+ z: float32
1450
+ zombiesCount: int32
1451
+ wave: int32
1452
+ datasetLevel: int32
1453
+ - name: action
1454
+ dtype: string
1455
+ - name: reward
1456
+ dtype: float32
1457
+ - name: next_state
1458
+ dtype:
1459
+ playerHealth: float32
1460
+ playerPosition:
1461
+ x: float32
1462
+ z: float32
1463
+ zombiesCount: int32
1464
+ wave: int32
1465
+ datasetLevel: int32
1466
+ - name: done
1467
+ dtype: bool
1468
+ - name: timestamp
1469
+ dtype: int64
1470
+ splits:
1471
+ train:
1472
+ num_examples: ${Math.floor(mouseDataset.length * 0.8)}
1473
+ test:
1474
+ num_examples: ${Math.floor(mouseDataset.length * 0.2)}
1475
+ ---
1476
+ # Space Zombies RL Mouse Behavior Dataset
1477
+
1478
+ This dataset contains mouse interaction data collected from the "Space Zombies RL" game, designed for reinforcement learning research on human input patterns.
1479
+
1480
+ ## Dataset Description
1481
+
1482
+ - **Total Samples**: ${mouseDataset.length}
1483
+ - **Collection Date**: ${new Date().toISOString().split('T')[0]}
1484
+ - **Game Version**: Space Zombies RL v1.0 by webXOS 2026
1485
+ - **Purpose**: RL training from human demonstrations, mouse behavior modeling, adaptive interface research
1486
+
1487
+ ## Usage
1488
+
1489
+ \`\`\`python
1490
+ from datasets import load_dataset
1491
+
1492
+ dataset = load_dataset("your-username/space-zombies-rl")
1493
+ \`\`\`
1494
+
1495
+ ## Citation
1496
+
1497
+ If you use this dataset in your research, please cite:
1498
+
1499
+ \`\`\`
1500
+ @dataset{space_zombies_rl_2026,
1501
+ title={Space Zombies RL Mouse Behavior Dataset},
1502
+ author={webXOS Research},
1503
+ year={2026},
1504
+ publisher={Hugging Face}
1505
+ }
1506
+ \`\`\`
1507
+ `;
1508
+
1509
+ // Create README
1510
+ const readmeText = `# Space Zombies RL Dataset
1511
+
1512
+ ## Overview
1513
+ Mouse behavior dataset collected from the Space Zombies RL game. Contains ${mouseDataset.length} samples of mouse movements, clicks, and game state transitions.
1514
+
1515
+ ## Files
1516
+ - \`mouse_behavior.json\`: Raw mouse interaction data
1517
+ - \`rl_transitions.csv\`: State-action-reward-next_state tuples for RL training
1518
+ - \`metadata.yaml\`: Hugging Face dataset card
1519
+ - \`README.md\`: This file
1520
+
1521
+ ## Collection Parameters
1522
+ - Sampling Rate: ${samplingInterval}ms for movement
1523
+ - Game: Space Zombies RL (webXOS 2026)
1524
+ - Controls: Click to move, auto-aim shooting, right-click for bomb
1525
+ - Waves Completed: ${currentWave - 1}
1526
+ - Dataset Level: ${datasetLevel}
1527
+
1528
+ ## Research Applications
1529
+ - Reinforcement Learning from Human Demonstrations
1530
+ - Mouse Behavior Modeling
1531
+ - Adaptive Interface Design
1532
+ - Human-in-the-loop RL
1533
+ - Neurorehabilitation Research
1534
+
1535
+ ## License
1536
+ MIT License - See metadata.yaml for details
1537
+
1538
+ ## Contact
1539
+ webXOS Research 2026
1540
+ `;
1541
+
1542
+ // Create CSV for transitions
1543
+ let csvContent = "timestamp,playerHealth,playerX,playerZ,zombiesCount,wave,datasetLevel,action,reward,nextHealth,nextX,nextZ,nextZombiesCount,nextWave,nextDatasetLevel,done\n";
1544
+ rlTransitions.forEach(transition => {
1545
+ const state = transition.state;
1546
+ const nextState = transition.next_state;
1547
+ csvContent += `${transition.timestamp},${state.playerHealth},${state.playerPosition.x},${state.playerPosition.z},${state.zombiesCount},${state.wave},${state.datasetLevel},${transition.action},${transition.reward},${nextState.playerHealth},${nextState.playerPosition.x},${nextState.playerPosition.z},${nextState.zombiesCount},${nextState.wave},${nextState.datasetLevel},${transition.done}\n`;
1548
+ });
1549
+
1550
+ // Create ZIP file
1551
+ const zip = new JSZip();
1552
+ zip.file("mouse_behavior.json", JSON.stringify(mouseDataset, null, 2));
1553
+ zip.file("rl_transitions.csv", csvContent);
1554
+ zip.file("metadata.yaml", metadataYaml);
1555
+ zip.file("README.md", readmeText);
1556
+
1557
+ // Generate and download ZIP
1558
+ zip.generateAsync({type: "blob", compression: "DEFLATE"})
1559
+ .then(function(blob) {
1560
+ // Create download link
1561
+ const a = document.createElement('a');
1562
+ const url = URL.createObjectURL(blob);
1563
+ a.href = url;
1564
+ a.download = `space_zombies_rl_dataset_${Date.now()}.zip`;
1565
+ document.body.appendChild(a);
1566
+ a.click();
1567
+
1568
+ // Clean up
1569
+ setTimeout(() => {
1570
+ document.body.removeChild(a);
1571
+ URL.revokeObjectURL(url);
1572
+ showNotification('Dataset exported successfully!', '#00ff00');
1573
+ }, 100);
1574
+ })
1575
+ .catch(error => {
1576
+ console.error('Error creating ZIP:', error);
1577
+ showNotification('Export failed!', '#ff0000');
1578
+ });
1579
+ }
1580
+
1581
+ // Calculate reward for RL transition
1582
+ function calculateReward(dataPoint) {
1583
+ let reward = 0;
1584
+
1585
+ // Positive rewards for actions
1586
+ if (dataPoint.type === 'move_click') reward += 0.05; // Movement
1587
+ if (dataPoint.type === 'rmb') reward += 0.1; // Bomb
1588
+ if (dataPoint.type === 'auto_shoot') reward += 0.02; // Auto-shoot
1589
+
1590
+ // Negative rewards for low health
1591
+ if (dataPoint.gameState.playerHealth < 30) reward -= 0.03;
1592
+
1593
+ // Reward for progress
1594
+ reward += dataPoint.gameState.datasetLevel * 0.01;
1595
+
1596
+ return parseFloat(reward.toFixed(3));
1597
+ }
1598
+
1599
+ // Check for collisions
1600
+ function checkCollisions() {
1601
+ // Projectile vs Zombie collisions
1602
+ for (let i = projectiles.length - 1; i >= 0; i--) {
1603
+ const projectile = projectiles[i];
1604
+
1605
+ for (let j = zombies.length - 1; j >= 0; j--) {
1606
+ const zombie = zombies[j];
1607
+
1608
+ const dx = projectile.position.x - zombie.position.x;
1609
+ const dz = projectile.position.z - zombie.position.z;
1610
+ const distance = Math.sqrt(dx * dx + dz * dz);
1611
+
1612
+ if (distance < 0.5) {
1613
+ // Damage zombie
1614
+ zombie.health -= projectile.damage;
1615
+
1616
+ // Remove projectile
1617
+ scene.remove(projectile);
1618
+ projectiles.splice(i, 1);
1619
+
1620
+ // Check if zombie is dead
1621
+ if (zombie.health <= 0) {
1622
+ // Create item drops
1623
+ const dropType = Math.random() < 0.5 ? 'exp' : 'health';
1624
+ createItemDrop(zombie.position.x, zombie.position.z, dropType);
1625
+
1626
+ // Add dataset points for killing zombie
1627
+ addDatasetPoints(15);
1628
+
1629
+ // Remove zombie
1630
+ scene.remove(zombie);
1631
+ zombies.splice(j, 1);
1632
+ zombiesKilled++;
1633
+
1634
+ // Check if wave is complete
1635
+ if (zombies.length === 0 && zombiesRemaining === 0) {
1636
+ currentWave++;
1637
+ if (currentWave <= maxWaves) {
1638
+ setTimeout(() => startWave(), 2000);
1639
+ }
1640
+ }
1641
+ }
1642
+
1643
+ break;
1644
+ }
1645
+ }
1646
+
1647
+ // Remove projectiles that go too far
1648
+ if (Math.abs(projectile.position.x) > 30 || Math.abs(projectile.position.z) > 30) {
1649
+ scene.remove(projectile);
1650
+ projectiles.splice(i, 1);
1651
+ }
1652
+ }
1653
+
1654
+ // Explosion vs Zombie collisions
1655
+ for (let i = explosions.length - 1; i >= 0; i--) {
1656
+ const explosion = explosions[i];
1657
+
1658
+ for (let j = zombies.length - 1; j >= 0; j--) {
1659
+ const zombie = zombies[j];
1660
+
1661
+ const dx = explosion.x - zombie.position.x;
1662
+ const dz = explosion.z - zombie.position.z;
1663
+ const distance = Math.sqrt(dx * dx + dz * dz);
1664
+
1665
+ if (distance < explosion.radius) {
1666
+ // Damage zombie
1667
+ zombie.health -= explosion.damage;
1668
+
1669
+ // Check if zombie is dead
1670
+ if (zombie.health <= 0) {
1671
+ // Create item drops
1672
+ const dropType = Math.random() < 0.5 ? 'exp' : 'health';
1673
+ createItemDrop(zombie.position.x, zombie.position.z, dropType);
1674
+
1675
+ // Add dataset points for killing zombie with bomb
1676
+ addDatasetPoints(25);
1677
+
1678
+ // Remove zombie
1679
+ scene.remove(zombie);
1680
+ zombies.splice(j, 1);
1681
+ zombiesKilled++;
1682
+
1683
+ // Check if wave is complete
1684
+ if (zombies.length === 0 && zombiesRemaining === 0) {
1685
+ currentWave++;
1686
+ if (currentWave <= maxWaves) {
1687
+ setTimeout(() => startWave(), 2000);
1688
+ }
1689
+ }
1690
+ }
1691
+ }
1692
+ }
1693
+
1694
+ // Update explosion
1695
+ explosion.time += 0.016;
1696
+ if (explosion.mesh) {
1697
+ explosion.mesh.material.opacity = 0.7 * (1 - explosion.time / explosion.maxTime);
1698
+ }
1699
+
1700
+ // Remove expired explosions
1701
+ if (explosion.time >= explosion.maxTime) {
1702
+ if (explosion.mesh) {
1703
+ scene.remove(explosion.mesh);
1704
+ }
1705
+ explosions.splice(i, 1);
1706
+ }
1707
+ }
1708
+
1709
+ // Player vs Item collisions
1710
+ for (let i = itemDrops.length - 1; i >= 0; i--) {
1711
+ const drop = itemDrops[i];
1712
+
1713
+ const dx = player.position.x - drop.x;
1714
+ const dz = player.position.z - drop.z;
1715
+ const distance = Math.sqrt(dx * dx + dz * dz);
1716
+
1717
+ if (distance < 0.8) {
1718
+ if (drop.type === 'exp') {
1719
+ addDatasetPoints(20); // XP orbs give dataset points
1720
+ } else if (drop.type === 'health') {
1721
+ playerHealth = Math.min(playerMaxHealth, playerHealth + 30);
1722
+ }
1723
+
1724
+ // Remove drop
1725
+ scene.remove(drop.mesh);
1726
+ itemDrops.splice(i, 1);
1727
+
1728
+ // Update UI
1729
+ updateUI();
1730
+ }
1731
+
1732
+ // Animate item drops
1733
+ if (drop.mesh) {
1734
+ drop.time += 0.05;
1735
+ drop.mesh.position.y = 0.5 + Math.sin(drop.time) * 0.2;
1736
+
1737
+ if (drop.mesh.rotation) {
1738
+ drop.mesh.rotation.y += 0.02;
1739
+ }
1740
+ }
1741
+ }
1742
+
1743
+ // Zombie vs Player collisions
1744
+ for (let i = zombies.length - 1; i >= 0; i--) {
1745
+ const zombie = zombies[i];
1746
+
1747
+ const dx = player.position.x - zombie.position.x;
1748
+ const dz = player.position.z - zombie.position.z;
1749
+ const distance = Math.sqrt(dx * dx + dz * dz);
1750
+
1751
+ if (distance < 0.8) {
1752
+ playerHealth -= zombie.damage;
1753
+
1754
+ if (playerHealth <= 0) {
1755
+ gameOver = true;
1756
+ document.getElementById('gameOver').style.display = 'block';
1757
+ document.getElementById('finalWave').textContent = currentWave;
1758
+ document.getElementById('finalDatasetLevel').textContent = datasetLevel;
1759
+ document.getElementById('finalDataPoints').textContent = mouseDataset.length;
1760
+ }
1761
+
1762
+ updateUI();
1763
+ }
1764
+ }
1765
+ }
1766
+
1767
+ // Update UI elements
1768
+ function updateUI() {
1769
+ const healthPercent = (playerHealth / playerMaxHealth) * 100;
1770
+ document.getElementById('healthFill').style.width = healthPercent + '%';
1771
+ document.getElementById('healthText').textContent = Math.floor(healthPercent) + '%';
1772
+
1773
+ // Update bomb cooldown
1774
+ if (bombCooldown > 0) {
1775
+ const cooldownPercent = (bombCooldown / bombMaxCooldown) * 100;
1776
+ document.getElementById('bombFill').style.width = (100 - cooldownPercent) + '%';
1777
+ document.getElementById('bombTimer').textContent = bombCooldown.toFixed(1) + 's';
1778
+ } else {
1779
+ document.getElementById('bombFill').style.width = '100%';
1780
+ document.getElementById('bombTimer').textContent = 'READY';
1781
+ }
1782
+ }
1783
+
1784
+ // Restart the game
1785
+ function restartGame() {
1786
+ // Reset game state
1787
+ playerHealth = 100;
1788
+ playerMaxHealth = 100;
1789
+ datasetLevel = 1;
1790
+ datasetPoints = 0;
1791
+ pointsToNextLevel = 100;
1792
+ playerSpeed = 0.1;
1793
+ playerDamage = 10;
1794
+ currentWave = 1;
1795
+ zombiesInWave = 0;
1796
+ zombiesRemaining = 0;
1797
+ zombiesKilled = 0;
1798
+ gameOver = false;
1799
+ gameCompleted = false;
1800
+ bombCooldown = 0;
1801
+ moveToTarget = null;
1802
+ isMoving = false;
1803
+ autoShoot = true;
1804
+
1805
+ // Reset dataset collection
1806
+ mouseDataset = [];
1807
+ sessionStartTime = Date.now();
1808
+ lmbCount = 0;
1809
+ rmbCount = 0;
1810
+ movementSamples = 0;
1811
+ lastMouseMoveTime = 0;
1812
+ lastMousePosition = { x: 0, y: 0 };
1813
+
1814
+ // Clear all game objects
1815
+ while (zombies.length > 0) {
1816
+ const zombie = zombies.pop();
1817
+ scene.remove(zombie);
1818
+ }
1819
+
1820
+ while (projectiles.length > 0) {
1821
+ const projectile = projectiles.pop();
1822
+ scene.remove(projectile);
1823
+ }
1824
+
1825
+ while (itemDrops.length > 0) {
1826
+ const drop = itemDrops.pop();
1827
+ if (drop.mesh) scene.remove(drop.mesh);
1828
+ }
1829
+
1830
+ while (explosions.length > 0) {
1831
+ const explosion = explosions.pop();
1832
+ if (explosion.mesh) scene.remove(explosion.mesh);
1833
+ }
1834
+
1835
+ // Reset player position
1836
+ player.position.set(0, 0, 0);
1837
+
1838
+ // Update UI
1839
+ updateUI();
1840
+ updateDatasetUI();
1841
+
1842
+ // Update data stats
1843
+ document.getElementById('lmbCount').textContent = lmbCount;
1844
+ document.getElementById('rmbCount').textContent = rmbCount;
1845
+ document.getElementById('moveCount').textContent = movementSamples;
1846
+ document.getElementById('sessionTime').textContent = 0;
1847
+
1848
+ // Hide game over/completion messages
1849
+ document.getElementById('gameOver').style.display = 'none';
1850
+ document.getElementById('completionMessage').style.display = 'none';
1851
+ document.getElementById('menu').style.display = 'none';
1852
+ document.getElementById('exportPanel').style.display = 'none';
1853
+ isMenuOpen = false;
1854
+
1855
+ // Start first wave
1856
+ startWave();
1857
+ }
1858
+
1859
+ // Game loop
1860
+ function animate() {
1861
+ if (gameOver || gameCompleted) {
1862
+ requestAnimationFrame(animate);
1863
+ return;
1864
+ }
1865
+
1866
+ const now = Date.now();
1867
+ const deltaTime = (now - lastSpawnTime) / 1000;
1868
+
1869
+ // Handle player movement
1870
+ if (isMoving && moveToTarget) {
1871
+ const dx = moveToTarget.x - player.position.x;
1872
+ const dz = moveToTarget.z - player.position.z;
1873
+ const distance = Math.sqrt(dx * dx + dz * dz);
1874
+
1875
+ if (distance > 0.2) {
1876
+ // Move towards target
1877
+ player.position.x += (dx / distance) * playerSpeed;
1878
+ player.position.z += (dz / distance) * playerSpeed;
1879
+
1880
+ // Rotate player to face movement direction
1881
+ const angle = Math.atan2(dx, dz);
1882
+ player.rotation.y = angle;
1883
+ } else {
1884
+ // Reached target
1885
+ isMoving = false;
1886
+ moveToTarget = null;
1887
+ }
1888
+ }
1889
+
1890
+ // Keep player within bounds
1891
+ player.position.x = Math.max(-24, Math.min(24, player.position.x));
1892
+ player.position.z = Math.max(-24, Math.min(24, player.position.z));
1893
+
1894
+ // Handle shooting (always auto-shoot like original)
1895
+ shoot();
1896
+
1897
+ // Update bomb cooldown
1898
+ if (bombCooldown > 0) {
1899
+ bombCooldown -= deltaTime;
1900
+ if (bombCooldown < 0) bombCooldown = 0;
1901
+ }
1902
+
1903
+ // Spawn zombies
1904
+ if (zombiesRemaining > 0 && now - lastSpawnTime > 1000) {
1905
+ spawnZombie();
1906
+ lastSpawnTime = now;
1907
+ }
1908
+
1909
+ // Update zombies with enhanced AI and movement
1910
+ zombies.forEach(zombie => {
1911
+ // Move towards player with occasional direction changes
1912
+ const dx = player.position.x - zombie.position.x;
1913
+ const dz = player.position.z - zombie.position.z;
1914
+ const distance = Math.sqrt(dx * dx + dz * dz);
1915
+
1916
+ if (distance > 0.5) {
1917
+ const currentTime = Date.now();
1918
+ if (currentTime - zombie.lastDirectionChange > 1000) {
1919
+ zombie.lastDirectionChange = currentTime;
1920
+ }
1921
+
1922
+ // Wobble effect for realistic zombie movement
1923
+ const wobble = Math.sin(currentTime * 0.01 + zombie.wobbleOffset) * 0.1;
1924
+ const angle = Math.atan2(dx, dz) + wobble;
1925
+
1926
+ zombie.position.x += Math.sin(angle) * zombie.speed;
1927
+ zombie.position.z += Math.cos(angle) * zombie.speed;
1928
+
1929
+ // Rotate to face movement direction
1930
+ zombie.rotation.y = angle;
1931
+ }
1932
+ });
1933
+
1934
+ // Update projectiles
1935
+ projectiles.forEach(projectile => {
1936
+ projectile.position.x += projectile.direction.x * projectile.speed;
1937
+ projectile.position.z += projectile.direction.z * projectile.speed;
1938
+ });
1939
+
1940
+ // Auto-aim at nearest zombie if not moving (like original)
1941
+ if (!isMoving) {
1942
+ let nearestZombie = null;
1943
+ let minDistance = Infinity;
1944
+
1945
+ zombies.forEach(zombie => {
1946
+ const dx = zombie.position.x - player.position.x;
1947
+ const dz = zombie.position.z - player.position.z;
1948
+ const distance = Math.sqrt(dx * dx + dz * dz);
1949
+
1950
+ if (distance < minDistance) {
1951
+ minDistance = distance;
1952
+ nearestZombie = zombie;
1953
+ }
1954
+ });
1955
+
1956
+ if (nearestZombie) {
1957
+ const dx = nearestZombie.position.x - player.position.x;
1958
+ const dz = nearestZombie.position.z - player.position.z;
1959
+ const angle = Math.atan2(dx, dz);
1960
+ player.rotation.y = angle;
1961
+ }
1962
+ }
1963
+
1964
+ // Check collisions
1965
+ checkCollisions();
1966
+
1967
+ // Update UI
1968
+ updateUI();
1969
+
1970
+ // Render
1971
+ renderer.render(scene, camera);
1972
+
1973
+ requestAnimationFrame(animate);
1974
+ }
1975
+
1976
+ // Start the game
1977
+ init();
1978
+ </script>
1979
+ </body>
1980
+ </html>