-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStarLair.html
More file actions
390 lines (361 loc) · 12.6 KB
/
StarLair.html
File metadata and controls
390 lines (361 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Infinite 6DOF StarLair - Desktop + Mobile</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<style>
/* ---------- BODY ---------- */
body {
margin: 0;
overflow: hidden;
background: black;
font-family: sans-serif;
color: white;
cursor: none;
touch-action: none;
}
/* ---------- HUD ---------- */
#scoreDisplay, #qteDisplay {
position: absolute;
font-size: 18px;
z-index: 1000;
}
#scoreDisplay { top: 20px; left: 20px; }
#qteDisplay { top: 20px; right: 20px; }
/* ---------- SCENE ---------- */
#sceneContainer {
position: absolute;
width: 100%;
height: 100%;
overflow: hidden;
transform-style: preserve-3d;
}
/* Objects & stars */
.object, .trail, .star {
position: absolute;
border-radius: 50%;
transform-origin: center center;
}
.object {
filter: drop-shadow(0 0 15px rgba(255,255,255,0.8)) contrast(1.3) brightness(1.5);
transition: transform 0.1s linear;
}
.trail {
filter: blur(3px) brightness(1.2);
opacity: 0.4;
}
.star {
filter: blur(1.5px) brightness(1.2);
}
/* ---------- OVERLAYS ---------- */
#mouseOverlay, #epilepsyOverlay {
display: none;
position: fixed;
top: 0; left: 0;
width: 100%; height: 100%;
text-align: center;
z-index: 9999;
cursor: pointer;
}
#mouseOverlay {
background: rgba(0,0,0,0.9);
color: white;
font-size: 32px;
line-height: 100vh;
}
#epilepsyOverlay {
display: flex;
justify-content: center;
align-items: center;
background: black;
color: red;
font-size: 36px;
flex-direction: column;
}
#epilepsyOverlay span {
font-size: 24px;
margin-top: 20px;
color: white;
}
/* ---------- NEBULA ---------- */
canvas#nebulaCanvas {
position: absolute;
top: 0; left: 0;
width: 100%; height: 100%;
z-index: -1;
}
/* ---------- MOBILE CONTROLS ---------- */
#mobileControls {
position: absolute;
bottom: 10px;
left: 0; right: 0;
display: flex;
justify-content: space-around;
z-index: 1000;
flex-wrap: wrap;
font-size: calc(12px + 1vw);
}
.button {
padding: calc(8px + 1vw) calc(12px + 1vw);
border-radius: calc(5px + 0.5vw);
margin: 3px;
background: rgba(255,255,255,0.1);
color: white;
user-select: none;
touch-action: none;
}
#joystick {
position: absolute;
bottom: 80px;
left: 20px;
width: calc(80px + 10vw);
height: calc(80px + 10vw);
border-radius: 50%;
display: none;
}
#joystickKnob {
width: calc(30px + 4vw);
height: calc(30px + 4vw);
left: 50%; top: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
background: rgba(255,255,255,0.5);
}
/* ---------- HIDE MOBILE ON DESKTOP ---------- */
body.touch #mobileControls, body.touch #joystick { display: flex; display: block; }
</style>
<script>
// ---------- TOUCH DETECTION ----------
if ('ontouchstart' in window || navigator.maxTouchPoints > 0) {
document.body.classList.add('touch');
}
</script>
</head>
<body>
<!-- HUD -->
<div id="scoreDisplay">Score: 0</div>
<div id="qteDisplay">QTE: -</div>
<!-- Scene & Overlays -->
<div id="sceneContainer"></div>
<canvas id="nebulaCanvas"></canvas>
<div id="mouseOverlay">Mouse left the screen! Click to resume.</div>
<div id="epilepsyOverlay">
⚠️ Epilepsy Warning! ⚠️
<span>Flashing lights may be present. Click anywhere to start.</span>
</div>
<!-- Mobile Controls -->
<div id="mobileControls">
<div class="button" data-key="w">Forward</div>
<div class="button" data-key="s">Backward</div>
<div class="button" data-key="a">Strafe Left</div>
<div class="button" data-key="d">Strafe Right</div>
<div class="button" data-key="space">Up</div>
<div class="button" data-key="shift">Down</div>
<div class="button" data-key="q">Roll Left</div>
<div class="button" data-key="e">Roll Right</div>
</div>
<div id="joystick"><div id="joystickKnob"></div></div>
<script>
// ---------- GAME STATE ----------
let score = 0, paused = true;
const QTE_CHOICES = [
{action:"FORWARD", key:"w"}, {action:"BACKWARD", key:"s"},
{action:"STRAFE LEFT", key:"a"}, {action:"STRAFE RIGHT", key:"d"},
{action:"UP", key:" "}, {action:"DOWN", key:"Shift"},
{action:"ROLL LEFT", key:"q"}, {action:"ROLL RIGHT", key:"e"}
];
let activeQTE = null;
let sceneColors = { object1:"#FFAA00", object2:"#00FFFF", nebula:[] };
// ---------- CAMERA ----------
let camera = { x:0, y:0, z:0, pitch:0, yaw:0, roll:0, speed:5 };
let keys = { w:0, s:0, a:0, d:0, space:0, shift:0, q:0, e:0 };
let mouse = { dx:0, dy:0 };
// ---------- DESKTOP INPUT ----------
document.addEventListener('keydown', e=>{
if(paused) return;
if(e.code==='KeyW') keys.w=1; if(e.code==='KeyS') keys.s=1;
if(e.code==='KeyA') keys.a=1; if(e.code==='KeyD') keys.d=1;
if(e.code==='Space') keys.space=1; if(e.code==='ShiftLeft') keys.shift=1;
if(e.code==='KeyQ') keys.q=1; if(e.code==='KeyE') keys.e=1;
if(activeQTE && keys[activeQTE.key]) handleQTE(true);
});
document.addEventListener('keyup', e=>{
if(e.code==='KeyW') keys.w=0; if(e.code==='KeyS') keys.s=0;
if(e.code==='KeyA') keys.a=0; if(e.code==='KeyD') keys.d=0;
if(e.code==='Space') keys.space=0; if(e.code==='ShiftLeft') keys.shift=0;
if(e.code==='KeyQ') keys.q=0; if(e.code==='KeyE') keys.e=0;
});
document.body.addEventListener('mousemove', e=>{ if(!paused){ mouse.dx=e.movementX*0.003; mouse.dy=e.movementY*0.003; } });
document.body.addEventListener('click', ()=>document.body.requestPointerLock());
// ---------- TOUCH BUTTONS ----------
document.querySelectorAll('.button').forEach(btn=>{
btn.addEventListener('touchstart', e=>{ e.preventDefault(); keys[btn.dataset.key]=1; });
btn.addEventListener('touchend', e=>{ e.preventDefault(); keys[btn.dataset.key]=0; });
});
// ---------- JOYSTICK ----------
const joystick = document.getElementById('joystick'), knob = document.getElementById('joystickKnob');
let joystickData = {x:0, y:0, active:false};
knob.addEventListener('touchstart', ()=>{ joystickData.active=true; });
knob.addEventListener('touchend', ()=>{
joystickData.active=false; keys.w=0; keys.s=0; keys.a=0; keys.d=0;
knob.style.left='35px'; knob.style.top='35px';
});
knob.addEventListener('touchmove', e=>{
if(!joystickData.active) return;
const touch = e.touches[0];
const rect = joystick.getBoundingClientRect();
let x = touch.clientX-rect.left-60;
let y = touch.clientY-rect.top-60;
let max = 50, dist = Math.sqrt(x*x + y*y);
if(dist>max){ x = x*max/dist; y=y*max/dist; }
knob.style.left = 35+x+'px'; knob.style.top = 35+y+'px';
keys.w = y<-10?1:0; keys.s = y>10?1:0;
keys.a = x<-10?1:0; keys.d = x>10?1:0;
});
// ---------- SWIPE LOOK ----------
let touchLook = { active:false, lastX:0, lastY:0 };
document.addEventListener('touchstart', e=>{
if(e.touches.length===1 && e.target.id!=='joystickKnob' && !e.target.classList.contains('button')){
touchLook.active=true;
touchLook.lastX=e.touches[0].clientX;
touchLook.lastY=e.touches[0].clientY;
}
});
document.addEventListener('touchmove', e=>{
if(!touchLook.active) return;
let dx=e.touches[0].clientX-touchLook.lastX;
let dy=e.touches[0].clientY-touchLook.lastY;
mouse.dx=dx*0.005; mouse.dy=dy*0.005;
touchLook.lastX=e.touches[0].clientX; touchLook.lastY=e.touches[0].clientY;
});
document.addEventListener('touchend', ()=>{ touchLook.active=false; });
// ---------- OVERLAYS ----------
const overlay = document.getElementById("mouseOverlay"), epilepsyOverlay = document.getElementById("epilepsyOverlay");
overlay.addEventListener('click', ()=>{ paused=false; overlay.style.display='none'; epilepsyOverlay.style.display='none'; });
epilepsyOverlay.addEventListener('click', ()=>{ paused=false; epilepsyOverlay.style.display='none'; });
// ---------- STARFIELD ----------
let stars = [];
function generateStars(count=200){
stars = [];
for(let i=0;i<count;i++) stars.push({
x:(Math.random()-0.5)*3000,
y:(Math.random()-0.5)*3000,
z:(Math.random()-0.5)*3000,
size: Math.random()*2+1,
color: `hsl(${Math.random()*360},60%,80%)`
});
}
// ---------- SCENE ----------
let objects = [];
function randomColor(){ return `hsl(${Math.random()*360},70%,60%)`; }
function generateScene(){
objects=[]; sceneColors.object1=randomColor(); sceneColors.object2=randomColor(); sceneColors.nebula=[];
for(let i=0;i<50;i++) sceneColors.nebula.push(`hsla(${Math.random()*360},60%,40%,0.1)`);
for(let i=0;i<70;i++) objects.push({x:(Math.random()-0.5)*2000, y:(Math.random()-0.5)*2000, z:(Math.random()-0.5)*2000, size:Math.random()*40+15, color:Math.random()<0.5?sceneColors.object1:sceneColors.object2});
activeQTE=QTE_CHOICES[Math.floor(Math.random()*QTE_CHOICES.length)];
document.getElementById("qteDisplay").innerText="QTE: "+activeQTE.action;
}
// ---------- QTE ----------
function handleQTE(success){
if(success) score++;
document.getElementById("scoreDisplay").innerText="Score: "+score;
generateScene();
}
// ---------- NEBULA ----------
const nebulaCanvas = document.getElementById("nebulaCanvas"), nebCtx = nebulaCanvas.getContext("2d");
nebulaCanvas.width = window.innerWidth; nebulaCanvas.height = window.innerHeight;
let nebulaParticles=[];
function generateNebulaParticles(){
nebulaParticles=[];
for(let i=0;i<sceneColors.nebula.length;i++){
nebulaParticles.push({
x: Math.random()*window.innerWidth,
y: Math.random()*window.innerHeight,
radius: Math.random()*100+50,
color: sceneColors.nebula[i],
dx: (Math.random()-0.5)*0.2,
dy: (Math.random()-0.5)*0.2
});
}
}
function renderNebula(){
nebCtx.clearRect(0,0,nebulaCanvas.width,nebulaCanvas.height);
nebulaParticles.forEach(p=>{
let grd = nebCtx.createRadialGradient(p.x,p.y,p.radius*0.2,p.x,p.y,p.radius);
grd.addColorStop(0,p.color); grd.addColorStop(1,'rgba(0,0,0,0)');
nebCtx.fillStyle=grd; nebCtx.fill();
p.x+=p.dx; p.y+=p.dy;
if(p.x<0)p.x=window.innerWidth; if(p.x>window.innerWidth)p.x=0;
if(p.y<0)p.y=window.innerHeight; if(p.y>window.innerHeight)p.y=0;
});
}
// ---------- UPDATE ----------
function update(){
if(paused) return;
let forward=keys.w-keys.s, right=keys.d-keys.a, up=keys.space-keys.shift;
camera.x += forward*Math.sin(camera.yaw)*camera.speed + right*Math.cos(camera.yaw)*camera.speed;
camera.z += forward*Math.cos(camera.yaw)*camera.speed - right*Math.sin(camera.yaw)*camera.speed;
camera.y += up*camera.speed;
camera.yaw += mouse.dx; camera.pitch -= mouse.dy;
mouse.dx=0; mouse.dy=0;
camera.roll += (keys.q-keys.e)*0.02;
}
// ---------- RENDER ----------
function renderScene(){
const container=document.getElementById("sceneContainer");
container.innerHTML="";
const cosPitch=Math.cos(camera.pitch), sinPitch=Math.sin(camera.pitch);
const cosYaw=Math.cos(camera.yaw), sinYaw=Math.sin(camera.yaw);
const cosRoll=Math.cos(camera.roll), sinRoll=Math.sin(camera.roll);
// Stars
stars.forEach(s=>{
let dx=s.x-camera.x, dy=s.y-camera.y, dz=s.z-camera.z;
let x1=dx*cosYaw - dz*sinYaw, z1=dx*sinYaw + dz*cosYaw, y1=dy;
let y2=y1*cosPitch - z1*sinPitch, z2=y1*sinPitch + z1*cosPitch, x2=x1;
let x3=x2*cosRoll - y2*sinRoll, y3=x2*sinRoll + y2*cosRoll, z3=z2;
let scale=800/(800+z3), left=window.innerWidth/2 + x3*scale, top=window.innerHeight/2 + y3*scale;
const div=document.createElement("div");
div.className="star"; div.style.width=div.style.height=s.size+"px";
div.style.left=left+"px"; div.style.top=top+"px"; div.style.backgroundColor=s.color;
container.appendChild(div);
});
// Objects
objects.forEach(obj=>{
let dx=obj.x-camera.x, dy=obj.y-camera.y, dz=obj.z-camera.z;
let x1=dx*cosYaw-dz*sinYaw, z1=dx*sinYaw+dz*cosYaw, y1=dy;
let y2=y1*cosPitch-z1*sinPitch, z2=y1*sinPitch+z1*cosPitch, x2=x1;
let x3=x2*cosRoll-y2*sinRoll, y3=x2*sinRoll+y2*cosRoll, z3=z2;
let scale=800/(800+z3);
let left=window.innerWidth/2 + x3*scale - obj.size/2;
let top=window.innerHeight/2 + y3*scale - obj.size/2;
const div=document.createElement("div");
div.className="object"; div.style.width=div.style.height=obj.size+"px";
div.style.left=left+"px"; div.style.top=top+"px";
div.style.backgroundImage=`radial-gradient(circle at 30% 30%, rgba(255,255,255,0.9), ${obj.color})`;
container.appendChild(div);
const trail=div.cloneNode(true); trail.classList.add("trail"); container.appendChild(trail);
});
}
// ---------- LOOP ----------
function loop(){ update(); renderNebula(); renderScene(); requestAnimationFrame(loop); }
// ---------- START ----------
generateStars(); generateScene(); generateNebulaParticles(); loop();
// ---------- RESIZE ----------
function resizeControls(){
const knob=document.getElementById('joystickKnob');
const joystick=document.getElementById('joystick');
const size=Math.min(window.innerWidth, window.innerHeight)*0.15;
joystick.style.width=joystick.style.height=size+'px';
knob.style.width=knob.style.height=(size*0.4)+'px';
knob.style.left=(size*0.3)+'px'; knob.style.top=(size*0.3)+'px';
}
window.addEventListener('resize', ()=>{
nebulaCanvas.width=window.innerWidth;
nebulaCanvas.height=window.innerHeight;
resizeControls();
});
resizeControls();
</script>
</body>
</html>