-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlumenfall.html
More file actions
1285 lines (1215 loc) · 50.2 KB
/
Copy pathlumenfall.html
File metadata and controls
1285 lines (1215 loc) · 50.2 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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<title>LUMENFALL</title>
<style>
:root { --gold:#ffd98a; --teal:#7fe7d6; }
* { margin:0; padding:0; box-sizing:border-box; }
html,body { height:100%; background:#05060c; overflow:hidden;
font-family:"Segoe UI",system-ui,sans-serif; color:#dfe7ff;
-webkit-user-select:none; user-select:none; touch-action:none; }
#wrap { position:fixed; inset:0; display:grid; place-items:center; }
canvas { display:block; image-rendering:auto;
box-shadow:0 0 120px rgba(20,30,60,.6); }
/* ---------- HUD ---------- */
#hud { position:fixed; inset:0; pointer-events:none; z-index:5;
font-variant-numeric:tabular-nums; }
.corner { position:absolute; padding:14px 18px; opacity:.92;
text-shadow:0 0 12px rgba(120,160,255,.5); }
#depthBox { top:0; left:0; }
#scoreBox { top:0; right:0; text-align:right; }
.label { font-size:11px; letter-spacing:3px; text-transform:uppercase;
color:#8fa0d0; }
.value { font-size:30px; font-weight:600; line-height:1.05;
background:linear-gradient(90deg,var(--gold),var(--teal));
-webkit-background-clip:text; background-clip:text; color:transparent; }
#echoBox { bottom:0; left:50%; transform:translateX(-50%);
text-align:center; }
.echo-dot { display:inline-block; width:10px; height:10px; margin:0 3px;
border-radius:50%; background:#2a3358; vertical-align:middle;
transition:all .3s; }
.echo-dot.on { background:var(--teal);
box-shadow:0 0 10px var(--teal),0 0 20px var(--teal); }
/* ---------- Overlays ---------- */
.screen { position:fixed; inset:0; z-index:10; display:flex;
flex-direction:column; align-items:center; justify-content:center;
text-align:center; background:radial-gradient(ellipse at center,
rgba(8,10,22,.55),rgba(3,4,10,.92)); backdrop-filter:blur(2px);
transition:opacity .6s; }
.screen.hide { opacity:0; pointer-events:none; }
h1 { font-size:clamp(46px,11vw,120px); font-weight:800; letter-spacing:14px;
margin-left:14px;
background:linear-gradient(120deg,#fff,var(--gold) 40%,var(--teal));
-webkit-background-clip:text; background-clip:text; color:transparent;
filter:drop-shadow(0 0 30px rgba(255,210,140,.35)); }
.tag { margin-top:8px; font-size:15px; letter-spacing:5px; color:#8fa0d0;
text-transform:uppercase; }
/* A button is clickable ONLY inside a screen that is actually visible.
Default off; each visible screen explicitly turns its own buttons on.
(#title hides via .hide; #gameOver and #shop show via .show.) */
#title:not(.hide) .btn,
#gameOver.show .btn,
#shop.show .btn { pointer-events:auto; }
.btn { pointer-events:none; margin-top:42px; padding:15px 46px;
font-size:16px; letter-spacing:4px; text-transform:uppercase;
color:#06121f; font-weight:700; cursor:pointer; border:none;
border-radius:40px;
background:linear-gradient(120deg,var(--gold),var(--teal));
box-shadow:0 0 40px rgba(127,231,214,.45); transition:transform .15s; }
.btn:hover { transform:scale(1.06); }
.hint { margin-top:34px; font-size:13px; letter-spacing:2px; color:#5f6c98;
line-height:2; max-width:440px; }
.hint b { color:#aeb9e6; font-weight:600; }
#finalStats { margin-top:26px; font-size:20px; color:#cdd6ff;
line-height:1.9; }
#finalStats span { color:var(--gold); font-weight:700; }
#gameOver { opacity:0; pointer-events:none; }
#gameOver.show { opacity:1; pointer-events:auto; }
/* biome label + combo */
#biome { margin-top:4px; font-size:13px; letter-spacing:3px; color:#9fb0e0;
text-transform:uppercase; opacity:.85; }
#combo { margin-top:2px; font-size:15px; font-weight:700; letter-spacing:1px;
color:var(--gold); min-height:18px; text-shadow:0 0 12px rgba(255,210,140,.6); }
/* biome transition banner */
#biomeBanner { position:fixed; top:38%; left:0; right:0; z-index:6;
text-align:center; pointer-events:none; opacity:0;
font-size:clamp(30px,6vw,64px); font-weight:800; letter-spacing:10px;
text-transform:uppercase; color:#fff;
filter:drop-shadow(0 0 30px rgba(160,200,255,.6)); }
#biomeBanner.show { animation:bannerFx 3.2s ease forwards; }
@keyframes bannerFx {
0%{opacity:0; transform:translateY(20px) scale(.96); letter-spacing:24px;}
18%{opacity:1; transform:translateY(0) scale(1); letter-spacing:10px;}
80%{opacity:1;} 100%{opacity:0; letter-spacing:14px;}
}
/* button rows + shop */
.btnrow { display:flex; gap:18px; flex-wrap:wrap; justify-content:center;
margin-top:38px; }
.btnrow .btn { margin-top:0; }
#shop { opacity:0; pointer-events:none; }
#shop.show { opacity:1; pointer-events:auto; }
#bank { margin-top:18px; font-size:22px; letter-spacing:2px; color:#ffe9bd;
text-shadow:0 0 16px rgba(255,210,140,.5); }
#bank span { font-weight:800; color:var(--gold); }
#shopGrid { display:grid; grid-template-columns:repeat(auto-fit,minmax(220px,260px));
gap:16px; margin-top:30px; max-width:860px; padding:0 16px; }
#shop.show .card { pointer-events:auto; }
.card { pointer-events:none; text-align:left; padding:16px 18px;
border-radius:16px; background:rgba(20,26,48,.62);
border:1px solid rgba(127,231,214,.18); cursor:pointer;
transition:transform .14s, border-color .14s, background .14s; }
.card:hover { transform:translateY(-3px); border-color:rgba(127,231,214,.5);
background:rgba(28,36,64,.8); }
.card.maxed { cursor:default; opacity:.6; border-color:rgba(255,210,140,.3); }
.card.cant { cursor:not-allowed; opacity:.5; }
.card .cn { font-size:16px; font-weight:700; color:#eaf1ff; }
.card .cd { font-size:12px; color:#9aa6cf; margin:6px 0 10px; line-height:1.5; }
.card .crow { display:flex; justify-content:space-between; align-items:center; }
.pips { display:flex; gap:4px; }
.pip { width:16px; height:5px; border-radius:3px; background:#2a3358; }
.pip.on { background:linear-gradient(90deg,var(--gold),var(--teal));
box-shadow:0 0 8px rgba(127,231,214,.6); }
.cost { font-size:13px; font-weight:700; color:var(--gold); }
.cost.maxed { color:var(--teal); }
#best { margin-top:20px; font-size:13px; letter-spacing:2px; color:#7b88b8; }
#best b { color:var(--gold); }
/* a charged echo dot glows gold (a stored boost) */
.echo-dot.charged { background:var(--gold);
box-shadow:0 0 10px var(--gold),0 0 22px rgba(255,200,100,.6);
animation:boostPulse 1.6s ease-in-out infinite; }
@keyframes boostPulse { 0%,100%{transform:scale(1);} 50%{transform:scale(1.35);} }
</style>
</head>
<body>
<div id="wrap"><canvas id="c"></canvas></div>
<div id="hud">
<div class="corner" id="depthBox">
<div class="label">Depth</div><div class="value" id="depth">0m</div>
<div id="biome">The Threshold</div>
</div>
<div class="corner" id="scoreBox">
<div class="label">Light</div><div class="value" id="score">0</div>
<div id="combo"></div>
</div>
<div class="corner" id="echoBox">
<div class="label" style="margin-bottom:7px">Echo Boost</div>
<div id="echoes"></div>
<div class="label" id="echoHint" style="margin-top:6px;font-size:10px;letter-spacing:1px;opacity:.7">flare to spend ▸</div>
</div>
</div>
<div id="biomeBanner"></div>
<div class="screen" id="title">
<h1>LUMENFALL</h1>
<div class="tag">a descent into living light</div>
<button class="btn" id="startBtn">Begin the Fall</button>
<div class="hint">
Steer with <b>← →</b> or <b>A / D</b> · <b>Mouse</b> to glide<br>
Hold <b>SPACE</b> / click to <b>flare</b> — burn brighter, push back the dark<br>
Gather <b>motes</b> · weave past <b>lasers</b> · flare through <b>gates</b><br>
Awaken <b>echoes</b> to bank <b>Echo Boosts</b> — when your flame runs dry,<br>
flaring spends one for a <b>supernova</b> that clears the dark<br>
Survive deeper · spend your light in <b>The Sanctum</b>
</div>
<div id="best"></div>
</div>
<div class="screen" id="gameOver">
<h1 style="font-size:clamp(38px,8vw,84px)">THE DARK</h1>
<div class="tag">your light scattered into the deep</div>
<div id="finalStats"></div>
<div class="btnrow">
<button class="btn" id="shopBtn">The Sanctum ⟡</button>
<button class="btn" id="againBtn">Fall Again</button>
</div>
</div>
<div class="screen" id="shop">
<h1 style="font-size:clamp(34px,7vw,72px)">THE SANCTUM</h1>
<div class="tag">spend your light · grow your flame</div>
<div id="bank">⟡ <span id="bankAmt">0</span> light</div>
<div id="shopGrid"></div>
<div class="btnrow">
<button class="btn" id="shopBackBtn">Return to the Edge</button>
</div>
</div>
<script>
"use strict";
/* ============================================================
LUMENFALL — a self-contained luminous descent
Hand-built: physics · particles · generative audio · lighting
============================================================ */
const canvas = document.getElementById('c');
const ctx = canvas.getContext('2d', { alpha:false });
let W=0, H=0, DPR=1;
function resize(){
DPR = Math.min(window.devicePixelRatio||1, 2);
W = window.innerWidth; H = window.innerHeight;
canvas.style.width = W+'px'; canvas.style.height = H+'px';
canvas.width = Math.floor(W*DPR); canvas.height = Math.floor(H*DPR);
ctx.setTransform(DPR,0,0,DPR,0,0);
}
window.addEventListener('resize', resize); resize();
/* ---------- utils ---------- */
const rand=(a,b)=>a+Math.random()*(b-a);
const randi=(a,b)=>Math.floor(rand(a,b+1));
const clamp=(v,a,b)=>v<a?a:v>b?b:v;
const lerp=(a,b,t)=>a+(b-a)*t;
const TAU=Math.PI*2;
function hsl(h,s,l,a=1){return `hsla(${h},${s}%,${l}%,${a})`;}
/* ============================================================
SAVE / PROGRESSION — persistent light bank & upgrades
============================================================ */
const SAVE_KEY='lumenfall.save.v1';
const UPGRADES=[
{ id:'radius', name:'Inner Light', icon:'◍',
desc:'Your glow reaches farther — see and push the dark sooner.',
max:5, cost:l=>120+l*180, val:l=>l*45 }, // +light radius
{ id:'energy', name:'Deep Reserve', icon:'⟁',
desc:'A larger flame. Flare longer before you run dry.',
max:5, cost:l=>140+l*200, val:l=>l*0.35 }, // +max energy
{ id:'regen', name:'Rekindle', icon:'⥁',
desc:'Energy returns faster between flares.',
max:4, cost:l=>160+l*220, val:l=>l*0.10 }, // +energy regen
{ id:'magnet', name:'Yearning', icon:'✷',
desc:'Motes drift toward your light, gathered from afar.',
max:4, cost:l=>150+l*210, val:l=>l*60 }, // mote pull radius
{ id:'shield', name:'Aegis Spark', icon:'❂',
desc:'Begin each fall shielded — survive one shadow without flaring.',
max:3, cost:l=>200+l*280, val:l=>l }, // # starting shields
{ id:'greed', name:'Avarice', icon:'⟡',
desc:'Every mote and echo yields more light.',
max:5, cost:l=>180+l*240, val:l=>l*0.20 }, // +score multiplier
];
let SAVE = loadSave();
function loadSave(){
try{ const s=JSON.parse(localStorage.getItem(SAVE_KEY));
if(s&&s.up) return { bank:s.bank|0, best:s.best|0, up:s.up }; }catch(e){}
const up={}; UPGRADES.forEach(u=>up[u.id]=0);
return { bank:0, best:0, up };
}
function persist(){ try{ localStorage.setItem(SAVE_KEY,JSON.stringify(SAVE)); }catch(e){} }
function upLvl(id){ return SAVE.up[id]||0; }
function upVal(id){ const u=UPGRADES.find(x=>x.id===id); return u.val(upLvl(id)); }
/* ============================================================
BIOMES — zones cycle by depth, each its own mood & rules
============================================================ */
const BIOMES=[
{ name:'The Threshold', hueA:230, hueB:260, fog:0.50, wallHue:250,
shadowMul:1.0, speedMul:1.0, light:1.0 },
{ name:'Crystal Reach', hueA:190, hueB:225, fog:0.42, wallHue:195,
shadowMul:0.9, speedMul:1.05, light:1.15 }, // bright, refractive
{ name:'The Hollows', hueA:265, hueB:290, fog:0.66, wallHue:280,
shadowMul:1.45, speedMul:1.1, light:0.85 }, // open, swarming dark
{ name:'Magma Veins', hueA:8, hueB:30, fog:0.40, wallHue:18,
shadowMul:1.15, speedMul:1.2, light:1.0 }, // hot, fast
{ name:'The Deep Choir',hueA:210, hueB:250, fog:0.80, wallHue:225,
shadowMul:1.3, speedMul:1.15, light:0.6 }, // near-blind, flares reveal
];
const BIOME_DEPTH=850; // metres per biome before cycling
function biomeAt(depth){
const i=Math.floor(depth/BIOME_DEPTH);
return { ...BIOMES[i%BIOMES.length],
tier:Math.floor(i/BIOMES.length), // loops add intensity
index:i };
}
/* ============================================================
AUDIO — generative ambient + reactive synth (Web Audio)
============================================================ */
const Audio = (()=>{
let ctxA=null, master=null, musicGain=null, started=false;
let droneTimers=[];
function init(){
if(ctxA) return;
ctxA = new (window.AudioContext||window.webkitAudioContext)();
master = ctxA.createGain(); master.gain.value=0.0;
master.connect(ctxA.destination);
musicGain = ctxA.createGain(); musicGain.gain.value=0.5;
// gentle reverb via convolver
const conv = ctxA.createConvolver();
const len = ctxA.sampleRate*2.4, buf = ctxA.createBuffer(2,len,ctxA.sampleRate);
for(let ch=0;ch<2;ch++){ const d=buf.getChannelData(ch);
for(let i=0;i<len;i++) d[i]=(Math.random()*2-1)*Math.pow(1-i/len,2.6); }
conv.buffer=buf;
const wet=ctxA.createGain(); wet.gain.value=0.32;
musicGain.connect(master); musicGain.connect(conv); conv.connect(wet); wet.connect(master);
}
function start(){
if(started) return; init();
if(ctxA.state==='suspended') ctxA.resume();
started=true;
master.gain.cancelScheduledValues(ctxA.currentTime);
master.gain.linearRampToValueAtTime(0.85, ctxA.currentTime+2);
drone();
}
// evolving pad chords
const SCALE=[0,3,5,7,10]; // minor pentatonic
const BASE=174.6; // F3-ish
function note(semi){ return BASE*Math.pow(2,semi/12); }
function pad(freq, t, dur){
const o1=ctxA.createOscillator(), o2=ctxA.createOscillator();
const g=ctxA.createGain(), f=ctxA.createBiquadFilter();
o1.type='sine'; o2.type='triangle';
o1.frequency.value=freq; o2.frequency.value=freq*1.5; o2.detune.value=4;
f.type='lowpass'; f.frequency.value=900; f.Q.value=2;
g.gain.value=0;
o1.connect(g); o2.connect(g); g.connect(f); f.connect(musicGain);
g.gain.setValueAtTime(0,t);
g.gain.linearRampToValueAtTime(0.10,t+dur*0.4);
g.gain.linearRampToValueAtTime(0.0001,t+dur);
f.frequency.linearRampToValueAtTime(1600,t+dur*0.5);
o1.start(t); o2.start(t); o1.stop(t+dur+0.1); o2.stop(t+dur+0.1);
}
function drone(){
if(!started) return;
const t=ctxA.currentTime, dur=rand(5,8);
const root=SCALE[randi(0,SCALE.length-1)];
[0,7,12].forEach((iv,i)=> pad(note(root+iv), t+i*0.05, dur));
if(Math.random()<0.5) pad(note(root+SCALE[randi(0,4)]+12), t+rand(1,3), dur*0.7);
droneTimers.push(setTimeout(drone, dur*1000*0.7));
}
// one-shot sparkle for pickups
function blip(semi, type='sine', vol=0.25){
if(!started) return;
const t=ctxA.currentTime;
const o=ctxA.createOscillator(), g=ctxA.createGain();
o.type=type; o.frequency.value=note(semi)*2;
o.connect(g); g.connect(musicGain);
g.gain.setValueAtTime(0,t);
g.gain.linearRampToValueAtTime(vol,t+0.01);
g.gain.exponentialRampToValueAtTime(0.0001,t+0.5);
o.frequency.exponentialRampToValueAtTime(note(semi)*4,t+0.3);
o.start(t); o.stop(t+0.55);
}
function chord(semis, vol=0.3){
semis.forEach((s,i)=>setTimeout(()=>blip(s,'triangle',vol),i*70));
}
function noise(vol=0.4,dur=0.6,lp=1200){ // shadow hit / death
if(!started) return;
const t=ctxA.currentTime, n=ctxA.createBufferSource();
const buf=ctxA.createBuffer(1,ctxA.sampleRate*dur,ctxA.sampleRate);
const d=buf.getChannelData(0);
for(let i=0;i<d.length;i++) d[i]=(Math.random()*2-1)*Math.pow(1-i/d.length,1.5);
n.buffer=buf;
const f=ctxA.createBiquadFilter(); f.type='lowpass'; f.frequency.value=lp;
const g=ctxA.createGain(); g.gain.value=vol;
g.gain.exponentialRampToValueAtTime(0.0001,t+dur);
n.connect(f); f.connect(g); g.connect(master);
n.start(t);
}
function setIntensity(x){ // 0..1 deepens the music
if(!started) return;
musicGain.gain.setTargetAtTime(0.4+0.35*x, ctxA.currentTime, 0.8);
}
return { start, blip, chord, noise, setIntensity,
get on(){return started;} };
})();
/* ============================================================
PARTICLES — pooled
============================================================ */
class Particle{
constructor(){ this.dead=true; }
spawn(x,y,vx,vy,life,size,hue,glow,grav=0){
this.x=x; this.y=y; this.vx=vx; this.vy=vy;
this.life=life; this.max=life; this.size=size; this.hue=hue;
this.glow=glow; this.grav=grav; this.dead=false; return this;
}
step(dt){
this.x+=this.vx*dt; this.y+=this.vy*dt;
this.vy+=this.grav*dt; this.vx*=0.99; this.vy*=0.99;
this.life-=dt; if(this.life<=0) this.dead=true;
}
}
const POOL=[]; for(let i=0;i<1400;i++) POOL.push(new Particle());
let poolIdx=0;
function emit(...a){
for(let n=0;n<1400;n++){
const p=POOL[poolIdx]; poolIdx=(poolIdx+1)%1400;
if(p.dead) return p.spawn(...a);
}
return POOL[poolIdx].spawn(...a);
}
/* ============================================================
WORLD ENTITIES
============================================================ */
let game; // current game state
class Mote{ // collectible light
constructor(x,y){ this.x=x; this.y=y; this.r=7; this.phase=rand(0,TAU);
this.hue=rand(40,55); this.dead=false; }
update(dt){ this.phase+=dt*3; }
draw(s){
const yy=this.y - s.camY;
const pulse=1+Math.sin(this.phase)*0.18;
const g=ctx.createRadialGradient(this.x,yy,0,this.x,yy,this.r*5*pulse);
g.addColorStop(0,hsl(this.hue,100,80,0.95));
g.addColorStop(0.3,hsl(this.hue,100,65,0.5));
g.addColorStop(1,hsl(this.hue,100,60,0));
ctx.fillStyle=g;
ctx.beginPath(); ctx.arc(this.x,yy,this.r*5*pulse,0,TAU); ctx.fill();
ctx.fillStyle=hsl(this.hue,100,92,1);
ctx.beginPath(); ctx.arc(this.x,yy,this.r*0.6*pulse,0,TAU); ctx.fill();
}
}
class Echo{ // big rare collectible — awakens an echo
constructor(x,y){ this.x=x; this.y=y; this.r=20; this.phase=rand(0,TAU);
this.dead=false; this.ring=0; }
update(dt){ this.phase+=dt*1.6; this.ring+=dt; }
draw(s){
const yy=this.y - s.camY;
const pulse=1+Math.sin(this.phase)*0.12;
// rotating rings
for(let k=0;k<3;k++){
const rr=this.r*(1.6+k*0.7)+Math.sin(this.ring*2+k)*6;
ctx.strokeStyle=hsl(170-k*20,90,70,0.45-k*0.1);
ctx.lineWidth=2;
ctx.beginPath();
for(let a=0;a<TAU;a+=0.25){
const wob=1+Math.sin(a*5+this.ring*3+k)*0.08;
const px=this.x+Math.cos(a+this.phase*(k+1))*rr*wob;
const py=yy+Math.sin(a+this.phase*(k+1))*rr*wob;
a===0?ctx.moveTo(px,py):ctx.lineTo(px,py);
}
ctx.closePath(); ctx.stroke();
}
const g=ctx.createRadialGradient(this.x,yy,0,this.x,yy,this.r*3*pulse);
g.addColorStop(0,hsl(165,100,85,0.95));
g.addColorStop(0.4,hsl(175,100,60,0.4));
g.addColorStop(1,hsl(180,100,50,0));
ctx.fillStyle=g;
ctx.beginPath(); ctx.arc(this.x,yy,this.r*3*pulse,0,TAU); ctx.fill();
ctx.fillStyle='#eafff9';
ctx.beginPath(); ctx.arc(this.x,yy,this.r*0.5*pulse,0,TAU); ctx.fill();
}
}
class Shadow{ // hazard — drifting tendril creature, fears the light
constructor(x,y,size){ this.x=x; this.y=y; this.size=size;
this.phase=rand(0,TAU); this.vx=rand(-20,20); this.dead=false;
this.fear=0; this.segs=[]; for(let i=0;i<6;i++) this.segs.push({x,y}); }
update(dt,player){
this.phase+=dt*2;
// drift, but recoil from player flare/light
const dx=this.x-player.x, dy=this.y-player.y;
const d=Math.hypot(dx,dy)||1;
const lightR=player.lightRadius();
if(d<lightR){
this.fear=Math.min(1,this.fear+dt*2.5);
const push=(lightR-d)/lightR * (player.flaring?420:160);
this.vx+=dx/d*push*dt; this.y+=dy/d*push*dt*0.6;
} else this.fear=Math.max(0,this.fear-dt);
this.vx*=0.96; this.x+=this.vx*dt;
this.x+=Math.sin(this.phase)*12*dt;
// tendril trail follows
let px=this.x, py=this.y;
for(const sg of this.segs){
sg.x=lerp(sg.x,px,0.35); sg.y=lerp(sg.y,py,0.35);
px=sg.x; py=sg.y;
}
}
draw(s){
const yy=this.y - s.camY;
const fearA=1-this.fear*0.7;
// tendrils
ctx.lineWidth=this.size*0.6; ctx.lineCap='round';
ctx.strokeStyle=`rgba(8,6,20,${0.85*fearA})`;
ctx.beginPath(); ctx.moveTo(this.x,yy);
for(const sg of this.segs) ctx.lineTo(sg.x, sg.y - s.camY);
ctx.stroke();
// body — a void with a faint violet edge
const r=this.size;
const g=ctx.createRadialGradient(this.x,yy,r*0.2,this.x,yy,r*1.4);
g.addColorStop(0,`rgba(2,1,8,${0.95*fearA})`);
g.addColorStop(0.7,`rgba(20,8,40,${0.7*fearA})`);
g.addColorStop(1,`rgba(60,20,90,0)`);
ctx.fillStyle=g;
ctx.beginPath();
for(let a=0;a<TAU;a+=0.4){
const wob=1+Math.sin(a*3+this.phase*1.5)*0.18;
const px=this.x+Math.cos(a)*r*1.4*wob, py=yy+Math.sin(a)*r*1.4*wob;
a===0?ctx.moveTo(px,py):ctx.lineTo(px,py);
}
ctx.closePath(); ctx.fill();
// eyes
ctx.fillStyle=`rgba(190,120,255,${0.8*(1-this.fear)})`;
const ex=Math.cos(this.phase)*r*0.25;
ctx.beginPath(); ctx.arc(this.x-r*0.3+ex,yy-r*0.1,r*0.13,0,TAU);
ctx.arc(this.x+r*0.3+ex,yy-r*0.1,r*0.13,0,TAU); ctx.fill();
}
}
class Barrier{ // drifting horizontal laser with one clean, wide gap
constructor(y,gapX,gapW){ this.y=y; this.gapX=gapX; this.gapW=gapW;
this.phase=rand(0,TAU); this.dead=false; this.hit=0; }
update(dt){ this.phase+=dt*0.8;
// gentle sway only, and freeze the gap once the player is close so it
// never drifts out of reach during the final approach
const near = game.player && Math.abs(game.player.y-this.y) < 220;
if(!near) this.gapX += Math.sin(this.phase)*16*dt;
const w=wallAt(this.y), inset=this.gapW*0.6+12;
this.gapX = clamp(this.gapX, w.left+inset, w.right-inset);
}
draw(s){
const yy=this.y - s.camY;
const w=wallAt(this.y);
const gx=this.gapX, gw=this.gapW;
const pulse=0.6+Math.sin(this.phase*4)*0.2;
ctx.save(); ctx.globalCompositeOperation='lighter';
const grad=ctx.createLinearGradient(0,yy-6,0,yy+6);
grad.addColorStop(0,'rgba(255,80,90,0)');
grad.addColorStop(0.5,`rgba(255,90,110,${pulse})`);
grad.addColorStop(1,'rgba(255,80,90,0)');
ctx.fillStyle=grad;
ctx.fillRect(w.left, yy-7, (gx-gw/2)-w.left, 14);
ctx.fillRect(gx+gw/2, yy-7, w.right-(gx+gw/2), 14);
// hot core line
ctx.fillStyle=`rgba(255,210,200,${pulse})`;
ctx.fillRect(w.left, yy-1.5, (gx-gw/2)-w.left, 3);
ctx.fillRect(gx+gw/2, yy-1.5, w.right-(gx+gw/2), 3);
// gap edge glints
ctx.fillStyle='rgba(255,180,180,0.9)';
ctx.beginPath(); ctx.arc(gx-gw/2,yy,3,0,TAU);
ctx.arc(gx+gw/2,yy,3,0,TAU); ctx.fill();
ctx.restore();
}
hits(p){ // swept: did the player cross this beam's y this frame, outside the gap?
if(!crossedY(p, this.y)) return false;
return p.x < this.gapX-this.gapW/2+4 || p.x > this.gapX+this.gapW/2-4;
}
}
class Gate{ // a sealed barrier of dark — must be FLARING to pass through
constructor(y){ this.y=y; this.phase=rand(0,TAU); this.dead=false;
this.open=0; this.passed=false; }
update(dt,player){ this.phase+=dt*2;
// opens as the player's flare nears it
const near = Math.abs(player.y-this.y)<260 && player.flaring;
this.open=lerp(this.open, near?1:0, 0.12);
}
draw(s){
const yy=this.y - s.camY; const w=wallAt(this.y);
const closed=1-this.open;
ctx.save();
// shimmering veil
for(let i=0;i<3;i++){
ctx.strokeStyle=`rgba(150,90,220,${0.4*closed - i*0.1})`;
ctx.lineWidth=4-i;
ctx.beginPath();
for(let x=w.left;x<=w.right;x+=12){
const yo=Math.sin(x*0.04+this.phase*1.5+i)*8*closed;
x===w.left?ctx.moveTo(x,yy+yo):ctx.lineTo(x,yy+yo);
}
ctx.stroke();
}
// sparkles along the veil
ctx.globalCompositeOperation='lighter';
ctx.fillStyle=`rgba(200,160,255,${closed})`;
for(let x=w.left+10;x<w.right;x+=46){
const yo=Math.sin(x*0.04+this.phase*1.5)*8*closed;
ctx.beginPath(); ctx.arc(x,yy+yo,2,0,TAU); ctx.fill();
}
ctx.restore();
}
hits(p){ // lethal only if you cross the closed veil without flaring it open
if(!crossedY(p, this.y)) return false;
return this.open < 0.55 && !p.flaring;
}
}
// Swept y-crossing test: did the player pass through line `lineY` between
// last frame's position (p.prevY) and this frame's (p.y)? Pads by 5px so a
// player sitting exactly on the line still registers. Prevents fast falls /
// frame hitches from tunnelling straight through thin hazards.
function crossedY(p, lineY){
const a = p.prevY===undefined ? p.y : p.prevY;
const b = p.y;
const lo = Math.min(a,b)-5, hi = Math.max(a,b)+5;
return lineY>=lo && lineY<=hi;
}
/* ---- cavern walls: procedurally carved, glow when lit ---- */
function wallAt(y){
// returns {left, right} cave opening for a given world-y
const t=y*0.0016;
const center = W*0.5
+ Math.sin(t)*W*0.16
+ Math.sin(t*2.3+1.7)*W*0.09
+ Math.sin(t*0.6+4.0)*W*0.05;
const half = W*0.30
+ Math.sin(t*1.7+2)*W*0.07
+ Math.sin(t*3.1)*W*0.035;
return { left:center-half, right:center+half, center, half };
}
/* ============================================================
PLAYER
============================================================ */
class Player{
constructor(){
this.x=W*0.5; this.y=120; this.vx=0; this.vy=140;
this.flaring=false; this.flare=0;
this.maxEnergy=1+upVal('energy');
this.energy=this.maxEnergy;
this.regen=0.18+upVal('regen');
this.shields=upLvl('shield');
this.invuln=0; // brief grace after losing a shield
this.super=0; // supercharged-flare timer (Echo Boost)
this.trail=[]; this.phase=0; this.tilt=0;
}
lightRadius(){
const biomeLight = game.biome ? game.biome.light : 1;
const boost = this.super>0 ? 260 : 0;
return (150 + upVal('radius') + this.flare*220 + this.energy*40 + boost) * biomeLight;
}
update(dt, input){
this.prevY=this.y; // remember frame-start y for swept hazard collision
this.phase+=dt*6;
// horizontal control — snappier so sharp dodges are actually possible
const accel=1500;
let ax=0;
if(input.left) ax-=accel;
if(input.right) ax+=accel;
if(input.mouseActive){
const target=input.mouseX;
ax += clamp((target-this.x)*6, -accel, accel);
}
this.vx += ax*dt; this.vx*=0.90;
this.x += this.vx*dt;
this.tilt = lerp(this.tilt, clamp(this.vx/400,-0.6,0.6), 0.15);
if(this.invuln>0) this.invuln-=dt;
if(this.super>0) this.super-=dt;
// Echo Boost: pressing flare while out of energy spends a stored echo
// charge to unleash a supercharged flare (refill + invuln + shockwave)
if(input.flare && this.energy<=0.02 && this.super<=0 && game.boosts>0){
game.boosts--; this.super=2.4; this.invuln=Math.max(this.invuln,2.4);
this.energy=this.maxEnergy;
unleashBoost(this.x,this.y);
renderEchoUI();
}
// gravity-ish descent (constant-ish fall, flare slows you & costs energy)
this.flaring = (input.flare && this.energy>0.02) || this.super>0;
const spd = game.biome ? game.biome.speedMul : 1;
if(this.flaring){
this.flare=lerp(this.flare,1,0.18);
if(this.super<=0) this.energy=Math.max(0,this.energy-dt*0.35);
this.vy=lerp(this.vy,90*spd,0.1); // flaring slows descent
} else {
this.flare=lerp(this.flare,0,0.12);
this.energy=Math.min(this.maxEnergy,this.energy+dt*this.regen);
this.vy=lerp(this.vy,(220+game.depth*0.025)*spd,0.02); // speeds up w/ depth
}
this.y += this.vy*dt;
// wall collision — bounce off cave edges
const w=wallAt(this.y), pad=14;
if(this.x < w.left+pad){ this.x=w.left+pad; this.vx=Math.abs(this.vx)*0.5+40;
this.graze(w.left); }
if(this.x > w.right-pad){ this.x=w.right-pad; this.vx=-Math.abs(this.vx)*0.5-40;
this.graze(w.right); }
// trail
this.trail.push({x:this.x,y:this.y,f:this.flare});
if(this.trail.length>26) this.trail.shift();
// ambient spark emission
if(Math.random()<0.7){
emit(this.x+rand(-6,6), this.y+rand(-6,6),
rand(-30,30)-this.vx*0.1, rand(-40,10),
rand(0.4,0.9), rand(1,3), rand(38,55),
0.8, rand(-30,30));
}
if(this.flaring && Math.random()<0.9){
const a=rand(0,TAU);
emit(this.x,this.y, Math.cos(a)*rand(60,200), Math.sin(a)*rand(60,200),
rand(0.3,0.7), rand(2,4), rand(35,52), 1, 0);
}
}
graze(wx){
for(let i=0;i<4;i++)
emit(wx, this.y+rand(-10,10), rand(-60,60), rand(-80,80),
rand(0.3,0.6), rand(1,3), rand(180,210), 0.7, 0);
}
draw(s){
const yy=this.y - s.camY;
// trail
for(let i=0;i<this.trail.length;i++){
const t=this.trail[i], a=i/this.trail.length;
const ty=t.y - s.camY;
const r=(1+a*5)*(1+t.f);
ctx.fillStyle=hsl(lerp(48,180,t.f), 100, lerp(70,85,a), a*0.5);
ctx.beginPath(); ctx.arc(t.x,ty,r,0,TAU); ctx.fill();
}
// core glow — gold when supercharged by an Echo Boost, teal when flaring
const R=this.lightRadius();
const g=ctx.createRadialGradient(this.x,yy,0,this.x,yy,R);
const hue = this.super>0 ? 45 : lerp(45,175,this.flare);
g.addColorStop(0, hsl(hue,100,95,0.9));
g.addColorStop(0.08, hsl(hue,100,80,0.55));
g.addColorStop(0.3, hsl(hue,100,60,0.16));
g.addColorStop(1, hsl(hue,100,50,0));
ctx.fillStyle=g;
ctx.beginPath(); ctx.arc(this.x,yy,R,0,TAU); ctx.fill();
// bright core
const cr=8+this.flare*6+Math.sin(this.phase)*1.5;
ctx.fillStyle='#ffffff';
ctx.beginPath(); ctx.arc(this.x,yy,cr*0.5,0,TAU); ctx.fill();
ctx.fillStyle=hsl(hue,100,88,0.9);
ctx.beginPath(); ctx.arc(this.x,yy,cr,0,TAU); ctx.fill();
// energy ring
ctx.strokeStyle=hsl(hue,100,80,0.6); ctx.lineWidth=2;
ctx.beginPath();
ctx.arc(this.x,yy,cr+6, -Math.PI/2,
-Math.PI/2 + TAU*clamp(this.energy/this.maxEnergy,0,1));
ctx.stroke();
// shield aura
if(this.shields>0){
const sp=0.5+Math.sin(this.phase*0.7)*0.2;
ctx.strokeStyle=`rgba(180,230,255,${sp})`; ctx.lineWidth=2.5;
for(let k=0;k<this.shields;k++){
ctx.beginPath(); ctx.arc(this.x,yy,cr+14+k*5,0,TAU); ctx.stroke();
}
}
if(this.invuln>0){
ctx.strokeStyle=`rgba(255,255,255,${this.invuln})`; ctx.lineWidth=3;
ctx.beginPath(); ctx.arc(this.x,yy,cr+10,0,TAU); ctx.stroke();
}
}
}
/* ============================================================
GAME STATE / LOOP
============================================================ */
const input={ left:false,right:false,flare:false,
mouseActive:false, mouseX:W/2 };
let deathTO=null; // pending game-over timer (so restarts can cancel it)
const echoEl=document.getElementById('echoes');
// the dots now represent your STORED Echo Boost charges: gold = ready to spend
function renderEchoUI(){
const g=game; if(!g) return;
echoEl.innerHTML='';
for(let i=0;i<g.boostMax;i++){
const d=document.createElement('span');
d.className='echo-dot'+(i<g.boosts?' charged':'');
echoEl.appendChild(d);
}
}
function newGame(){
clearTimeout(deathTO); // cancel any pending game-over from a prior death
game={
player:null,
camY:0, depth:0, score:0,
combo:0, comboTimer:0, mult:1,
motes:[], echoes:[], shadows:[], barriers:[], gates:[],
echoCount:0, echoTotal:7, // total echoes ever awakened this run
boosts:0, boostMax:7, // stored Echo Boost charges (spent via flare)
nextMoteY:300, nextShadowY:600, nextEchoY:1400,
nextBarrierY:1100, nextGateY:1700,
shake:0, flash:0, vignette:0, over:false, paused:false, time:0,
biome:biomeAt(0), lastBiomeIndex:0,
bg:[] // floating background dust
};
game.player=new Player();
for(let i=0;i<60;i++) game.bg.push({
x:rand(0,W), y:rand(0,H*3), z:rand(0.2,1), r:rand(0.5,2),
hue:rand(200,260) });
renderEchoUI();
document.getElementById('biome').textContent=game.biome.name;
document.getElementById('combo').textContent='';
document.getElementById('score').textContent='0';
document.getElementById('depth').textContent='0m';
}
function spawnAhead(){
const g=game;
const lookahead=g.camY+H+400;
// motes
while(g.nextMoteY < lookahead){
const y=g.nextMoteY; const w=wallAt(y);
const x=rand(w.left+30, w.right-30);
if(Math.random()<0.85) g.motes.push(new Mote(x,y));
g.nextMoteY += rand(90,190);
}
// shadows — frequency & density rise with depth and biome
while(g.nextShadowY < lookahead){
const y=g.nextShadowY; const b=biomeAt(y/10); const w=wallAt(y);
const x=rand(w.left+50, w.right-50);
const size=rand(16,26)+Math.min(20,g.depth*0.002);
g.shadows.push(new Shadow(x,y,size));
// sometimes a second shadow nearby in dense biomes
if(Math.random() < (b.shadowMul-1)*0.6){
g.shadows.push(new Shadow(rand(w.left+50,w.right-50), y+rand(40,120), size*0.85));
}
const base=clamp(rand(380,640)-g.depth*0.04, 130, 640);
g.nextShadowY += base / b.shadowMul;
}
// laser barriers — appear from ~1100m, denser deeper.
// The gap is anchored to the CAVE CENTRE at the barrier's own depth — i.e.
// the path the cave naturally funnels you onto. Through a bend this is where
// you'll actually be, so the gap is always reachable. A small nudge (kept
// inside the bore) makes it a real dodge rather than a freebie.
while(g.nextBarrierY < lookahead){
const y=g.nextBarrierY; const w=wallAt(y);
const gw=clamp(230-g.depth*0.004, 160, 230); // one nice wide gap
const inset=gw*0.6+18;
// bias the gap toward where the player is, with a modest random nudge
const nudge=rand(-1,1)*Math.min(W*0.16, 220);
const gx=clamp(g.player.x+nudge, w.left+inset, w.right-inset);
g.barriers.push(new Barrier(y, gx, gw));
g.nextBarrierY += clamp(rand(900,1500)-g.depth*0.05, 460, 1500);
}
// flare-gates — appear from ~1700m
while(g.nextGateY < lookahead){
g.gates.push(new Gate(g.nextGateY));
g.nextGateY += clamp(rand(1300,2000)-g.depth*0.05, 650, 2000);
}
// echoes — rare, milestone reward
while(g.nextEchoY < lookahead){
const y=g.nextEchoY; const w=wallAt(y);
g.echoes.push(new Echo(w.center, y));
g.nextEchoY += rand(1600,2400);
}
}
// any overlay screen visible? if so, no live game should be simulating
function anyScreenOpen(){
const t=document.getElementById('title');
const o=document.getElementById('gameOver');
const s=document.getElementById('shop');
return (t && !t.classList.contains('hide'))
|| (o && o.classList.contains('show'))
|| (s && s.classList.contains('show'));
}
let last=performance.now();
function frame(now){
let dt=(now-last)/1000; last=now;
dt=Math.min(dt,0.05);
// simulate only when actually playing: not paused, not over, no menu up
if(game && !game.paused && !game.over && !anyScreenOpen()) update(dt);
else if(game && game.over) { stepParticles(dt); game.shake*=0.9; } // death anim
render();
requestAnimationFrame(frame);
}
function update(dt){
const g=game; if(g.over) { stepParticles(dt); g.shake*=0.9; return; }
g.time+=dt;
const p=g.player;
p.update(dt,input);
// camera trails the player, keeping it in upper-third
const targetCam = p.y - H*0.34;
g.camY = lerp(g.camY, targetCam, 0.12);
g.depth = Math.max(g.depth, Math.floor(p.y/10));
document.getElementById('depth').textContent = g.depth+'m';
// biome transition
g.biome = biomeAt(g.depth);
if(g.biome.index !== g.lastBiomeIndex){
g.lastBiomeIndex = g.biome.index;
if(g.depth>10) announceBiome(g.biome.name);
document.getElementById('biome').textContent=g.biome.name;
}
Audio.setIntensity(clamp(g.depth/1500,0,1));
spawnAhead();
// combo decay
if(g.comboTimer>0){ g.comboTimer-=dt;
if(g.comboTimer<=0){ g.combo=0; updateCombo(); } }
const greed=1+upVal('greed');
const magR=upVal('magnet');
// motes (with magnet pull)
for(const m of g.motes){
if(m.dead) continue; m.update(dt);
const dx=p.x-m.x, dy=p.y-m.y, d=Math.hypot(dx,dy)||1;
if(magR>0 && d<magR){ const pull=(1-d/magR)*420*dt;
m.x+=dx/d*pull; m.y+=dy/d*pull; }
if(d < 26){
m.dead=true;
bumpCombo();
const gain=Math.round(10*greed*g.mult);
g.score+=gain; g.flash=Math.max(g.flash,0.12);
Audio.blip(randi(0,12)+g.combo,'sine',0.18);
for(let i=0;i<10;i++)
emit(m.x,m.y,rand(-120,120),rand(-120,120),rand(0.4,0.9),
rand(2,4),m.hue,1,40);
document.getElementById('score').textContent=g.score;
}
}
// echoes
for(const e of g.echoes){
if(e.dead) continue; e.update(dt);
if(Math.hypot(e.x-p.x,e.y-p.y) < 40){
e.dead=true; g.echoCount++;
g.score+=Math.round(120*greed);
// awakening an echo stores an Echo Boost charge (spent by flaring)
g.boosts=Math.min(g.boostMax, g.boosts+1);
g.flash=0.5; g.shake=Math.max(g.shake,8); p.energy=p.maxEnergy;
Audio.chord([0,3,7,10,12],0.3);
for(let i=0;i<60;i++){ const a=rand(0,TAU);
emit(e.x,e.y,Math.cos(a)*rand(80,360),Math.sin(a)*rand(80,360),
rand(0.6,1.4),rand(2,5),rand(160,185),1,0); }
renderEchoUI();
document.getElementById('score').textContent=g.score;
}
}
// shadows
for(const sh of g.shadows){
if(sh.dead) continue; sh.update(dt,p);
const d=Math.hypot(sh.x-p.x,sh.y-p.y);
if(d < sh.size+10){
if(p.flaring){ // flaring scatters them for points
sh.dead=true; bumpCombo();
g.score+=Math.round(5*greed*g.mult); g.shake=Math.max(g.shake,6);
document.getElementById('score').textContent=g.score;
Audio.noise(0.3,0.4,1800);
for(let i=0;i<30;i++){ const a=rand(0,TAU);
emit(sh.x,sh.y,Math.cos(a)*rand(60,260),Math.sin(a)*rand(60,260),
rand(0.4,1),rand(2,4),rand(260,290),1,0); }
} else if(!absorb(p, sh.x, sh.y)){ die(); return; }
else sh.dead=true;
}
}
// laser barriers
for(const ba of g.barriers){
if(ba.dead) continue; ba.update(dt);
if(ba.hits(p) && p.invuln<=0){
if(!absorb(p, p.x, p.y)){ die(); return; }
ba.dead=true;
}
}
// flare-gates
for(const ga of g.gates){
if(ga.dead) continue; ga.update(dt,p);
if(ga.hits(p) && p.invuln<=0){
if(!absorb(p, p.x, p.y)){ die(); return; }
ga.dead=true;
} else if(!ga.passed && p.y>ga.y+10){
ga.passed=true; // rewarded for flaring through cleanly
if(p.flaring){ g.score+=Math.round(15*greed*g.mult); bumpCombo();
document.getElementById('score').textContent=g.score; }
}
}
// cull off-screen
const cullY=g.camY-200;
g.motes=g.motes.filter(m=>!m.dead && m.y>cullY);
g.echoes=g.echoes.filter(e=>!e.dead && e.y>cullY);
g.shadows=g.shadows.filter(s=>!s.dead && s.y>cullY);
g.barriers=g.barriers.filter(b=>!b.dead && b.y>cullY);
g.gates=g.gates.filter(x=>!x.dead && x.y>cullY);
stepParticles(dt);
g.shake*=0.88; g.flash*=0.9;
// deep-choir biome closes the vignette tighter
const fogTarget=(g.biome.fog||0.5) + (p.energy<0.25?0.25:0);
g.vignette=lerp(g.vignette, fogTarget, 0.05);
}
/* ---- combo, shield-absorb, biome banner helpers ---- */
function bumpCombo(){
const g=game; g.combo++; g.comboTimer=2.4;
g.mult=1+Math.min(g.combo*0.1, 2.0); // up to 3x
updateCombo();
}
function updateCombo(){
const g=game, el=document.getElementById('combo');
el.textContent = g.combo>=3 ? `×${g.mult.toFixed(1)} · ${g.combo} chain` : '';
}
function absorb(p, x, y){ // consume a shield if available; returns true if survived
if(p.shields<=0) return false;
p.shields--; p.invuln=1.0; game.shake=Math.max(game.shake,10);
game.flash=Math.max(game.flash,0.35);
Audio.noise(0.4,0.5,2400);
for(let i=0;i<40;i++){ const a=rand(0,TAU);
emit(x,y,Math.cos(a)*rand(80,300),Math.sin(a)*rand(80,300),
rand(0.4,1),rand(2,4),rand(190,210),1,0); }
return true;
}
function unleashBoost(x,y){
const g=game;
g.flash=0.7; g.shake=Math.max(g.shake,16);
Audio.chord([0,7,12,19],0.34); Audio.noise(0.35,0.6,3000);
// shatter every shadow on screen
for(const sh of g.shadows){