Repository navigation
Expand file tree
/
Copy pathGeometrydash.html
More file actions
2300 lines (2213 loc) · 115 KB
/
Copy pathGeometrydash.html
File metadata and controls
2300 lines (2213 loc) · 115 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="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<meta name="theme-color" content="#0A1033">
<title>Geometry Dash Web · 几何冲刺</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@600;700;900&family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet">
<style>
:root {
--bg: #060818;
--panel: rgba(8, 12, 38, 0.92);
--panel-border: rgba(255,255,255,0.14);
--white: #FFFFFF;
--muted: #9BA3C9;
--green: #7DFF00;
--cyan: #00FFFF;
--gold: #FFD700;
--red: #FF3B5C;
--fd: 'Orbitron', system-ui, sans-serif;
--fm: 'JetBrains Mono', monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { color-scheme: dark; }
html, body {
width: 100%; height: 100%;
background: var(--bg);
overflow: hidden;
font-family: var(--fm);
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
-webkit-tap-highlight-color: transparent;
}
canvas { display: block; width: 100%; height: 100%; }
.hidden { display: none !important; }
/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
#progress-wrap {
position: absolute; top: 12px; left: 50%;
transform: translateX(-50%);
width: min(46vw, 420px); height: 14px;
background: rgba(0,0,0,0.55);
border: 2px solid rgba(255,255,255,0.75);
border-radius: 9px;
}
#progress-fill {
position: absolute; top: 1px; left: 1px; bottom: 1px;
width: 0%; border-radius: 6px;
background: linear-gradient(180deg, #B4FF57, #52D000);
box-shadow: 0 0 10px rgba(125,255,0,0.55);
transition: width 0.08s linear;
}
#progress-pct {
position: absolute; top: 8px; left: calc(50% + min(23vw, 210px) + 12px);
color: var(--white); font-family: var(--fd);
font-size: 17px; font-weight: 700;
text-shadow: 0 2px 0 rgba(0,0,0,0.6), 0 0 12px rgba(255,255,255,0.25);
font-variant-numeric: tabular-nums;
}
#hud-coins { position: absolute; top: 40px; right: 16px; display: flex; gap: 7px; }
.hud-coin {
width: 17px; height: 17px; border-radius: 50%;
border: 2px solid rgba(255,215,0,0.8);
background: rgba(0,0,0,0.4);
box-shadow: 0 0 6px rgba(0,0,0,0.5);
transition: background 0.2s, box-shadow 0.2s;
}
.hud-coin.got {
background: radial-gradient(circle at 35% 30%, #FFF3B0, #FFD700 55%, #B8860B);
box-shadow: 0 0 12px rgba(255,215,0,0.8);
}
#pause-btn {
position: absolute; top: 8px; right: 12px;
width: 42px; height: 42px;
background: rgba(0,0,0,0.35);
border: 2px solid rgba(255,255,255,0.5);
border-radius: 10px;
color: #fff; cursor: pointer;
pointer-events: auto;
display: flex; align-items: center; justify-content: center;
transition: border-color 0.15s, background 0.15s;
}
#pause-btn:hover { border-color: var(--green); background: rgba(0,0,0,0.55); }
#pause-btn svg { width: 16px; height: 16px; fill: #fff; }
#practice-badge {
position: absolute; top: 14px; left: 14px;
font-family: var(--fd); font-size: 12px; font-weight: 700;
letter-spacing: 2px; color: #6CFF6C;
background: rgba(0,60,0,0.45);
border: 1px solid rgba(108,255,108,0.6);
padding: 5px 10px; border-radius: 7px;
text-shadow: 0 0 8px rgba(108,255,108,0.5);
}
/* ---------- 菜单通用 ---------- */
.overlay {
position: absolute; inset: 0; z-index: 50;
display: flex; align-items: center; justify-content: center;
background: rgba(4, 6, 20, 0.55);
backdrop-filter: blur(3px);
}
.overlay.opaque { background: rgba(4,6,20,0.0); backdrop-filter: none; }
.panel {
background: var(--panel);
border: 2px solid var(--panel-border);
border-radius: 18px;
box-shadow: 0 18px 50px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.08);
padding: 30px 34px;
text-align: center;
max-width: min(92vw, 760px);
max-height: 92vh;
overflow-y: auto;
animation: popIn 0.32s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes popIn {
from { opacity: 0; transform: scale(0.86) translateY(24px); }
to { opacity: 1; transform: scale(1) translateY(0); }
}
.gd-logo {
font-family: var(--fd); font-weight: 900;
font-size: clamp(34px, 7vw, 62px);
line-height: 1.02; letter-spacing: 2px;
text-transform: uppercase;
background: linear-gradient(180deg, #FFF8C0 0%, #FFD54A 38%, #FF8A00 72%, #B84A00 100%);
-webkit-background-clip: text; background-clip: text;
-webkit-text-fill-color: transparent;
filter: drop-shadow(0 3px 0 rgba(0,0,0,0.85)) drop-shadow(0 0 26px rgba(255,170,0,0.35));
}
.gd-sub {
font-family: var(--fd); font-weight: 700;
font-size: 13px; letter-spacing: 7px; margin-top: 8px;
color: var(--cyan);
text-shadow: 0 0 14px rgba(0,255,255,0.6);
}
.hint { color: var(--muted); font-size: 12px; letter-spacing: 1px; line-height: 1.9; }
.gbtn {
font-family: var(--fd); font-weight: 900;
text-transform: uppercase; letter-spacing: 1.5px;
font-size: 15px; color: #123300;
background: linear-gradient(180deg, #C6FF6B 0%, #7DE000 55%, #55B000 100%);
border: 2px solid #0E2A00;
box-shadow: 0 5px 0 #0E2A00, 0 8px 18px rgba(0,0,0,0.45);
border-radius: 12px;
padding: 13px 30px;
cursor: pointer;
transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
pointer-events: auto;
}
.gbtn:hover { filter: brightness(1.1); }
.gbtn:active { transform: translateY(4px); box-shadow: 0 1px 0 #0E2A00, 0 3px 8px rgba(0,0,0,0.45); }
.gbtn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.gbtn.blue {
color: #001A33;
background: linear-gradient(180deg, #7FE9FF 0%, #19B8F0 55%, #0E86C4 100%);
border-color: #002238; box-shadow: 0 5px 0 #002238, 0 8px 18px rgba(0,0,0,0.45);
}
.gbtn.blue:active { box-shadow: 0 1px 0 #002238, 0 3px 8px rgba(0,0,0,0.45); }
.gbtn.red {
color: #330008;
background: linear-gradient(180deg, #FF8FA3 0%, #FF3B5C 55%, #C21237 100%);
border-color: #38000C; box-shadow: 0 5px 0 #38000C, 0 8px 18px rgba(0,0,0,0.45);
}
.gbtn.red:active { box-shadow: 0 1px 0 #38000C, 0 3px 8px rgba(0,0,0,0.45); }
.gbtn.ghost {
color: #E7ECFF;
background: linear-gradient(180deg, rgba(255,255,255,0.16), rgba(255,255,255,0.05));
border-color: rgba(255,255,255,0.4);
box-shadow: 0 5px 0 rgba(255,255,255,0.18), 0 8px 18px rgba(0,0,0,0.4);
}
.gbtn.ghost:active { box-shadow: 0 1px 0 rgba(255,255,255,0.18); }
.btn-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }
#big-play {
width: 118px; height: 118px; margin: 26px auto 20px;
border-radius: 26px;
background: linear-gradient(180deg, #C6FF6B 0%, #7DE000 55%, #4EA400 100%);
border: 3px solid #0E2A00;
box-shadow: 0 7px 0 #0E2A00, 0 14px 34px rgba(125,224,0,0.35);
cursor: pointer;
display: flex; align-items: center; justify-content: center;
transition: transform 0.1s, box-shadow 0.1s, filter 0.15s;
animation: playPulse 2.2s ease-in-out infinite;
}
#big-play:hover { filter: brightness(1.08); }
#big-play:active { transform: translateY(5px); box-shadow: 0 2px 0 #0E2A00, 0 6px 16px rgba(125,224,0,0.3); }
#big-play svg { width: 52px; height: 52px; fill: #123300; margin-left: 8px; filter: drop-shadow(0 2px 0 rgba(255,255,255,0.25)); }
@keyframes playPulse {
0%, 100% { box-shadow: 0 7px 0 #0E2A00, 0 14px 34px rgba(125,224,0,0.3); }
50% { box-shadow: 0 7px 0 #0E2A00, 0 14px 48px rgba(125,224,0,0.55); }
}
.toggles { display: flex; gap: 14px; justify-content: center; margin-top: 20px; }
.tgl {
width: 52px; height: 52px; border-radius: 50%;
background: rgba(255,255,255,0.07);
border: 2px solid rgba(255,255,255,0.35);
color: #fff; cursor: pointer;
display: flex; align-items: center; justify-content: center;
transition: border-color 0.15s, opacity 0.15s, box-shadow 0.15s;
}
.tgl svg { width: 22px; height: 22px; fill: currentColor; }
.tgl.off { opacity: 0.32; }
.tgl:hover { border-color: var(--green); box-shadow: 0 0 14px rgba(125,255,0,0.25); }
.tgl:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
/* ---------- 选关 ---------- */
#select-title {
font-family: var(--fd); font-weight: 900; font-size: 24px;
letter-spacing: 4px; color: #fff; text-transform: uppercase;
text-shadow: 0 2px 0 rgba(0,0,0,0.7), 0 0 18px rgba(255,255,255,0.2);
margin-bottom: 20px;
}
#cards { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.card {
width: 216px; border-radius: 16px;
border: 2px solid rgba(255,255,255,0.22);
padding: 16px 15px 15px;
cursor: pointer; position: relative;
transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
text-align: left;
}
.card:hover { transform: translateY(-4px); border-color: rgba(255,255,255,0.65); box-shadow: 0 14px 34px rgba(0,0,0,0.5); }
.card:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
.card.c0 { background: linear-gradient(160deg, #0E3D6B 0%, #0A2547 60%, #071A33 100%); }
.card.c1 { background: linear-gradient(160deg, #14653A 0%, #0B3D25 60%, #072B1A 100%); }
.card.c2 { background: linear-gradient(160deg, #7A2408 0%, #56160C 60%, #3A0D10 100%); }
.card-top { display: flex; align-items: center; gap: 11px; }
.face { width: 46px; height: 46px; flex: 0 0 auto; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5)); }
.card-name {
font-family: var(--fd); font-weight: 900; font-size: 15px;
color: #fff; letter-spacing: 0.5px; line-height: 1.25;
text-shadow: 0 2px 0 rgba(0,0,0,0.55);
}
.card-diff { font-size: 10px; letter-spacing: 2px; color: rgba(255,255,255,0.75); margin-top: 3px; font-weight: 700; }
.stars { display: flex; align-items: center; gap: 3px; margin-top: 10px; }
.stars svg { width: 15px; height: 15px; fill: var(--gold); filter: drop-shadow(0 1px 1px rgba(0,0,0,0.6)); }
.stars span { color: #fff; font-size: 12px; font-weight: 700; margin-left: 3px; }
.song-row {
margin-top: 10px; font-size: 10.5px; color: rgba(255,255,255,0.85);
display: flex; align-items: center; gap: 6px; letter-spacing: 0.4px;
}
.song-row svg { width: 13px; height: 13px; fill: #B18CFF; flex: 0 0 auto; }
.pbar-label { display: flex; justify-content: space-between; font-size: 9.5px; color: rgba(255,255,255,0.6); margin: 9px 0 3px; letter-spacing: 1px; }
.pbar { height: 10px; border-radius: 6px; background: rgba(0,0,0,0.5); border: 1px solid rgba(255,255,255,0.35); position: relative; overflow: hidden; }
.pbar > div { position: absolute; inset: 1px auto 1px 1px; width: 0%; border-radius: 4px; }
.pbar.normal > div { background: linear-gradient(180deg, #B4FF57, #52D000); }
.pbar.practice > div { background: linear-gradient(180deg, #7FE9FF, #1D9BFF); }
.card-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 11px; }
.card-coins { display: flex; gap: 5px; }
.card-coin { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid rgba(255,215,0,0.75); background: rgba(0,0,0,0.35); }
.card-coin.got { background: radial-gradient(circle at 35% 30%, #FFF3B0, #FFD700 55%, #B8860B); box-shadow: 0 0 7px rgba(255,215,0,0.7); }
.card-att { font-size: 9.5px; color: rgba(255,255,255,0.55); letter-spacing: 1px; }
.crown { position: absolute; top: -13px; right: 12px; width: 26px; height: 26px; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.6)); }
/* ---------- 完成界面 ---------- */
.complete-title {
font-family: var(--fd); font-weight: 900;
font-size: clamp(28px, 6vw, 46px); letter-spacing: 2px;
text-transform: uppercase;
background: linear-gradient(180deg, #FFFBD0 0%, #FFE24A 45%, #FF9500 100%);
-webkit-background-clip: text; background-clip: text;
-webkit-text-fill-color: transparent;
filter: drop-shadow(0 3px 0 rgba(0,0,0,0.8)) drop-shadow(0 0 24px rgba(255,200,0,0.45));
animation: completeBounce 0.55s cubic-bezier(0.34,1.8,0.64,1);
}
@keyframes completeBounce {
0% { transform: scale(0.3); opacity: 0; }
60% { transform: scale(1.15); opacity: 1; }
100% { transform: scale(1); }
}
.death-title {
font-family: var(--fd); font-weight: 900;
font-size: clamp(26px, 5vw, 40px); letter-spacing: 2px; text-transform: uppercase;
background: linear-gradient(180deg, #FFB3C1 0%, #FF3B5C 55%, #A50E2D 100%);
-webkit-background-clip: text; background-clip: text;
-webkit-text-fill-color: transparent;
filter: drop-shadow(0 3px 0 rgba(0,0,0,0.8));
}
.stat-grid {
display: grid; grid-template-columns: repeat(2, minmax(120px, 1fr));
gap: 10px 26px; margin: 20px auto 4px; max-width: 360px;
}
.stat { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.stat b { color: #fff; font-family: var(--fd); font-weight: 700; }
.stat span { color: var(--muted); letter-spacing: 1px; }
.cmp-coins { display: flex; gap: 12px; justify-content: center; margin: 16px 0 4px; }
.cmp-coin { width: 30px; height: 30px; border-radius: 50%; border: 2.5px solid rgba(255,215,0,0.8); background: rgba(0,0,0,0.4); }
.cmp-coin.got { background: radial-gradient(circle at 35% 30%, #FFF3B0, #FFD700 55%, #B8860B); box-shadow: 0 0 16px rgba(255,215,0,0.85); }
.newbest {
display: inline-block; margin-top: 12px;
font-family: var(--fd); font-weight: 900; font-size: 14px; letter-spacing: 2px;
color: #7DFF00; text-shadow: 0 0 14px rgba(125,255,0,0.7);
animation: playPulse 1.4s infinite;
border: 1px solid rgba(125,255,0,0.5); border-radius: 8px; padding: 6px 14px;
}
.menu-note { margin-top: 16px; font-size: 11px; color: var(--muted); letter-spacing: 1px; line-height: 1.8; }
kbd {
font-family: var(--fm); font-size: 10.5px; color: #fff;
background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.3);
border-bottom-width: 2.5px; border-radius: 5px; padding: 1.5px 6px;
}
@media (max-width: 720px) {
.panel { padding: 22px 18px; }
#cards { gap: 10px; }
.card { width: min(86vw, 300px); }
#progress-wrap { width: 56vw; }
#progress-pct { left: calc(50% + 28vw + 8px); font-size: 14px; top: 10px; }
.stat-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
.panel, .complete-title, #big-play { animation: none; }
}
</style>
</head>
<body>
<canvas id="gameCanvas"></canvas>
<div id="hud" class="hidden">
<div id="progress-wrap"><div id="progress-fill"></div></div>
<div id="progress-pct">0%</div>
<div id="hud-coins">
<div class="hud-coin" id="hc0"></div>
<div class="hud-coin" id="hc1"></div>
<div class="hud-coin" id="hc2"></div>
</div>
<button id="pause-btn" aria-label="暂停">
<svg viewBox="0 0 24 24"><path d="M6 4h4v16H6zM14 4h4v16h-4z"/></svg>
</button>
<div id="practice-badge" class="hidden">PRACTICE</div>
</div>
<!-- 主菜单 -->
<div id="menu-main" class="overlay opaque">
<div class="panel">
<div class="gd-logo">Geometry<br>Dash</div>
<div class="gd-sub">WEB EDITION</div>
<button id="big-play" aria-label="开始游戏">
<svg viewBox="0 0 24 24"><path d="M8 5v14l11-7z"/></svg>
</button>
<div class="toggles">
<button class="tgl" id="tgl-music" aria-label="音乐开关">
<svg viewBox="0 0 24 24"><path d="M12 3v10.55A4 4 0 1 0 14 17V7h4V3h-6z"/></svg>
</button>
<button class="tgl" id="tgl-sfx" aria-label="音效开关">
<svg viewBox="0 0 24 24"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3A4.5 4.5 0 0 0 14 8.5v7a4.47 4.47 0 0 0 2.5-3.5zM14 3.23v2.06a7.007 7.007 0 0 1 0 13.42v2.06A9.01 9.01 0 0 0 14 3.23z"/></svg>
</button>
</div>
<div class="hint" style="margin-top:18px">
<kbd>空格</kbd> / <kbd>↑</kbd> / 点按 跳跃 · 按住连跳 · <kbd>P</kbd>/<kbd>Esc</kbd> 暂停
</div>
</div>
</div>
<!-- 选关 -->
<div id="menu-select" class="overlay opaque hidden">
<div class="panel" style="padding-bottom:24px">
<div id="select-title">Select Level</div>
<div id="cards"></div>
<div class="btn-row">
<button class="gbtn ghost" id="sel-back">← 返回</button>
</div>
<div class="menu-note">每关 3 枚隐藏金币 · 练习模式含检查点 · 关卡与音乐逐拍同步</div>
</div>
</div>
<!-- 暂停 -->
<div id="menu-pause" class="overlay hidden">
<div class="panel">
<div class="death-title" style="background:linear-gradient(180deg,#DDE6FF,#8FB0FF 55%,#4A6ACF);-webkit-background-clip:text;background-clip:text;">Paused</div>
<div class="stat-grid" style="margin-top:16px">
<div class="stat"><span>进度</span><b id="pause-pct">0%</b></div>
<div class="stat"><span>尝试</span><b id="pause-att">1</b></div>
</div>
<div class="btn-row">
<button class="gbtn" id="pause-resume">继续</button>
<button class="gbtn blue" id="pause-restart">重来</button>
</div>
<div class="btn-row">
<button class="gbtn ghost" id="pause-practice">进入练习模式</button>
<button class="gbtn red" id="pause-exit">退出</button>
</div>
<div class="toggles">
<button class="tgl" id="ptgl-music" aria-label="音乐开关">
<svg viewBox="0 0 24 24"><path d="M12 3v10.55A4 4 0 1 0 14 17V7h4V3h-6z"/></svg>
</button>
<button class="tgl" id="ptgl-sfx" aria-label="音效开关">
<svg viewBox="0 0 24 24"><path d="M3 9v6h4l5 5V4L7 9H3zm13.5 3A4.5 4.5 0 0 0 14 8.5v7a4.47 4.47 0 0 0 2.5-3.5zM14 3.23v2.06a7.007 7.007 0 0 1 0 13.42v2.06A9.01 9.01 0 0 0 14 3.23z"/></svg>
</button>
</div>
</div>
</div>
<!-- 通关 -->
<div id="menu-complete" class="overlay hidden">
<div class="panel">
<div class="complete-title">Level Complete!</div>
<div class="hint" id="cmp-level" style="margin-top:8px;letter-spacing:2px"></div>
<div class="cmp-coins">
<div class="cmp-coin" id="cc0"></div>
<div class="cmp-coin" id="cc1"></div>
<div class="cmp-coin" id="cc2"></div>
</div>
<div class="stat-grid">
<div class="stat"><span>尝试次数</span><b id="cmp-att">1</b></div>
<div class="stat"><span>跳跃次数</span><b id="cmp-jumps">0</b></div>
<div class="stat"><span>用时</span><b id="cmp-time">0:00</b></div>
<div class="stat"><span>模式</span><b id="cmp-mode">NORMAL</b></div>
</div>
<div id="cmp-newbest" class="newbest hidden">★ 首次通关 ★</div>
<div class="btn-row">
<button class="gbtn" id="cmp-replay">再玩一次</button>
<button class="gbtn blue" id="cmp-select">选关</button>
</div>
</div>
</div>
<script>
(function() {
'use strict';
const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
const $ = id => document.getElementById(id);
const hud = $('hud'), progressFill = $('progress-fill'), progressPct = $('progress-pct');
const hudCoins = [$('hc0'), $('hc1'), $('hc2')];
const practiceBadge = $('practice-badge');
const menuMain = $('menu-main'), menuSelect = $('menu-select'),
menuPause = $('menu-pause'), menuComplete = $('menu-complete');
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
let W = 0, H = 0, dpr = 1;
function resizeCanvas() {
dpr = Math.min(window.devicePixelRatio || 1, 2);
W = window.innerWidth; H = window.innerHeight;
canvas.width = W * dpr; canvas.height = H * dpr;
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
}
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
// ============================================================
// SOUND ENGINE(音效;BGM 系统在下方,保持原样)
// ============================================================
class SoundEngine {
constructor() {
this.ctx = null;
this.masterGain = null;
this.sfxEnabled = true;
this.bgmEnabled = true;
this._init();
}
_init() {
try {
this.ctx = new (window.AudioContext || window.webkitAudioContext)();
this.masterGain = this.ctx.createGain();
this.masterGain.gain.value = 0.4;
this.masterGain.connect(this.ctx.destination);
} catch (_) {}
}
resume() {
if (this.ctx && this.ctx.state === 'suspended') {
this.ctx.resume().catch(() => {});
}
}
suspend() {
if (this.ctx && this.ctx.state === 'running') {
this.ctx.suspend().catch(() => {});
}
}
setSFXEnabled(e) { this.sfxEnabled = e; }
setBGMEnabled(e) { this.bgmEnabled = e; }
_node(freq, type, vol, dur) {
if (!this.ctx || !this.sfxEnabled) return null;
const osc = this.ctx.createOscillator();
const gain = this.ctx.createGain();
osc.type = type;
osc.frequency.setValueAtTime(freq, this.ctx.currentTime);
gain.gain.setValueAtTime(vol, this.ctx.currentTime);
gain.gain.exponentialRampToValueAtTime(0.001, this.ctx.currentTime + dur);
osc.connect(gain);
gain.connect(this.masterGain);
osc.start(this.ctx.currentTime);
osc.stop(this.ctx.currentTime + dur);
return { osc, gain };
}
_ramp(freq, endFreq, type, vol, dur) {
if (!this.ctx || !this.sfxEnabled) return;
const osc = this.ctx.createOscillator();
const gain = this.ctx.createGain();
osc.type = type;
osc.frequency.setValueAtTime(freq, this.ctx.currentTime);
osc.frequency.exponentialRampToValueAtTime(Math.max(endFreq, 20), this.ctx.currentTime + dur);
gain.gain.setValueAtTime(vol, this.ctx.currentTime);
gain.gain.exponentialRampToValueAtTime(0.001, this.ctx.currentTime + dur);
osc.connect(gain);
gain.connect(this.masterGain);
osc.start(this.ctx.currentTime);
osc.stop(this.ctx.currentTime + dur);
}
jump() {
this._ramp(380, 820, 'square', 0.10, 0.08);
this._ramp(600, 1200, 'sawtooth', 0.04, 0.05);
}
die() {
this._ramp(450, 60, 'sawtooth', 0.18, 0.35);
this._ramp(200, 40, 'square', 0.09, 0.25);
this._node(80, 'sine', 0.22, 0.08);
}
win() {
const notes = [523.25, 659.25, 783.99, 1046.50];
let t = 0;
notes.forEach((f) => {
setTimeout(() => this._node(f, 'sine', 0.14, 0.14), t);
t += 200;
});
setTimeout(() => this._node(1567.98, 'sine', 0.06, 0.18), 500);
}
land() { this._ramp(120, 60, 'sine', 0.10, 0.06); }
click() {
this._node(880, 'sine', 0.09, 0.03);
this._node(1200, 'square', 0.03, 0.02);
}
portal() {
this._ramp(300, 1200, 'sine', 0.1, 0.15);
this._ramp(500, 1800, 'triangle', 0.06, 0.1);
}
orb() {
this._ramp(520, 1400, 'square', 0.09, 0.09);
this._ramp(900, 1800, 'sine', 0.05, 0.07);
}
pad() {
this._ramp(200, 950, 'sawtooth', 0.11, 0.14);
this._ramp(420, 1600, 'sine', 0.05, 0.1);
}
coin() {
this._node(987.77, 'sine', 0.1, 0.07);
setTimeout(() => this._node(1318.51, 'sine', 0.11, 0.16), 70);
}
checkpoint() {
this._node(659.25, 'triangle', 0.08, 0.07);
setTimeout(() => this._node(880, 'triangle', 0.08, 0.11), 60);
}
}
const sound = new SoundEngine();
let soundMuted = false; // 供 BGM 系统引用(保留原变量名)
// ============================================================
// BGM MUSIC SYSTEM v2 —— 前瞻调度 + 和弦对齐 + 段落演进
// 三档难度 = 三首原创:云端巡航 / 霓虹奔跑者 / 过载协议
// ============================================================
const BGM_HZ = m => 440 * Math.pow(2, (m - 69) / 12);
const bsyn = {
ready: false,
init() {
if (this.ready || !sound.ctx) return;
const c = sound.ctx;
this.bus = c.createGain(); this.bus.gain.value = 0.5;
this.bus.connect(sound.masterGain);
this.duck = c.createGain(); this.duck.connect(this.bus);
this.dl = c.createDelay(1.2);
this.fb = c.createGain(); this.fb.gain.value = 0.32;
this.dlp = c.createBiquadFilter(); this.dlp.type = 'lowpass'; this.dlp.frequency.value = 3000;
const dOut = c.createGain(); dOut.gain.value = 0.5;
this.dlIn = c.createGain();
this.dlIn.connect(this.dl); this.dl.connect(this.dlp);
this.dlp.connect(this.fb); this.fb.connect(this.dl);
this.dlp.connect(dOut); dOut.connect(this.bus);
this.nb = c.createBuffer(1, c.sampleRate * 0.6, c.sampleRate);
const d = this.nb.getChannelData(0);
for (let i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1;
this.ready = true;
},
setTempo(bpm) { if (this.ready) this.dl.delayTime.value = 0.75 * 60 / bpm; },
ok() { return this.ready && sound.bgmEnabled && !soundMuted; },
send(node, amt) {
const g = sound.ctx.createGain(); g.gain.value = amt;
node.connect(g); g.connect(this.dlIn);
},
kick(t, v) {
if (!this.ok() || !v) return; const c = sound.ctx;
const o = c.createOscillator(), g = c.createGain();
o.type = 'sine';
o.frequency.setValueAtTime(150, t);
o.frequency.exponentialRampToValueAtTime(44, t + 0.08);
g.gain.setValueAtTime(v, t);
g.gain.exponentialRampToValueAtTime(0.0001, t + 0.22);
o.connect(g); g.connect(this.bus);
o.start(t); o.stop(t + 0.24);
this.duck.gain.cancelScheduledValues(t);
this.duck.gain.setValueAtTime(0.5, t);
this.duck.gain.linearRampToValueAtTime(1, t + 0.2);
},
snare(t, v) {
if (!this.ok() || !v) return; const c = sound.ctx;
const n = c.createBufferSource(); n.buffer = this.nb; n.loop = true;
const hp = c.createBiquadFilter(); hp.type = 'highpass'; hp.frequency.value = 1700;
const g = c.createGain();
g.gain.setValueAtTime(v, t);
g.gain.exponentialRampToValueAtTime(0.0001, t + 0.13);
n.connect(hp); hp.connect(g); g.connect(this.bus);
n.start(t); n.stop(t + 0.15);
const o = c.createOscillator(), og = c.createGain();
o.type = 'triangle';
o.frequency.setValueAtTime(195, t);
o.frequency.exponentialRampToValueAtTime(150, t + 0.06);
og.gain.setValueAtTime(v * 0.6, t);
og.gain.exponentialRampToValueAtTime(0.0001, t + 0.08);
o.connect(og); og.connect(this.bus);
o.start(t); o.stop(t + 0.09);
},
clap(t, v) {
if (!this.ok() || !v) return; const c = sound.ctx;
for (let i = 0; i < 2; i++) {
const tt = t + i * 0.012;
const n = c.createBufferSource(); n.buffer = this.nb; n.loop = true;
const bp = c.createBiquadFilter(); bp.type = 'bandpass';
bp.frequency.value = 1400; bp.Q.value = 1.1;
const g = c.createGain();
g.gain.setValueAtTime(v * (i ? 1 : 0.5), tt);
g.gain.exponentialRampToValueAtTime(0.0001, tt + (i ? 0.16 : 0.03));
n.connect(bp); bp.connect(g); g.connect(this.bus);
n.start(tt); n.stop(tt + 0.18);
}
},
hat(t, v, open) {
if (!this.ok() || !v) return; const c = sound.ctx;
const n = c.createBufferSource(); n.buffer = this.nb; n.loop = true;
n.playbackRate.value = 1.3;
const hp = c.createBiquadFilter(); hp.type = 'highpass'; hp.frequency.value = 8200;
const g = c.createGain(); const d = open ? 0.22 : 0.04;
g.gain.setValueAtTime(v, t);
g.gain.exponentialRampToValueAtTime(0.0001, t + d);
n.connect(hp); hp.connect(g); g.connect(this.bus);
n.start(t); n.stop(t + d + 0.02);
},
crash(t, v) {
if (!this.ok() || !v) return; const c = sound.ctx;
const n = c.createBufferSource(); n.buffer = this.nb; n.loop = true;
const hp = c.createBiquadFilter(); hp.type = 'highpass'; hp.frequency.value = 5000;
const g = c.createGain();
g.gain.setValueAtTime(v, t);
g.gain.exponentialRampToValueAtTime(0.0001, t + 1.1);
n.connect(hp); hp.connect(g); g.connect(this.bus);
n.start(t); n.stop(t + 1.15);
},
sub(t, m, d, v) {
if (!this.ok() || !v) return; const c = sound.ctx;
const o = c.createOscillator(), g = c.createGain();
o.type = 'sine'; o.frequency.value = BGM_HZ(m);
g.gain.setValueAtTime(0.0001, t);
g.gain.linearRampToValueAtTime(v, t + 0.015);
g.gain.setValueAtTime(v, t + Math.max(0.02, d - 0.06));
g.gain.exponentialRampToValueAtTime(0.0001, t + d);
o.connect(g); g.connect(this.duck);
o.start(t); o.stop(t + d + 0.02);
},
bass(t, m, d, v, acc) {
if (!this.ok() || !v) return; const c = sound.ctx;
const lp = c.createBiquadFilter(); lp.type = 'lowpass'; lp.Q.value = 2;
lp.frequency.setValueAtTime(acc ? 2300 : 1300, t);
lp.frequency.exponentialRampToValueAtTime(240, t + Math.min(0.22, d));
const g = c.createGain();
g.gain.setValueAtTime(v, t);
g.gain.exponentialRampToValueAtTime(0.0001, t + d);
const o1 = c.createOscillator(); o1.type = 'sawtooth'; o1.frequency.value = BGM_HZ(m);
const o2 = c.createOscillator(); o2.type = 'square'; o2.frequency.value = BGM_HZ(m - 12);
const g2 = c.createGain(); g2.gain.value = 0.45;
o1.connect(lp); o2.connect(g2); g2.connect(lp);
lp.connect(g); g.connect(this.duck);
o1.start(t); o2.start(t);
o1.stop(t + d + 0.03); o2.stop(t + d + 0.03);
},
pluck(t, m, d, v) {
if (!this.ok() || !v) return; const c = sound.ctx;
const lp = c.createBiquadFilter(); lp.type = 'lowpass'; lp.Q.value = 1;
lp.frequency.setValueAtTime(4500, t);
lp.frequency.exponentialRampToValueAtTime(380, t + Math.min(0.3, d));
const g = c.createGain();
g.gain.setValueAtTime(v, t);
g.gain.exponentialRampToValueAtTime(0.0001, t + d);
const o1 = c.createOscillator(); o1.type = 'triangle'; o1.frequency.value = BGM_HZ(m);
const o2 = c.createOscillator(); o2.type = 'sawtooth'; o2.frequency.value = BGM_HZ(m);
const g2 = c.createGain(); g2.gain.value = 0.4;
o1.connect(lp); o2.connect(g2); g2.connect(lp);
lp.connect(g); g.connect(this.duck);
this.send(g, 0.16);
o1.start(t); o2.start(t);
o1.stop(t + d + 0.02); o2.stop(t + d + 0.02);
},
stab(t, ms, d, v) {
if (!this.ok() || !v) return; const c = sound.ctx;
const lp = c.createBiquadFilter(); lp.type = 'lowpass'; lp.Q.value = 1.4;
lp.frequency.setValueAtTime(2600, t);
lp.frequency.exponentialRampToValueAtTime(500, t + d);
const g = c.createGain();
g.gain.setValueAtTime(v, t);
g.gain.exponentialRampToValueAtTime(0.0001, t + d);
ms.forEach(m => {
[-7, 7].forEach(det => {
const o = c.createOscillator(); o.type = 'sawtooth';
o.frequency.value = BGM_HZ(m); o.detune.value = det;
o.connect(lp); o.start(t); o.stop(t + d + 0.02);
});
});
lp.connect(g); g.connect(this.duck);
this.send(g, 0.1);
},
lead(t, m, d, v, hard) {
if (!this.ok() || !v) return; const c = sound.ctx;
const lp = c.createBiquadFilter(); lp.type = 'lowpass';
lp.frequency.value = hard ? 3600 : 2900; lp.Q.value = 0.8;
const g = c.createGain();
g.gain.setValueAtTime(0.0001, t);
g.gain.linearRampToValueAtTime(v, t + 0.012);
g.gain.setValueAtTime(v, t + Math.max(0.02, d - 0.05));
g.gain.exponentialRampToValueAtTime(0.0001, t + d + 0.08);
const vib = c.createOscillator(); vib.frequency.value = 5.4;
const vg = c.createGain(); vg.gain.setValueAtTime(0, t);
vg.gain.linearRampToValueAtTime(d > 0.3 ? 9 : 4, t + Math.min(0.3, d * 0.6));
vib.connect(vg);
[-7, 7].forEach(det => {
const o = c.createOscillator(); o.type = 'sawtooth';
o.frequency.value = BGM_HZ(m); o.detune.value = det;
vg.connect(o.detune);
o.connect(lp); o.start(t); o.stop(t + d + 0.1);
});
vib.start(t); vib.stop(t + d + 0.1);
lp.connect(g); g.connect(this.duck);
this.send(g, 0.28);
},
pad(t, ms, d, v) {
if (!this.ok() || !v) return; const c = sound.ctx;
const lp = c.createBiquadFilter(); lp.type = 'lowpass';
lp.frequency.value = 1150; lp.Q.value = 0.5;
const g = c.createGain();
const att = Math.min(0.6, d * 0.3);
g.gain.setValueAtTime(0.0001, t);
g.gain.linearRampToValueAtTime(v, t + att);
g.gain.setValueAtTime(v, t + Math.max(att, d - 0.2));
g.gain.linearRampToValueAtTime(0.0001, t + d + 0.4);
ms.forEach(m => {
[-8, 8].forEach(det => {
const o = c.createOscillator(); o.type = 'sawtooth';
o.frequency.value = BGM_HZ(m); o.detune.value = det;
o.connect(lp); o.start(t); o.stop(t + d + 0.45);
});
});
lp.connect(g); g.connect(this.duck);
},
riser(t, d, v) {
if (!this.ok() || !v) return; const c = sound.ctx;
const n = c.createBufferSource(); n.buffer = this.nb; n.loop = true;
const hp = c.createBiquadFilter(); hp.type = 'highpass';
hp.frequency.setValueAtTime(420, t);
hp.frequency.exponentialRampToValueAtTime(5200, t + d);
const g = c.createGain();
g.gain.setValueAtTime(0.0001, t);
g.gain.exponentialRampToValueAtTime(v, t + d);
g.gain.linearRampToValueAtTime(0.0001, t + d + 0.05);
n.connect(hp); hp.connect(g); g.connect(this.bus);
n.start(t); n.stop(t + d + 0.08);
}
};
const BGM_TRACKS = [
(function() { // Easy · 云端巡航 SKYLINE CRUISE · Am F C G
const CH = [[57,60,64],[53,57,60],[60,64,67],[55,59,62]];
const RT = [33,29,36,31];
const P1 = [[0,76,3],[4,72,2],[6,74,2],[8,72,7],[16,72,3],[20,69,2],[22,67,2],[24,69,7]];
const P2 = [[0,67,3],[4,72,2],[6,74,2],[8,76,7],[16,74,3],[20,71,2],[22,67,2],[24,74,7]];
const ARP = [0,1,2,1];
return { name:'SKYLINE CRUISE 云端巡航', bpm:100, loop:32, fn(e) {
const b=e.b, s=e.s, ci=b%4, ch=CH[ci], sec=b>>3;
if (s===0) bsyn.kick(e.t, 0.4);
if (s===8 && sec>0) bsyn.kick(e.t, 0.34);
if (s===8) bsyn.clap(e.t, 0.15);
if (s%2===0) bsyn.hat(e.t, s%4===0?0.032:0.018);
if (sec>0 && s%4===2) bsyn.hat(e.t, 0.04, true);
if (b%8===7) { if (s===12) bsyn.clap(e.t,0.07); if (s===14) bsyn.clap(e.t,0.09); }
if (s===0) bsyn.sub(e.t, RT[ci], e.sd*10, 0.07);
if (s===0) bsyn.bass(e.t, RT[ci]+12, e.sd*3, 0.05);
if (s===10) bsyn.bass(e.t, RT[ci]+12, e.sd*2, 0.04);
if (s===0) bsyn.pad(e.t, ch.map(x=>x+12), e.sd*15, sec===3?0.034:0.022);
if (s%2===0 && sec!==3) bsyn.pluck(e.t, ch[ARP[(s>>1)&3]]+24, e.sd*1.6, sec===0?0.028:0.034);
if (sec===3 && s===0) bsyn.pluck(e.t, ch[2]+24, e.sd*8, 0.042);
if (sec===1 || sec===2) {
const mel = (ci<2)?P1:P2, pos=(b%2)*16+s;
for (const nt of mel) if (nt[0]===pos) {
bsyn.lead(e.t, nt[1]+(sec===2?12:0), nt[2]*e.sd, sec===2?0.032:0.048);
if (sec===2) bsyn.pluck(e.t, nt[1], nt[2]*e.sd, 0.028);
}
}
}};
})(),
(function() { // Normal · 霓虹奔跑者 NEON RUNNER · Em C G D
const CH = [[64,67,71],[60,64,67],[62,67,71],[62,66,69]];
const RT = [40,36,43,38];
const P1 = [[0,76,3],[6,79,3],[12,76,2],[16,79,3],[22,76,3],[28,72,3]];
const P2 = [[0,74,3],[6,79,3],[12,74,2],[16,78,3],[22,74,3],[28,69,3]];
const AP = [0,2,1,2];
return { name:'NEON RUNNER 霓虹奔跑者', bpm:128, loop:32, fn(e) {
const b=e.b, s=e.s, ci=b%4, ch=CH[ci];
const brk=b>=16&&b<20, bld=b>=20&&b<24, big=b>=24;
if (!brk) { if (s%4===0) bsyn.kick(e.t, 0.44); }
else if (b===16 && s===0) bsyn.kick(e.t, 0.38);
if (!brk && (s===4||s===12)) bsyn.snare(e.t, big?0.19:0.16);
if (!brk && s%4===2) bsyn.hat(e.t, big?0.055:0.04, big&&s===14);
if (!brk && s%2===1 && (big||b>=8)) bsyn.hat(e.t, 0.015);
if (bld && b===23 && s%2===0) bsyn.snare(e.t, 0.09+s*0.008);
else if (!brk && b%8===7 && s>=12 && s%2===0) bsyn.snare(e.t, 0.11);
if (big && b%4===0 && s===0) bsyn.crash(e.t, 0.11);
if (!brk) {
if (s===0) bsyn.sub(e.t, RT[ci]-12, e.sd*3.5, 0.075);
if (s%4===2) bsyn.bass(e.t, RT[ci], e.sd*1.8, 0.08);
} else if (s===0) bsyn.sub(e.t, RT[ci]-12, e.sd*15, 0.065);
if (s%2===(big?0:1)) bsyn.pluck(e.t, ch[AP[(s>>2)&3]]+12, e.sd*1.4, brk?0.028:0.024);
if ((brk||big) && s===0) bsyn.pad(e.t, ch, e.sd*15, brk?0.03:0.018);
if (b===22 && s===0) bsyn.riser(e.t, e.sd*32, 0.05);
if ((b>=8&&b<16) || big) {
const mel = ci<2?P1:P2, pos=(b%2)*16+s;
for (const nt of mel) if (nt[0]===pos) {
bsyn.lead(e.t, nt[1], nt[2]*e.sd, 0.05);
if (big) bsyn.lead(e.t, nt[1]+12, nt[2]*e.sd, 0.018);
}
}
}};
})(),
(function() { // Hard · 过载协议 OVERDRIVE PROTOCOL · Am F G E
const CH = [[57,60,64],[53,57,60],[55,59,62],[52,56,59]];
const RT = [33,29,31,28];
const MEL = [
[[0,81,2],[4,79,2],[6,81,2],[10,84,3]],
[[0,81,2],[4,77,2],[6,79,2],[10,81,3]],
[[0,79,2],[4,83,2],[6,79,2],[10,74,3]],
[[0,80,2],[4,83,2],[6,80,2],[10,76,4]],
];
const ACC = [1,0,0,0.6,0,0,1,0, 0,0.6,1,0,0,0.6,0,0];
return { name:'OVERDRIVE PROTOCOL 过载协议', bpm:150, loop:32, fn(e) {
const b=e.b, s=e.s, ci=b%4, ch=CH[ci], r=RT[ci];
const half=b>=16&&b<20, bld=b>=20&&b<24, peak=b>=24;
if (half) {
if (s===0) bsyn.kick(e.t, 0.44);
if (s===8) bsyn.snare(e.t, 0.22);
if (s%4===2) bsyn.hat(e.t, 0.045, true);
} else {
if (s%4===0) bsyn.kick(e.t, 0.44);
if (peak && s===14 && b%2===1) bsyn.kick(e.t, 0.28);
if (s===4||s===12) bsyn.snare(e.t, peak?0.21:0.18);
bsyn.hat(e.t, s%2?(peak?0.028:0.016):(s%4===0?0.045:0.03), peak&&s===10);
if (b%4===3 && s>=12) bsyn.snare(e.t, 0.07+(s-12)*0.032);
}
if (bld) {
if (s%2===0) bsyn.snare(e.t, 0.05+(b-20)*0.028+s*0.004);
if (b===20 && s===0) bsyn.riser(e.t, e.sd*64, 0.05);
}
if (s===0 && b%4===0 && (peak||b%8===0)) bsyn.crash(e.t, 0.12);
if (!half) {
const a = ACC[s];
if (a) bsyn.bass(e.t, r+12+(s===6?12:(s===10?7:0)), e.sd*(a===1?1.6:1.1), 0.07*a+0.018, a===1);
if (s===0) bsyn.sub(e.t, r, e.sd*3.5, 0.068);
} else {
if (s===0) { bsyn.sub(e.t, r, e.sd*14, 0.075); bsyn.bass(e.t, r+12, e.sd*12, 0.045); }
if (s===11) bsyn.pluck(e.t, r+25, e.sd*2, 0.038);
}
if (!half && (s===3||s===11)) bsyn.stab(e.t, ch.map(x=>x+12), e.sd*1.5, peak?0.042:0.032);
if ((b>=8&&b<16) || peak) {
for (const nt of MEL[ci]) if (nt[0]===s) {
bsyn.lead(e.t, nt[1], nt[2]*e.sd, 0.05, true);
if (peak) bsyn.lead(e.t, nt[1]-12, nt[2]*e.sd, 0.02, true);
}
}
if (half && s===0) bsyn.pad(e.t, ch, e.sd*15, 0.032);
}};
})(),
];
class BGMPlayer {
constructor(diff) {
this.playing = false;
this.step = 0;
this.nextT = 0;
this.setDifficulty(diff);
}
setDifficulty(diff) {
this.cfg = BGM_TRACKS[diff];
this.stepDur = 60 / this.cfg.bpm / 4;
if (bsyn.ready) bsyn.setTempo(this.cfg.bpm);
}
start() {
bsyn.init();
bsyn.setTempo(this.cfg.bpm);
this.playing = true;
this.step = 0;
if (sound.ctx) this.nextT = sound.ctx.currentTime + 0.08;
}
stop() { this.playing = false; }
update() {
if (!this.playing || !sound.ctx) return;
if (soundMuted || !sound.bgmEnabled) {
this.nextT = sound.ctx.currentTime + 0.06;
return;
}
bsyn.init();
const ct = sound.ctx.currentTime;
if (this.nextT < ct - 0.12) this.nextT = ct + 0.02;
let n = 0;
while (this.nextT < ct + 0.16 && n < 64) {
const s = this.step & 15;
const b = (this.step >> 4) % this.cfg.loop;
try {
this.cfg.fn({ t: this.nextT, s: s, b: b, sd: this.stepDur });
} catch (_) {}
this.step++;
this.nextT += this.stepDur;
n++;
}
}
}
// ============================================================
// 原版物理常量(换算自 GD 反编译值,单位:格/秒)
// gravity 0.958199 u/f² → 114.98 | jump 11.180032 u/f → 22.36
// ============================================================
const PHYS = {
G: 114.98, // 方块重力
VJ: 22.36, // 方块跳跃初速
MAXFALL: 26.0, // 下落终端速度
ROT: 463, // 空中旋转 °/s(180°/次跳跃)
SHIP_G: 46, // 飞船下落加速度
SHIP_DECEL: 69, // 飞船上升不按时减速
SHIP_THRUST: 62, // 飞船推力
SHIP_VMAX_UP: 16.0, // 8.0 u/f
SHIP_VMAX_DN: 12.8, // 6.4 u/f
BALL_G: 68.99, // 0.6x
UFO_VJ: 16.1, // 0.72x 跳跃
PAD_Y: 32.0, // 黄垫 16 u/f
PAD_P: 21.1, // 粉垫
PAD_B: 24.0, // 蓝垫(换重力)
ORB_Y: 22.36, // 黄球环
ORB_P: 16.3, // 粉球环 0.73x
ORB_B: 11.2, // 蓝球环(换重力冲量)
ORB_G: 22.36, // 绿球环(换重力+跳)
HAZ_HALF: 0.255, // 玩家危险判定半宽(原版内缩碰撞箱)
WAVE_HAZ: 0.20,
CEIL: 13 // 世界顶(非方块模式钳制)
};
const MODES = { CUBE: 0, SHIP: 1, BALL: 2, UFO: 3, WAVE: 4 };
const MODE_NAME = ['CUBE', 'SHIP', 'BALL', 'UFO', 'WAVE'];
const LEVEL_LEN = 640; // 32 小节 × 20 格(每拍 5 格)
const DT = 1 / 120; // 固定物理步长(确定性)
// ============================================================
// 存档
// ============================================================
const SAVE_KEY = 'gd_web_v1';
function loadSave() {
try {
const s = JSON.parse(localStorage.getItem(SAVE_KEY));
if (s && s.lv && s.lv.length === 3) return s;
} catch (_) {}
return { lv: [0,1,2].map(() => ({ best: 0, pbest: 0, att: 0, jumps: 0, coins: [false,false,false], done: false })),
opt: { music: true, sfx: true } };
}
const save = loadSave();
function persist() { try { localStorage.setItem(SAVE_KEY, JSON.stringify(save)); } catch (_) {} }
// ============================================================
// 关卡 DSL —— 每小节 20 列,节拍位于第 0/5/10/15 列
// ============================================================
function parseLevel(def) {
const L = {
name: def.name, sub: def.sub, stars: def.stars, track: def.track,
bpm: def.bpm, speed: def.bpm / 60 * 5,
length: LEVEL_LEN, colorKeys: def.colorKeys,
solids: [], cellSet: new Set(),
solidCols: new Map(), hazCols: new Map(), itemCols: new Map(),
hazards: [], items: [], portals: [], coins: [], checks: [], pits: new Set()
};
let itemId = 0, coinId = 0;
function colPush(map, c0, c1, obj) {
for (let c = Math.floor(c0); c <= Math.floor(c1); c++) {
if (!map.has(c)) map.set(c, []);
map.get(c).push(obj);
}
}
function addSolid(x0, x1, y0, y1, slab) {
const s = { x0, x1, y0, y1, slab: !!slab };
L.solids.push(s);
colPush(L.solidCols, x0, x1 - 0.001, s);
if (!slab) for (let cx = x0; cx < x1; cx++)
for (let cy = y0; cy < y1; cy++) L.cellSet.add(cx + ',' + cy);