webxos commited on
Commit
9c738df
·
verified ·
1 Parent(s): 54b6115

Upload webXOS_ghosthunter_gym_v1.html

Browse files
Files changed (1) hide show
  1. webXOS_ghosthunter_gym_v1.html +900 -0
webXOS_ghosthunter_gym_v1.html ADDED
@@ -0,0 +1,900 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!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">
6
+ <title>GHOST HUNTER · DATA SET GYM</title>
7
+ <!-- 8-bit font -->
8
+ <link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
9
+ <style>
10
+ body {
11
+ margin: 0;
12
+ overflow: hidden;
13
+ font-family: 'Press Start 2P', 'Courier New', monospace;
14
+ background-color: black;
15
+ image-rendering: pixelated;
16
+ image-rendering: crisp-edges;
17
+ }
18
+ #info {
19
+ position: absolute;
20
+ top: 10px;
21
+ left: 10px;
22
+ color: #8af0ff;
23
+ text-shadow: 2px 2px 0 #004466;
24
+ font-size: 0.7rem;
25
+ z-index: 100;
26
+ background: #001c28;
27
+ padding: 6px 10px;
28
+ border: 2px solid #3ecfcf;
29
+ outline: 2px solid #005f7a;
30
+ letter-spacing: 0.5px;
31
+ pointer-events: none;
32
+ box-shadow: 4px 4px 0 #001018;
33
+ }
34
+ #timer-round {
35
+ position: absolute;
36
+ top: 10px;
37
+ left: 50%;
38
+ transform: translateX(-50%);
39
+ color: #ffffaa;
40
+ font-size: 0.9rem;
41
+ text-shadow: 2px 2px 0 #886600;
42
+ background: #1a2a1a;
43
+ padding: 6px 12px;
44
+ border: 2px solid #aaff55;
45
+ outline: 2px solid #3f9f3f;
46
+ z-index: 100;
47
+ letter-spacing: 0.5px;
48
+ white-space: nowrap;
49
+ box-shadow: 4px 4px 0 #0a1f0a;
50
+ }
51
+ #ghost-count {
52
+ position: absolute;
53
+ top: 10px;
54
+ right: 10px;
55
+ color: #ffaa88;
56
+ font-size: 0.9rem;
57
+ text-shadow: 2px 2px 0 #882200;
58
+ background: #2a1010;
59
+ padding: 6px 12px;
60
+ border: 2px solid #ff8866;
61
+ outline: 2px solid #aa4444;
62
+ z-index: 100;
63
+ letter-spacing: 0.5px;
64
+ box-shadow: 4px 4px 0 #200808;
65
+ }
66
+ #crosshair {
67
+ position: absolute;
68
+ top: 50%;
69
+ left: 50%;
70
+ transform: translate(-50%, -50%);
71
+ width: 18px;
72
+ height: 18px;
73
+ border: 3px solid #aaf0ff;
74
+ box-shadow: 0 0 0 2px #004466, 2px 2px 0 #003344;
75
+ pointer-events: none;
76
+ z-index: 200;
77
+ opacity: 0.9;
78
+ }
79
+ #crosshair::after {
80
+ content: '';
81
+ position: absolute;
82
+ top: 50%;
83
+ left: 50%;
84
+ width: 5px;
85
+ height: 5px;
86
+ background: #aaf0ff;
87
+ transform: translate(-50%, -50%);
88
+ box-shadow: 1px 1px 0 #004466;
89
+ }
90
+ #instructions {
91
+ position: absolute;
92
+ bottom: 15px;
93
+ left: 50%;
94
+ transform: translateX(-50%);
95
+ color: #b5ffff;
96
+ font-size: 0.55rem;
97
+ text-shadow: 2px 2px 0 #006688;
98
+ background: #0a1c28;
99
+ padding: 8px 14px;
100
+ border: 2px solid #3ecfcf;
101
+ outline: 2px solid #006688;
102
+ z-index: 100;
103
+ letter-spacing: 0.5px;
104
+ white-space: nowrap;
105
+ box-shadow: 4px 4px 0 #021018;
106
+ animation: pulse 2s step-end infinite;
107
+ }
108
+ @keyframes pulse {
109
+ 0% { opacity: 1; background: #0a1c28; }
110
+ 50% { opacity: 0.9; background: #0e2430; border-color: #5fe0e0; }
111
+ 100% { opacity: 1; background: #0a1c28; }
112
+ }
113
+ #victory {
114
+ position: absolute;
115
+ top: 50%;
116
+ left: 50%;
117
+ transform: translate(-50%, -50%);
118
+ color: #ffffaa;
119
+ font-size: 1.8rem;
120
+ text-shadow: 3px 3px 0 #448800;
121
+ background: #1a3f1a;
122
+ padding: 20px 30px;
123
+ border: 4px solid #aaff55;
124
+ outline: 3px solid #2f9f2f;
125
+ z-index: 300;
126
+ letter-spacing: 2px;
127
+ display: none;
128
+ text-align: center;
129
+ line-height: 1.5;
130
+ box-shadow: 10px 10px 0 #0a2a0a;
131
+ }
132
+ #victory span {
133
+ font-size: 1.0rem;
134
+ display: block;
135
+ margin-top: 15px;
136
+ color: #aaf0ff;
137
+ text-shadow: 2px 2px 0 #004466;
138
+ }
139
+ .scanline {
140
+ position: absolute;
141
+ top: 0;
142
+ left: 0;
143
+ width: 100%;
144
+ height: 100%;
145
+ background: repeating-linear-gradient(0deg, rgba(0,255,255,0.03) 0px, rgba(0,0,0,0.2) 2px, transparent 3px);
146
+ pointer-events: none;
147
+ z-index: 300;
148
+ opacity: 0.3;
149
+ }
150
+ .hit-effect {
151
+ position: absolute;
152
+ width: 20px;
153
+ height: 20px;
154
+ background: radial-gradient(circle, #ffffaa, #ff8800);
155
+ border-radius: 50%;
156
+ pointer-events: none;
157
+ z-index: 400;
158
+ transform: translate(-50%, -50%);
159
+ animation: hitPing 0.2s ease-out forwards;
160
+ }
161
+ @keyframes hitPing {
162
+ 0% { opacity: 1; transform: translate(-50%, -50%) scale(0.5); }
163
+ 100% { opacity: 0; transform: translate(-50%, -50%) scale(2); }
164
+ }
165
+ /* small flash for hit (kept for screen feedback) */
166
+ .kill-flash {
167
+ position: absolute;
168
+ top: 0;
169
+ left: 0;
170
+ width: 100%;
171
+ height: 100%;
172
+ background: rgba(255,220,150,0.1);
173
+ pointer-events: none;
174
+ z-index: 500;
175
+ animation: flashFade 0.1s ease-out;
176
+ }
177
+ @keyframes flashFade {
178
+ 0% { opacity: 0.4; }
179
+ 100% { opacity: 0; }
180
+ }
181
+ #lock-hint {
182
+ position: absolute;
183
+ bottom: 70px;
184
+ left: 50%;
185
+ transform: translateX(-50%);
186
+ color: #b0b0ff;
187
+ font-size: 0.45rem;
188
+ background: #000c1a;
189
+ padding: 4px 8px;
190
+ border: 1px solid #3399ff;
191
+ z-index: 150;
192
+ white-space: nowrap;
193
+ }
194
+ /* Dataset UI */
195
+ #dataset-panel {
196
+ position: absolute;
197
+ bottom: 120px;
198
+ right: 10px;
199
+ background: #0a1a2a;
200
+ border: 2px solid #ffaa55;
201
+ outline: 2px solid #aa5500;
202
+ padding: 8px 12px;
203
+ color: #ffdd99;
204
+ font-size: 0.6rem;
205
+ z-index: 250;
206
+ box-shadow: 4px 4px 0 #031010;
207
+ display: flex;
208
+ flex-direction: column;
209
+ gap: 6px;
210
+ min-width: 160px;
211
+ }
212
+ #dataset-panel button {
213
+ font-family: 'Press Start 2P', monospace;
214
+ background: #2a3f3f;
215
+ border: 2px solid #88aaff;
216
+ color: #ddeeff;
217
+ padding: 6px 8px;
218
+ font-size: 0.55rem;
219
+ cursor: pointer;
220
+ box-shadow: 2px 2px 0 #001122;
221
+ }
222
+ #dataset-panel button:hover {
223
+ background: #3f5f5f;
224
+ }
225
+ #capture-count {
226
+ color: #aaffaa;
227
+ text-align: right;
228
+ }
229
+ #export-status {
230
+ font-size: 0.45rem;
231
+ color: #99ccff;
232
+ word-break: break-all;
233
+ max-width: 180px;
234
+ }
235
+ </style>
236
+ <script type="importmap">
237
+ {
238
+ "imports": {
239
+ "three": "https://unpkg.com/three@0.128.0/build/three.module.js",
240
+ "three/addons/": "https://unpkg.com/three@0.128.0/examples/jsm/",
241
+ "jszip": "https://cdn.skypack.dev/jszip@3.10.1"
242
+ }
243
+ }
244
+ </script>
245
+ </head>
246
+ <body>
247
+ <div id="info">>> GHOST HUNTER // DATASET GYM // by webXOS </div>
248
+ <div id="timer-round">TIME 00:00 ROUND 1/10</div>
249
+ <div id="ghost-count">GHOSTS 0</div>
250
+ <div id="crosshair"></div>
251
+ <div id="instructions">[CLICK TO LOCK] W/A/S/D MOVE | HOLD LMB AUTO (tight spread) | KILL = SCREENSHOT</div>
252
+ <div id="lock-hint">↖ CLICK GAME AREA TO LOCK / ESC TO UNLOCK</div>
253
+ <div id="victory">VICTORY<span id="final-time"></span></div>
254
+ <div class="scanline"></div>
255
+
256
+ <!-- Dataset capture & export panel -->
257
+ <div id="dataset-panel">
258
+ <div style="display: flex; justify-content: space-between;">
259
+ <span>📸 CAPTURES</span>
260
+ <span id="capture-count">0</span>
261
+ </div>
262
+ <button id="export-dataset">💾 EXPORT DATASET (ZIP)</button>
263
+ <div id="export-status"></div>
264
+ </div>
265
+
266
+ <script type="module">
267
+ import * as THREE from 'three';
268
+ import { PointerLockControls } from 'three/addons/controls/PointerLockControls.js';
269
+ import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
270
+ import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
271
+ import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
272
+ import JSZip from 'jszip';
273
+
274
+ // --- SCENE SETUP ---
275
+ const scene = new THREE.Scene();
276
+ scene.background = new THREE.Color(0x050510);
277
+ const camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.1, 1000);
278
+ camera.position.set(0, 1.8, 0);
279
+ const renderer = new THREE.WebGLRenderer({ antialias: false, powerPreference: "high-performance", preserveDrawingBuffer: true }); // preserveDrawingBuffer for captures
280
+ renderer.setSize(window.innerWidth, window.innerHeight);
281
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.0));
282
+ renderer.toneMapping = THREE.ReinhardToneMapping;
283
+ document.body.appendChild(renderer.domElement);
284
+
285
+ // --- POST PROCESSING ---
286
+ const renderScene = new RenderPass(scene, camera);
287
+ const bloomPass = new UnrealBloomPass(new THREE.Vector2(window.innerWidth, window.innerHeight), 1.0, 0.3, 0.6);
288
+ bloomPass.threshold = 0.1;
289
+ bloomPass.strength = 1.3;
290
+ bloomPass.radius = 0.7;
291
+ const composer = new EffectComposer(renderer);
292
+ composer.addPass(renderScene);
293
+ composer.addPass(bloomPass);
294
+
295
+ // --- CONTROLS ---
296
+ const controls = new PointerLockControls(camera, document.body);
297
+ scene.add(controls.getObject());
298
+
299
+ renderer.domElement.addEventListener('click', () => {
300
+ if (gameActive) controls.lock();
301
+ });
302
+
303
+ // --- MOVEMENT (A left, D right) ---
304
+ const keyState = { w: false, a: false, s: false, d: false };
305
+ document.addEventListener('keydown', (e) => {
306
+ if (!gameActive) return;
307
+ switch(e.code) {
308
+ case 'KeyW': keyState.w = true; e.preventDefault(); break;
309
+ case 'KeyA': keyState.a = true; e.preventDefault(); break;
310
+ case 'KeyS': keyState.s = true; e.preventDefault(); break;
311
+ case 'KeyD': keyState.d = true; e.preventDefault(); break;
312
+ default: break;
313
+ }
314
+ });
315
+ document.addEventListener('keyup', (e) => {
316
+ switch(e.code) {
317
+ case 'KeyW': keyState.w = false; e.preventDefault(); break;
318
+ case 'KeyA': keyState.a = false; e.preventDefault(); break;
319
+ case 'KeyS': keyState.s = false; e.preventDefault(); break;
320
+ case 'KeyD': keyState.d = false; e.preventDefault(); break;
321
+ default: break;
322
+ }
323
+ });
324
+
325
+ const velocity = new THREE.Vector3();
326
+ const moveSpeed = 0.06;
327
+ const damping = 0.92;
328
+ const boundary = 20;
329
+
330
+ // --- WORLD POINTS (same as before) ---
331
+ const patterns = [
332
+ [[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]],
333
+ [[0,0,0,0,0],[0,0,0,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]],
334
+ [[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0]]
335
+ ];
336
+ const cellSize = 1.8;
337
+ const jitter = 0.2;
338
+ const positions = [];
339
+ const colors = [];
340
+ function addPoint(px, py, pz) {
341
+ positions.push(px, py, pz);
342
+ colors.push(0.5+0.3*Math.random(), 0.7+0.3*Math.random(), 1.0);
343
+ }
344
+ const floorMin = -boundary, floorMax = boundary;
345
+ const cellsX = Math.floor((floorMax - floorMin) / cellSize);
346
+ const cellsZ = cellsX;
347
+ for (let i = 0; i < cellsX; i++) {
348
+ for (let j = 0; j < cellsZ; j++) {
349
+ const wx = floorMin + i * cellSize + cellSize/2;
350
+ const wz = floorMin + j * cellSize + cellSize/2;
351
+ const patIdx = (i + j) % patterns.length;
352
+ const pattern = patterns[patIdx];
353
+ for (let r = 0; r < 5; r++) {
354
+ for (let c = 0; c < 5; c++) {
355
+ if (pattern[r][c] === 1) {
356
+ const offsetX = (c/4-0.5)*cellSize*0.8 + (Math.random()-0.5)*jitter;
357
+ const offsetZ = (r/4-0.5)*cellSize*0.8 + (Math.random()-0.5)*jitter;
358
+ const offsetY = (Math.random()-0.5)*0.15;
359
+ addPoint(wx+offsetX, 0+offsetY, wz+offsetZ);
360
+ }
361
+ }
362
+ }
363
+ }
364
+ }
365
+ for (let s = -1; s <= 1; s+=2) {
366
+ for (let z = -boundary; z <= boundary; z+= cellSize*1.5) {
367
+ for (let y = 1; y < 10; y+= cellSize*0.9) {
368
+ addPoint(s*boundary, y, z);
369
+ }
370
+ }
371
+ for (let x = -boundary; x <= boundary; x+= cellSize*1.5) {
372
+ for (let y = 1; y < 10; y+= cellSize*0.9) {
373
+ addPoint(x, y, s*boundary);
374
+ }
375
+ }
376
+ }
377
+ const worldGeometry = new THREE.BufferGeometry();
378
+ worldGeometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
379
+ worldGeometry.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));
380
+ const worldMaterial = new THREE.PointsMaterial({
381
+ size: 0.18,
382
+ vertexColors: true,
383
+ blending: THREE.AdditiveBlending,
384
+ depthWrite: false,
385
+ transparent: true,
386
+ opacity: 0.8,
387
+ sizeAttenuation: true
388
+ });
389
+ const worldPoints = new THREE.Points(worldGeometry, worldMaterial);
390
+ scene.add(worldPoints);
391
+
392
+ // --- GAME STATE ---
393
+ let gameActive = true;
394
+ let round = 1;
395
+ const maxRounds = 10;
396
+ let ghosts = [];
397
+ let enemyProjectiles = [];
398
+ let explosions = []; // for 3D death effect
399
+ let elapsedSeconds = 0;
400
+
401
+ const timerRoundDiv = document.getElementById('timer-round');
402
+ const ghostCountDiv = document.getElementById('ghost-count');
403
+ const victoryDiv = document.getElementById('victory');
404
+ const finalTimeSpan = document.getElementById('final-time');
405
+
406
+ // Weapon state: LMB auto-fire only (no RMB)
407
+ let lmbPressed = false;
408
+ let lastLMBShot = 0;
409
+ const LMB_COOLDOWN = 0.12; // auto-fire rate
410
+ const SHOTGUN_PELLETS = 3; // fewer pellets, tighter spread for precision
411
+ const SPREAD_ANGLE = 0.03; // very tight spread (almost precise)
412
+
413
+ // --- DATASET CAPTURE ---
414
+ let captures = []; // each: { blob, metadata }
415
+ let captureIndex = 0;
416
+ const captureCountSpan = document.getElementById('capture-count');
417
+ const exportBtn = document.getElementById('export-dataset');
418
+ const exportStatus = document.getElementById('export-status');
419
+
420
+ function updateCaptureUI() {
421
+ captureCountSpan.innerText = captures.length;
422
+ }
423
+
424
+ // Capture canvas as PNG blob with current metadata
425
+ function captureCurrentFrame(killCount) {
426
+ // Use renderer to get a data URL (preserveDrawingBuffer must be true)
427
+ renderer.render(scene, camera); // ensure latest frame (composer already renders, but we can force)
428
+ // Use toBlob on the canvas element
429
+ renderer.domElement.toBlob((blob) => {
430
+ if (!blob) return;
431
+ const metadata = {
432
+ index: captureIndex++,
433
+ timestamp: performance.now(),
434
+ round: round,
435
+ ghostsRemaining: ghosts.length,
436
+ killsThisShot: killCount || 0,
437
+ playerPos: {
438
+ x: controls.getObject().position.x,
439
+ z: controls.getObject().position.z
440
+ },
441
+ description: `Kill shot at round ${round}, ${ghosts.length} ghosts remain`
442
+ };
443
+ captures.push({ blob, metadata });
444
+ updateCaptureUI();
445
+ }, 'image/png');
446
+ }
447
+
448
+ // --- IMPROVED GHOST EXPLOSION (3D particle burst) ---
449
+ function createGhostExplosion(position) {
450
+ const count = 20 + Math.floor(Math.random() * 20);
451
+ const positions = [];
452
+ const colors = [];
453
+ const velocities = [];
454
+ for (let i = 0; i < count; i++) {
455
+ // random direction
456
+ const vel = new THREE.Vector3(
457
+ (Math.random() - 0.5) * 0.5,
458
+ (Math.random() - 0.5) * 0.5,
459
+ (Math.random() - 0.5) * 0.5
460
+ ).normalize().multiplyScalar(0.08 + Math.random() * 0.1);
461
+ velocities.push(vel);
462
+ positions.push(0, 0, 0); // relative to center
463
+ colors.push(1.0, 0.8 + Math.random()*0.2, 0.3 + Math.random()*0.3);
464
+ }
465
+ const geom = new THREE.BufferGeometry();
466
+ geom.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
467
+ geom.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));
468
+ const mat = new THREE.PointsMaterial({
469
+ size: 0.25,
470
+ vertexColors: true,
471
+ blending: THREE.AdditiveBlending,
472
+ depthWrite: false,
473
+ transparent: true,
474
+ opacity: 1.0,
475
+ sizeAttenuation: true
476
+ });
477
+ const points = new THREE.Points(geom, mat);
478
+ points.position.copy(position);
479
+ scene.add(points);
480
+ explosions.push({
481
+ mesh: points,
482
+ velocities: velocities,
483
+ life: 1.0, // seconds
484
+ age: 0
485
+ });
486
+ }
487
+
488
+ // --- HITSCAN FUNCTION (modified to capture only on kill) ---
489
+ function firePrecisionShot() {
490
+ const origin = camera.position.clone();
491
+ const baseDir = new THREE.Vector3();
492
+ camera.getWorldDirection(baseDir);
493
+
494
+ // compute local axes perpendicular to view direction
495
+ const right = new THREE.Vector3().crossVectors(baseDir, camera.up).normalize();
496
+ const up = new THREE.Vector3().crossVectors(right, baseDir).normalize();
497
+
498
+ let killedAny = false;
499
+ let killCount = 0;
500
+
501
+ for (let i = 0; i < SHOTGUN_PELLETS; i++) {
502
+ // very tight spread
503
+ const spreadX = (Math.random() - 0.5) * SPREAD_ANGLE * 2;
504
+ const spreadY = (Math.random() - 0.5) * SPREAD_ANGLE * 2;
505
+
506
+ const dir = baseDir.clone()
507
+ .addScaledVector(right, spreadX)
508
+ .addScaledVector(up, spreadY)
509
+ .normalize();
510
+
511
+ let bestHit = null;
512
+ let bestT = Infinity;
513
+
514
+ for (let j = 0; j < ghosts.length; j++) {
515
+ const ghost = ghosts[j];
516
+ const toGhost = new THREE.Vector3().subVectors(ghost.position, origin);
517
+
518
+ const t = toGhost.dot(dir);
519
+ if (t < 0) continue;
520
+ if (t > 45) continue;
521
+
522
+ const toGhostLenSq = toGhost.lengthSq();
523
+ const perpDistSq = Math.max(0, toGhostLenSq - t * t);
524
+ const ghostRadius = ghost.userData.hitRadius || 2.5;
525
+
526
+ if (perpDistSq < ghostRadius * ghostRadius) {
527
+ if (t < bestT) {
528
+ bestT = t;
529
+ bestHit = ghost;
530
+ }
531
+ }
532
+ }
533
+
534
+ if (bestHit) {
535
+ // Remove ghost
536
+ scene.remove(bestHit);
537
+ const idx = ghosts.indexOf(bestHit);
538
+ if (idx !== -1) ghosts.splice(idx, 1);
539
+
540
+ // Create explosion effect at ghost position
541
+ createGhostExplosion(bestHit.position.clone());
542
+
543
+ // Show screen hit effect (2D)
544
+ showHitEffect(bestHit.position.clone());
545
+
546
+ killedAny = true;
547
+ killCount++;
548
+ }
549
+ }
550
+
551
+ // Screen flash for any kill
552
+ if (killedAny) {
553
+ const flash = document.createElement('div');
554
+ flash.className = 'kill-flash';
555
+ document.body.appendChild(flash);
556
+ setTimeout(() => flash.remove(), 100);
557
+
558
+ // --- CAPTURE ONLY ON KILL ---
559
+ captureCurrentFrame(killCount);
560
+ }
561
+ }
562
+
563
+ // --- VISUAL EFFECTS (2D screen hit marker) ---
564
+ function showHitEffect(worldPos) {
565
+ const ndc = worldPos.clone().project(camera);
566
+ if (Math.abs(ndc.x) <= 1 && Math.abs(ndc.y) <= 1 && ndc.z <= 1) {
567
+ const screenX = (ndc.x * 0.5 + 0.5) * window.innerWidth;
568
+ const screenY = (-ndc.y * 0.5 + 0.5) * window.innerHeight;
569
+
570
+ const div = document.createElement('div');
571
+ div.className = 'hit-effect';
572
+ div.style.left = screenX + 'px';
573
+ div.style.top = screenY + 'px';
574
+ document.body.appendChild(div);
575
+ setTimeout(() => div.remove(), 200);
576
+ }
577
+ }
578
+
579
+ // --- MOUSE EVENTS: only LMB auto-fire, RMB removed ---
580
+ document.addEventListener('mousedown', (e) => {
581
+ if (!controls.isLocked || !gameActive) return;
582
+ e.preventDefault();
583
+ if (e.button === 0) {
584
+ lmbPressed = true;
585
+ }
586
+ // ignore button 2 (RMB)
587
+ });
588
+
589
+ document.addEventListener('mouseup', (e) => {
590
+ if (e.button === 0) {
591
+ lmbPressed = false;
592
+ }
593
+ });
594
+
595
+ document.addEventListener('contextmenu', (e) => e.preventDefault());
596
+
597
+ // --- GHOST CREATION (same) ---
598
+ function createGhost(pos, roundNum) {
599
+ const pointCount = 60 + Math.floor(Math.random() * 30);
600
+ const positions = [];
601
+ const colors = [];
602
+ const visualRadius = 1.2 + roundNum * 0.2;
603
+ const hitRadius = visualRadius * 2.0;
604
+ for (let i = 0; i < pointCount; i++) {
605
+ const r = visualRadius * Math.pow(Math.random(), 0.7);
606
+ const theta = Math.random() * Math.PI * 2;
607
+ const phi = Math.acos(2 * Math.random() - 1);
608
+ positions.push(
609
+ r * Math.sin(phi) * Math.cos(theta),
610
+ r * Math.sin(phi) * Math.sin(theta),
611
+ r * Math.cos(phi)
612
+ );
613
+ colors.push(0.7+0.3*Math.random(), 0.8+0.2*Math.random(), 1.0);
614
+ }
615
+ const geom = new THREE.BufferGeometry();
616
+ geom.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
617
+ geom.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));
618
+ const mat = new THREE.PointsMaterial({
619
+ size: 0.2,
620
+ vertexColors: true,
621
+ blending: THREE.AdditiveBlending,
622
+ depthWrite: false,
623
+ sizeAttenuation: true,
624
+ transparent: true,
625
+ opacity: 0.95
626
+ });
627
+ const points = new THREE.Points(geom, mat);
628
+ points.position.copy(pos);
629
+ points.userData = {
630
+ visualRadius: visualRadius,
631
+ hitRadius: hitRadius,
632
+ shootInterval: 1.0 + Math.random() * 1.2,
633
+ lastShot: performance.now() / 1000,
634
+ baseY: pos.y,
635
+ timeOffset: Math.random() * 100,
636
+ rotSpeed: 0.002 + Math.random() * 0.004
637
+ };
638
+ scene.add(points);
639
+ return points;
640
+ }
641
+
642
+ function spawnRound(roundNum) {
643
+ const count = roundNum * 2;
644
+ for (let i = 0; i < count; i++) {
645
+ let x, z;
646
+ do {
647
+ x = (Math.random() - 0.5) * 30;
648
+ z = (Math.random() - 0.5) * 30;
649
+ } while (Math.sqrt(x*x + z*z) < 5);
650
+ const y = 2.0 + Math.random() * 6;
651
+ ghosts.push(createGhost(new THREE.Vector3(x, y, z), roundNum));
652
+ }
653
+ updateUI();
654
+ }
655
+
656
+ function updateUI() {
657
+ const mins = Math.floor(elapsedSeconds / 60);
658
+ const secs = Math.floor(elapsedSeconds % 60);
659
+ timerRoundDiv.innerText = `TIME ${mins.toString().padStart(2,'0')}:${secs.toString().padStart(2,'0')} ROUND ${round}/${maxRounds}`;
660
+ ghostCountDiv.innerText = `GHOSTS ${ghosts.length}`;
661
+ }
662
+
663
+ function nextRound() {
664
+ if (round < maxRounds) {
665
+ round++;
666
+ spawnRound(round);
667
+ } else {
668
+ gameActive = false;
669
+ controls.unlock();
670
+ victoryDiv.style.display = 'block';
671
+ const mins = Math.floor(elapsedSeconds / 60);
672
+ const secs = Math.floor(elapsedSeconds % 60);
673
+ finalTimeSpan.innerText = `TIME: ${mins.toString().padStart(2,'0')}:${secs.toString().padStart(2,'0')}`;
674
+ }
675
+ }
676
+
677
+ // --- Enemy projectiles (cosmetic) ---
678
+ function createEnemyProjectile(position, direction) {
679
+ const count = 12;
680
+ const positions = [];
681
+ const colors = [];
682
+ const radius = 0.6;
683
+ for (let i = 0; i < count; i++) {
684
+ const r = radius * (0.7 + 0.3 * Math.random());
685
+ const theta = Math.random() * Math.PI * 2;
686
+ const phi = Math.acos(2 * Math.random() - 1);
687
+ positions.push(
688
+ r * Math.sin(phi) * Math.cos(theta),
689
+ r * Math.sin(phi) * Math.sin(theta),
690
+ r * Math.cos(phi)
691
+ );
692
+ colors.push(1.0, 0.3 + 0.7*Math.random(), 0.0);
693
+ }
694
+ const geom = new THREE.BufferGeometry();
695
+ geom.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
696
+ geom.setAttribute('color', new THREE.Float32BufferAttribute(colors, 3));
697
+ const mat = new THREE.PointsMaterial({
698
+ size: 0.3,
699
+ vertexColors: true,
700
+ blending: THREE.AdditiveBlending,
701
+ depthWrite: false,
702
+ sizeAttenuation: true
703
+ });
704
+ const points = new THREE.Points(geom, mat);
705
+ points.position.copy(position);
706
+ points.userData = {
707
+ velocity: direction.clone().multiplyScalar(1.5),
708
+ life: 2.5
709
+ };
710
+ scene.add(points);
711
+ return points;
712
+ }
713
+
714
+ // --- EXPORT DATASET (ZIP) ---
715
+ async function exportDataset() {
716
+ if (captures.length === 0) {
717
+ exportStatus.innerText = 'No captures yet!';
718
+ setTimeout(() => { exportStatus.innerText = ''; }, 2000);
719
+ return;
720
+ }
721
+
722
+ exportStatus.innerText = 'Building ZIP...';
723
+ const zip = new JSZip();
724
+
725
+ // Add images and metadata
726
+ const imgFolder = zip.folder('images');
727
+ const metadataList = [];
728
+
729
+ for (let i = 0; i < captures.length; i++) {
730
+ const cap = captures[i];
731
+ const filename = `frame_${String(i).padStart(4, '0')}.png`;
732
+ imgFolder.file(filename, cap.blob);
733
+ metadataList.push({
734
+ ...cap.metadata,
735
+ filename: filename
736
+ });
737
+ }
738
+
739
+ // Add metadata.json
740
+ zip.file('metadata.json', JSON.stringify(metadataList, null, 2));
741
+
742
+ // Add README.md for Hugging Face
743
+ const readme = `# Ghost Hunter RLHF Dataset (Precision Auto)
744
+
745
+ This dataset contains screenshots captured during gameplay of "Ghost Hunter" (8-bit FPS). Each image corresponds to a moment when the player successfully destroyed a ghost with the precision auto-fire. The dataset is intended for reinforcement learning from human feedback (RLHF) tasks, such as training a preference model to distinguish between "good" and "bad" shots.
746
+
747
+ ## Dataset Structure
748
+
749
+ - \`images/\`: PNG frames captured at the moment of a kill.
750
+ - \`metadata.json\`: JSON array with per-frame metadata including round number, ghosts remaining, player position, kills in that shot, and timestamp.
751
+
752
+ ## Stats
753
+
754
+ - Total captures: ${captures.length}
755
+ - Rounds covered: ${new Set(metadataList.map(m => m.round)).size}
756
+ - Time span: ${elapsedSeconds.toFixed(1)} seconds
757
+
758
+ ## Usage
759
+
760
+ Use this dataset to fine-tune vision-language models or as a reward model input for RLHF. Each image can be paired with the question: "Is this a good aim?" or similar.
761
+
762
+ ## License
763
+
764
+ CC0 (public domain) - feel free to use for any purpose.
765
+ `;
766
+ zip.file('README.md', readme);
767
+
768
+ // Generate zip and trigger download
769
+ const content = await zip.generateAsync({ type: 'blob' });
770
+ const url = URL.createObjectURL(content);
771
+ const a = document.createElement('a');
772
+ a.href = url;
773
+ a.download = `ghost_hunter_dataset_${new Date().toISOString().slice(0,10)}.zip`;
774
+ a.click();
775
+ URL.revokeObjectURL(url);
776
+
777
+ exportStatus.innerText = `Exported ${captures.length} captures.`;
778
+ setTimeout(() => { exportStatus.innerText = ''; }, 3000);
779
+ }
780
+
781
+ exportBtn.addEventListener('click', exportDataset);
782
+
783
+ // Initial spawn
784
+ spawnRound(1);
785
+
786
+ // --- ANIMATION LOOP ---
787
+ const clock = new THREE.Clock();
788
+ function animate() {
789
+ const delta = Math.min(clock.getDelta(), 0.1);
790
+ const now = performance.now() / 1000;
791
+
792
+ if (gameActive) {
793
+ elapsedSeconds += delta;
794
+ updateUI();
795
+
796
+ // Movement (A left, D right)
797
+ if (controls.isLocked) {
798
+ const moveDir = new THREE.Vector3();
799
+ if (keyState.w) moveDir.z = 1; // forward
800
+ if (keyState.s) moveDir.z = -1; // backward
801
+ if (keyState.a) moveDir.x = -1; // left
802
+ if (keyState.d) moveDir.x = 1; // right
803
+ if (moveDir.length() > 0) moveDir.normalize();
804
+
805
+ const cameraDir = new THREE.Vector3();
806
+ camera.getWorldDirection(cameraDir);
807
+ cameraDir.y = 0;
808
+ cameraDir.normalize();
809
+ const right = new THREE.Vector3().crossVectors(cameraDir, new THREE.Vector3(0,1,0)).normalize();
810
+
811
+ const moveWorld = new THREE.Vector3();
812
+ if (keyState.w || keyState.s) moveWorld.addScaledVector(cameraDir, moveDir.z);
813
+ if (keyState.a || keyState.d) moveWorld.addScaledVector(right, moveDir.x);
814
+
815
+ velocity.lerp(moveWorld.multiplyScalar(moveSpeed), 0.2);
816
+ const pos = controls.getObject().position;
817
+ pos.x += velocity.x;
818
+ pos.z += velocity.z;
819
+ if (Math.abs(pos.x) > boundary) pos.x = boundary * Math.sign(pos.x);
820
+ if (Math.abs(pos.z) > boundary) pos.z = boundary * Math.sign(pos.z);
821
+ velocity.multiplyScalar(damping);
822
+ }
823
+
824
+ // LMB auto-fire
825
+ if (lmbPressed && (now - lastLMBShot) > LMB_COOLDOWN) {
826
+ firePrecisionShot();
827
+ lastLMBShot = now;
828
+ }
829
+
830
+ // Ghost shooting (cosmetic)
831
+ ghosts.forEach(ghost => {
832
+ if (now - ghost.userData.lastShot > ghost.userData.shootInterval) {
833
+ ghost.userData.lastShot = now;
834
+ const dir = new THREE.Vector3().subVectors(camera.position, ghost.position).normalize();
835
+ enemyProjectiles.push(createEnemyProjectile(ghost.position.clone(), dir));
836
+ }
837
+ ghost.position.y = ghost.userData.baseY + Math.sin(now * 2 + ghost.userData.timeOffset) * 0.3;
838
+ ghost.rotation.y += ghost.userData.rotSpeed;
839
+ });
840
+
841
+ // Projectile movement
842
+ for (let i = enemyProjectiles.length - 1; i >= 0; i--) {
843
+ const proj = enemyProjectiles[i];
844
+ proj.position.addScaledVector(proj.userData.velocity, delta * 20);
845
+ proj.userData.life -= delta;
846
+ if (proj.userData.life <= 0) {
847
+ scene.remove(proj);
848
+ enemyProjectiles.splice(i, 1);
849
+ proj.geometry.dispose();
850
+ proj.material.dispose();
851
+ }
852
+ }
853
+
854
+ // Update explosions (death effects)
855
+ for (let i = explosions.length - 1; i >= 0; i--) {
856
+ const exp = explosions[i];
857
+ exp.age += delta;
858
+ if (exp.age >= exp.life) {
859
+ scene.remove(exp.mesh);
860
+ exp.mesh.geometry.dispose();
861
+ exp.mesh.material.dispose();
862
+ explosions.splice(i, 1);
863
+ continue;
864
+ }
865
+ // animate particles outward
866
+ const positions = exp.mesh.geometry.attributes.position.array;
867
+ const vel = exp.velocities;
868
+ for (let j = 0; j < positions.length / 3; j++) {
869
+ positions[j*3] += vel[j].x * delta * 15; // speed factor
870
+ positions[j*3+1] += vel[j].y * delta * 15;
871
+ positions[j*3+2] += vel[j].z * delta * 15;
872
+ }
873
+ exp.mesh.geometry.attributes.position.needsUpdate = true;
874
+ exp.mesh.material.opacity = 1.0 - exp.age / exp.life;
875
+ }
876
+
877
+ // Round transition
878
+ if (ghosts.length === 0 && gameActive) {
879
+ nextRound();
880
+ }
881
+ } else {
882
+ ghosts.forEach(g => g.rotation.y += 0.002);
883
+ }
884
+
885
+ worldMaterial.size = 0.16 + 0.02 * Math.sin(now * 6);
886
+
887
+ composer.render();
888
+ requestAnimationFrame(animate);
889
+ }
890
+ animate();
891
+
892
+ window.addEventListener('resize', () => {
893
+ camera.aspect = window.innerWidth / window.innerHeight;
894
+ camera.updateProjectionMatrix();
895
+ renderer.setSize(window.innerWidth, window.innerHeight);
896
+ composer.setSize(window.innerWidth, window.innerHeight);
897
+ });
898
+ </script>
899
+ </body>
900
+ </html>