-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStompMatch.html
More file actions
1360 lines (1272 loc) · 67.9 KB
/
StompMatch.html
File metadata and controls
1360 lines (1272 loc) · 67.9 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">
<title>StompMatch</title>
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
<style>
body{margin:0;overflow:hidden;background:#000;font-family:'Press Start 2P',monospace;color:#fff}
canvas{display:block;width:100vw;height:100vh;image-rendering:pixelated;position:fixed;top:0;left:0;z-index:0}
#ui{position:fixed;top:20px;left:0;width:100%;display:flex;justify-content:space-between;padding:0 50px;box-sizing:border-box;pointer-events:none;z-index:10}
.player-info{background:rgba(0,0,0,.8);padding:15px 25px;border:4px solid rgba(255,255,255,.7);text-align:center;box-shadow:6px 6px 0 rgba(0,0,0,.8);backdrop-filter:blur(4px)}
.player-name{font-size:.8rem;margin-bottom:15px;text-transform:uppercase;letter-spacing:2px}
.health-bar-bg{width:200px;height:30px;background:#222;border:4px solid rgba(255,255,255,.6);position:relative}
.health-bar-fill{height:100%;transition:width .2s steps(20)}
.health-bar-fill::after{content:"";position:absolute;top:0;left:0;right:0;height:40%;background:rgba(255,255,255,.3)}
.power-status{font-size:.5rem;margin-top:8px;height:12px;color:#ffff55}
#p1-name{color:#ff5555}#p1-health-fill{background:linear-gradient(90deg,#aa2222,#ff5555)}
#p2-name{color:#5555ff}#p2-health-fill{background:linear-gradient(90deg,#2222aa,#5555ff)}
#controls-overlay{position:fixed;bottom:20px;left:0;width:100%;display:flex;justify-content:space-between;padding:0 50px;box-sizing:border-box;pointer-events:none;opacity:.85;z-index:10}
.controls{background:rgba(0,0,0,.7);padding:12px;border:3px solid rgba(255,255,255,.4);font-size:.5rem;line-height:2;backdrop-filter:blur(4px)}
.controls-p1{color:#ffaaaa}.controls-p2{color:#aaaaff}
#game-over{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.85);display:none;flex-direction:column;justify-content:center;align-items:center;z-index:20;backdrop-filter:blur(6px)}
#game-over h1{font-size:3rem;margin-bottom:20px;text-shadow:6px 6px 0 #000}
#game-over button{font-family:'Press Start 2P',monospace;padding:18px 36px;font-size:1rem;background:#fff;color:#000;border:4px solid #555;cursor:pointer;pointer-events:auto;margin-top:20px;box-shadow:6px 6px 0 #000;transition:transform .1s}
#game-over button:hover{background:#ddd;transform:translate(2px,2px);box-shadow:4px 4px 0 #000}
#main-menu,#difficulty-menu,#settings-menu,#map-menu{position:fixed;top:0;left:0;width:100%;height:100%;display:flex;flex-direction:column;justify-content:center;align-items:center;z-index:30}
#main-menu{background:rgba(0,0,0,.45);backdrop-filter:blur(10px) brightness(0.7);-webkit-backdrop-filter:blur(10px) brightness(0.7)}
#difficulty-menu,#settings-menu,#map-menu{background:rgba(0,0,0,.88);display:none}
.menu-title{font-size:3.5rem;margin-bottom:40px;text-shadow:6px 6px 0 #5555ff,-6px -6px 0 #ff5555;text-align:center;line-height:1.5;animation:glitch 2s infinite}
@keyframes glitch{0%{text-shadow:6px 6px 0 #5555ff,-6px -6px 0 #ff5555;transform:translate(0)}25%{text-shadow:-4px -4px 0 #5555ff,4px 4px 0 #ff5555;transform:translate(-1px,1px)}50%{text-shadow:4px -4px 0 #5555ff,-4px 4px 0 #ff5555;transform:translate(1px,-1px)}75%{text-shadow:-4px 4px 0 #5555ff,4px -4px 0 #ff5555;transform:translate(-1px,-1px)}100%{text-shadow:6px 6px 0 #5555ff,-6px -6px 0 #ff5555;transform:translate(0)}}
.menu-btn{font-family:'Press Start 2P',monospace;padding:18px 36px;font-size:1.3rem;background:rgba(30,30,50,.9);color:#fff;border:5px solid rgba(255,255,255,.8);cursor:pointer;margin:12px;box-shadow:6px 6px 0 #000;transition:all .1s;text-transform:uppercase;letter-spacing:2px}
.menu-btn:hover{background:#fff;color:#000;transform:translate(3px,3px);box-shadow:3px 3px 0 #000}
.diff-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:16px;margin-bottom:25px}
.diff-btn{padding:18px;font-size:1.8rem}
.map-grid{display:grid;grid-template-columns:repeat(2,1fr);gap:28px;margin-bottom:28px}
.map-card{font-family:'Press Start 2P',monospace;background:rgba(15,15,30,.95);border:5px solid rgba(255,255,255,.4);padding:28px 18px;cursor:pointer;box-shadow:6px 6px 0 #000;transition:all .12s;text-align:center;min-width:190px;position:relative}
.map-card:hover{border-color:#fff;background:rgba(40,40,70,.95);transform:translate(3px,3px);box-shadow:3px 3px 0 #000}
.map-icon{font-size:2.8rem;margin-bottom:14px}
.map-name{font-size:.85rem;margin-bottom:8px;color:#fff;text-transform:uppercase;letter-spacing:1px}
.map-desc{font-size:.42rem;color:#888;line-height:2}
.map-card.theme-city{border-color:#5555ff}
.map-card.theme-city:hover{border-color:#aaaaff;box-shadow:0 0 20px rgba(80,80,255,.3),3px 3px 0 #000}
.map-card.theme-grass{border-color:#22cc55}
.map-card.theme-grass:hover{border-color:#88ffaa;box-shadow:0 0 20px rgba(30,200,80,.3),3px 3px 0 #000}
.map-card.has-dropdown{position:relative}
.dropdown-arrow{font-size:.5rem;margin-left:6px;color:#aaa;display:inline-block;transition:transform .15s}
.map-card.open .dropdown-arrow{transform:rotate(180deg)}
.map-dropdown{display:none;position:absolute;top:calc(100% + 8px);left:0;width:100%;z-index:50;box-shadow:0 8px 24px rgba(0,0,0,.8)}
.map-card.open .map-dropdown{display:block}
.map-card.theme-city .map-dropdown{background:rgba(8,8,28,.98);border:3px solid #5555ff}
.map-card.theme-grass .map-dropdown{background:rgba(4,18,8,.98);border:3px solid #22cc55}
.dropdown-option{font-family:'Press Start 2P',monospace;padding:14px 16px;cursor:pointer;border-bottom:2px solid rgba(80,80,150,.2);text-align:left;transition:background .1s}
.dropdown-option:last-child{border-bottom:none}
.theme-city .dropdown-option:hover{background:rgba(80,80,200,.3)}
.theme-grass .dropdown-option:hover{background:rgba(40,160,60,.3)}
.do-icon{font-size:1.2rem;margin-right:10px;vertical-align:middle}
.do-name{font-size:.55rem;color:#ddd;display:inline-block;vertical-align:middle}
.do-era{font-size:.38rem;color:#888;display:block;margin-top:4px;padding-left:2rem}
#settings-btn{position:fixed;bottom:28px;left:28px;font-family:'Press Start 2P',monospace;padding:12px;font-size:.9rem;background:rgba(30,30,50,.8);color:#aaa;border:3px solid #555;cursor:pointer;z-index:31;backdrop-filter:blur(4px)}
#settings-btn:hover{background:#aaa;color:#000}
.settings-panel{background:rgba(20,20,40,.95);padding:40px;border:6px solid #fff;text-align:center}
input[type=range]{-webkit-appearance:none;width:280px;background:transparent;cursor:pointer}
input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;height:22px;width:14px;background:#fff;border:3px solid #5555ff;cursor:pointer;margin-top:-6px}
input[type=range]::-webkit-slider-runnable-track{height:10px;background:#333;border:2px solid #666}
#ui,#controls-overlay,#game-over{display:none}
.credit{position:fixed;bottom:10px;right:20px;font-size:.5rem;color:#555;z-index:31;pointer-events:none}
/* ======= PAUSE MENU ======= */
#pause-menu{
position:fixed;top:0;left:0;width:100%;height:100%;
background:rgba(0,0,0,.82);
display:none;flex-direction:column;justify-content:center;align-items:center;
z-index:25;backdrop-filter:blur(8px);
}
#pause-menu .pause-box{
background:rgba(12,12,28,.97);
border:6px solid rgba(255,255,255,.85);
padding:48px 60px;
box-shadow:8px 8px 0 #000,-4px -4px 0 rgba(80,80,255,.3);
text-align:center;
}
#pause-menu .pause-title{
font-size:2.5rem;
margin-bottom:12px;
text-shadow:5px 5px 0 #5555ff,-5px -5px 0 #ff5555;
letter-spacing:3px;
animation:glitch 2s infinite;
}
#pause-menu .pause-subtitle{
font-size:.5rem;color:#666;letter-spacing:4px;margin-bottom:40px;
}
#pause-menu .pause-divider{
width:100%;height:3px;
background:linear-gradient(90deg,transparent,rgba(255,255,255,.3),transparent);
margin:20px 0 36px 0;
}
#pause-menu .menu-btn{font-size:1rem;padding:14px 32px;margin:8px;}
#pause-menu .vol-row{margin:18px 0 28px 0;}
#pause-menu .vol-row label{display:block;margin-bottom:10px;font-size:.6rem;color:#ccc;}
</style>
</head>
<body>
<audio id="bgm" src="https://raw.githubusercontent.com/Ren23447/StompMatch/main/retrolarki.mp3" loop></audio>
<canvas id="gameCanvas"></canvas>
<div id="main-menu">
<h1 class="menu-title">STOMP<br>MATCH</h1>
<button class="menu-btn" onclick="goToMapSelect('single')">Single Player</button>
<button class="menu-btn" onclick="goToMapSelect('split')">Splitscreen</button>
<button id="settings-btn" onclick="showSettings()">⚙ Settings</button>
</div>
<div id="map-menu">
<h1 style="font-size:1.8rem;margin-bottom:8px;letter-spacing:2px">SELECT MAP</h1>
<p style="font-size:.55rem;color:#777;margin-bottom:36px;letter-spacing:3px">CHOOSE YOUR BATTLEFIELD</p>
<div class="map-grid">
<div class="map-card has-dropdown theme-city" id="city-card" onclick="toggleDropdown('city-card',event)">
<div class="map-icon">🏢</div>
<div class="map-name">City <span class="dropdown-arrow">▼</span></div>
<div class="map-desc">Urban rooftops<br>Multiple eras<br>Click to choose</div>
<div class="map-dropdown" onclick="event.stopPropagation()">
<div class="dropdown-option" onclick="selectMap(0)">
<span class="do-icon">🌙</span><span class="do-name">City Night</span>
<span class="do-era">Modern Era • 4 open tiers • Balanced</span>
</div>
<div class="dropdown-option" onclick="selectMap(1)">
<span class="do-icon">🏛</span><span class="do-name">City Dusk</span>
<span class="do-era">Golden Age • 5 dense tiers • Close quarters</span>
</div>
<div class="dropdown-option" onclick="selectMap(2)">
<span class="do-icon">🌄</span><span class="do-name">City Lunar Eclipse</span>
<span class="do-era">Future Era • Wide sky islands • Precision</span>
</div>
</div>
</div>
<div class="map-card has-dropdown theme-grass" id="grass-card" onclick="toggleDropdown('grass-card',event)">
<div class="map-icon">🌿</div>
<div class="map-name">Grass Fields <span class="dropdown-arrow">▼</span></div>
<div class="map-desc">Open countryside<br>Cloud platforms<br>Click to choose</div>
<div class="map-dropdown" onclick="event.stopPropagation()">
<div class="dropdown-option" onclick="selectMap(3)">
<span class="do-icon">🌞</span><span class="do-name">Morning Meadow</span>
<span class="do-era">Dawn • Misty hills • Water edges</span>
</div>
<div class="dropdown-option" onclick="selectMap(4)">
<span class="do-icon">☀</span><span class="do-name">Noon Plains</span>
<span class="do-era">Midday • Open fields • Water edges</span>
</div>
<div class="dropdown-option" onclick="selectMap(5)">
<span class="do-icon">🌇</span><span class="do-name">Sunset Valley</span>
<span class="do-era">Dusk • Amber sky • Water edges</span>
</div>
</div>
</div>
</div>
<button class="menu-btn" onclick="showMainMenu()">Back</button>
</div>
<div id="difficulty-menu">
<h1 style="font-size:1.8rem;margin-bottom:36px;letter-spacing:2px">BOT DIFFICULTY</h1>
<div class="diff-grid">
<button class="menu-btn diff-btn" onclick="startGame('single',1)">1</button>
<button class="menu-btn diff-btn" onclick="startGame('single',2)">2</button>
<button class="menu-btn diff-btn" onclick="startGame('single',3)">3</button>
<button class="menu-btn diff-btn" onclick="startGame('single',4)">4</button>
<button class="menu-btn diff-btn" onclick="startGame('single',5)">5</button>
<button class="menu-btn diff-btn" onclick="startGame('single',6)">6</button>
<button class="menu-btn diff-btn" onclick="startGame('single',7)">7</button>
<button class="menu-btn diff-btn" onclick="startGame('single',8)">8</button>
<button class="menu-btn diff-btn" onclick="startGame('single',9)">9</button>
</div>
<button class="menu-btn" onclick="showMapMenu()">Back</button>
</div>
<div id="settings-menu">
<div class="settings-panel">
<h1 style="font-size:1.6rem;margin-bottom:24px">SETTINGS</h1>
<div style="margin:28px 0">
<label style="display:block;margin-bottom:12px;font-size:.9rem">Volume: <span id="vol-display">50</span>%</label>
<input type="range" id="vol-slider" min="0" max="100" value="50" oninput="updateVolume(this.value)">
</div>
<button class="menu-btn" onclick="showMainMenu()">Back</button>
</div>
</div>
<!-- PAUSE MENU -->
<div id="pause-menu">
<div class="pause-box">
<div class="pause-title">PAUSED</div>
<div class="pause-subtitle">PRESS ESC TO RESUME</div>
<div class="pause-divider"></div>
<div class="vol-row">
<label>Volume: <span id="pause-vol-display">50</span>%</label>
<input type="range" id="pause-vol-slider" min="0" max="100" value="50" oninput="updateVolumePause(this.value)">
</div>
<button class="menu-btn" onclick="resumeGame()">▶ Resume</button>
<button class="menu-btn" onclick="location.reload()">↻ Main Menu</button>
</div>
</div>
<div id="ui">
<div class="player-info"><div id="p1-name" class="player-name">Player 1</div><div class="health-bar-bg"><div id="p1-health-fill" class="health-bar-fill"></div></div><div id="p1-power" class="power-status"></div></div>
<div class="player-info"><div id="p2-name" class="player-name">Player 2</div><div class="health-bar-bg"><div id="p2-health-fill" class="health-bar-fill"></div></div><div id="p2-power" class="power-status"></div></div>
</div>
<div id="controls-overlay">
<div class="controls controls-p1">P1: WASD | W=Jump | F=Power</div>
<div class="controls controls-p2">P2: Arrows | UP=Jump | L=Power</div>
</div>
<div id="game-over">
<h1 id="winner-text">Game Over</h1>
<button onclick="playAgain()">▶ Play Again</button>
<button onclick="location.reload()">↻ Main Menu</button>
</div>
<div class="credit">Created by Ren Hatsune</div>
<script>
/* ======= AUDIO ======= */
const audioCtx=new(window.AudioContext||window.webkitAudioContext)();
function playTone(f,t,d,v,fe){if(audioCtx.state==='suspended')audioCtx.resume();const o=audioCtx.createOscillator(),g=audioCtx.createGain();o.type=t;o.connect(g);g.connect(audioCtx.destination);o.frequency.setValueAtTime(f,audioCtx.currentTime);if(fe)o.frequency.exponentialRampToValueAtTime(fe,audioCtx.currentTime+d);g.gain.setValueAtTime(v*masterVolume*2,audioCtx.currentTime);g.gain.exponentialRampToValueAtTime(0.01,audioCtx.currentTime+d);o.start();o.stop(audioCtx.currentTime+d);}
function playJump(){playTone(200,'triangle',.15,.05,400);}
function playDmg(){playTone(150,'sawtooth',.2,.1,50);}
function playPick(){playTone(600,'sine',.1,.05,1200);setTimeout(()=>playTone(800,'sine',.2,.05,1600),100);}
/* ======= DROPDOWN ======= */
const DROPDOWNS=['city-card','grass-card'];
function toggleDropdown(id,e){
e.stopPropagation();
const open=document.getElementById(id).classList.contains('open');
DROPDOWNS.forEach(d=>document.getElementById(d).classList.remove('open'));
if(!open) document.getElementById(id).classList.add('open');
}
document.addEventListener('click',()=>DROPDOWNS.forEach(d=>document.getElementById(d)&&document.getElementById(d).classList.remove('open')));
/* ======= STATE ======= */
let masterVolume=0.5,gameMode='split',botDiff=1,gameStarted=false,pendingMode='split',selectedMap=0;
let isPaused=false;
function updateVolume(v){
masterVolume=v/100;
document.getElementById('vol-display').innerText=v;
document.getElementById('pause-vol-display').innerText=v;
document.getElementById('pause-vol-slider').value=v;
const b=document.getElementById('bgm');if(b)b.volume=masterVolume*0.6;
}
function updateVolumePause(v){
masterVolume=v/100;
document.getElementById('pause-vol-display').innerText=v;
document.getElementById('vol-display').innerText=v;
document.getElementById('vol-slider').value=v;
const b=document.getElementById('bgm');if(b)b.volume=masterVolume*0.6;
}
const ALL_SCREENS=['main-menu','difficulty-menu','settings-menu','map-menu'];
function hideAll(){ALL_SCREENS.forEach(id=>document.getElementById(id).style.display='none');}
function showMainMenu(){hideAll();document.getElementById('main-menu').style.display='flex';}
function showSettings(){hideAll();document.getElementById('settings-menu').style.display='flex';}
function showMapMenu(){hideAll();document.getElementById('map-menu').style.display='flex';DROPDOWNS.forEach(d=>document.getElementById(d)&&document.getElementById(d).classList.remove('open'));}
function showDifficultyMenu(){hideAll();document.getElementById('difficulty-menu').style.display='flex';}
function goToMapSelect(m){pendingMode=m;showMapMenu();}
function selectMap(id){
selectedMap=id;
DROPDOWNS.forEach(d=>document.getElementById(d)&&document.getElementById(d).classList.remove('open'));
if(pendingMode==='single')showDifficultyMenu();else startGame('split');
}
/* ======= PAUSE ======= */
function pauseGame(){
if(!gameStarted||isGameOver)return;
isPaused=true;
document.getElementById('pause-menu').style.display='flex';
const bgm=document.getElementById('bgm');if(bgm)bgm.pause();
}
function resumeGame(){
isPaused=false;
document.getElementById('pause-menu').style.display='none';
const bgm=document.getElementById('bgm');if(bgm)bgm.play().catch(()=>{});
requestAnimationFrame(gameLoop);
}
window.addEventListener('keydown',function(e){
if(e.code==='Escape'&&gameStarted&&!isGameOver){
if(isPaused)resumeGame();
else pauseGame();
}
});
function startGame(mode,diff=1){
gameMode=mode;botDiff=diff;
hideAll();
['ui','controls-overlay'].forEach(id=>document.getElementById(id).style.display='flex');
document.getElementById('gameCanvas').style.display='block';
document.getElementById('game-over').style.display='none';
document.getElementById('pause-menu').style.display='none';
isPaused=false;
platforms=MAPS[selectedMap];
initCloudPlatforms(selectedMap);
initWaterZones(selectedMap);
if(gameMode==='single'){document.querySelector('.controls-p2').style.display='none';document.getElementById('p2-name').innerText='BOT LVL '+botDiff;p2.isBot=true;}
else{document.querySelector('.controls-p2').style.display='';document.getElementById('p2-name').innerText='Player 2';p2.isBot=false;}
for(let p of[p1,p2]){p.x=p.spawnX;p.y=p.spawnY;p.vx=p.vy=0;p.health=100;p.powerup=null;p.weapon=null;p.inv=0;p.jumps=0;p.grounded=false;p.camX=undefined;p.camY=undefined;p.inWater=false;p.waterDmgT=0;}
particles.length=0;projectiles.length=0;items.length=0;isGameOver=false;
splitAngle=Math.PI/2; splitAngleVel=0;
if(audioCtx.state==='suspended')audioCtx.resume();
const bgm=document.getElementById('bgm');if(bgm){bgm.volume=masterVolume*0.6;bgm.play().catch(()=>{});}
gameStarted=true;requestAnimationFrame(gameLoop);
}
function playAgain(){
document.getElementById('game-over').style.display='none';
startGame(gameMode,botDiff);
}
/* ======= CANVAS ======= */
const canvas=document.getElementById('gameCanvas');
const ctx=canvas.getContext('2d');
let W=canvas.width=window.innerWidth,H=canvas.height=window.innerHeight;
window.addEventListener('resize',()=>{W=canvas.width=window.innerWidth;H=canvas.height=window.innerHeight;});
ctx.imageSmoothingEnabled=false;
const keys={};
window.addEventListener('keydown',e=>{keys[e.code]=true;if(['ArrowUp','ArrowDown','ArrowLeft','ArrowRight',' '].includes(e.key))e.preventDefault();});
window.addEventListener('keyup',e=>keys[e.code]=false);
/* ======= PARTICLES ======= */
class Particle{
constructor(x,y,col){this.x=x;this.y=y;this.col=col;this.vx=(Math.random()-.5)*10;this.vy=(Math.random()-.5)*10-2;this.life=1;this.decay=Math.random()*.05+.02;this.sz=Math.floor(Math.random()*7+3);}
update(){this.x+=this.vx;this.y+=this.vy;this.vy+=.2;this.life-=this.decay;}
draw(c){c.globalAlpha=Math.max(0,this.life);c.fillStyle='#000';c.fillRect(this.x-2,this.y-2,this.sz+4,this.sz+4);c.fillStyle=this.col;c.fillRect(this.x,this.y,this.sz,this.sz);c.globalAlpha=1;}
}
let particles=[];
function spawnParts(x,y,col,n){for(let i=0;i<n;i++)particles.push(new Particle(x,y,col));}
/* ======= CLOUD PLATFORMS ======= */
const CLOUD_STAND_FRAMES=90;
const CLOUD_GONE_FRAMES=900;
class CloudPlatform{
constructor(x,y,w){
this.x=x;this.y=y;this.w=w;this.h=18;
this.width=w;this.height=18;
this.style='cloud';
this.state='solid';
this.alpha=1;
this.standFrames=0;
this.goneTimer=0;
}
update(activePlayers){
let anyOn=false;
if(this.state==='solid'){
for(let p of activePlayers){
if(p.health<=0)continue;
if(p.x+p.w>this.x&&p.x<this.x+this.w&&Math.abs((p.y+p.h)-this.y)<5&&p.vy>=0){anyOn=true;break;}
}
if(anyOn){this.standFrames++; if(this.standFrames>=CLOUD_STAND_FRAMES)this.state='fading';}
else this.standFrames=Math.max(0,this.standFrames-2);
} else if(this.state==='fading'){
this.alpha-=0.025;
if(this.alpha<=0){this.alpha=0;this.state='gone';this.goneTimer=0;this.standFrames=0;}
} else if(this.state==='gone'){
this.goneTimer++;
if(this.goneTimer>=CLOUD_GONE_FRAMES)this.state='rising';
} else if(this.state==='rising'){
this.alpha+=0.018;
if(this.alpha>=1){this.alpha=1;this.state='solid';}
}
this.width=this.state==='gone'?0:this.w;
this.height=this.state==='gone'?0:18;
}
isSolid(){return (this.state==='solid'||this.state==='fading')&&this.alpha>0.3;}
draw(c){
if(this.state==='gone')return;
c.globalAlpha=this.alpha;
const x=this.x,y=this.y,w=this.w;
if(this.state==='solid'&&this.standFrames>CLOUD_STAND_FRAMES*0.75){
if(Math.floor(Date.now()/120)%2===0)c.globalAlpha=this.alpha*0.6;
}
const puff=(px,py,pw,ph)=>{
c.fillStyle='#1a1a2a';c.fillRect(px+3,py+3,pw,ph);
c.fillStyle='rgba(180,220,255,0.85)';c.fillRect(px,py,pw,ph);
c.fillStyle='rgba(255,255,255,0.9)';c.fillRect(px,py,pw,ph*0.4);
c.fillStyle='rgba(140,190,240,0.7)';c.fillRect(px,py+ph*0.65,pw,ph*0.35);
};
const pu=Math.floor(w/3);
puff(x,y,pu*2,this.h);
puff(x+pu,y-8,pu*2,this.h+2);
puff(x+pu*2,y,pu,this.h-2);
c.strokeStyle='rgba(100,160,220,0.6)';c.lineWidth=2;
c.strokeRect(x,y,w,this.h);
c.globalAlpha=1;
}
}
let cloudPlatforms=[];
// FIXED: Clouds placed much higher (y values reduced significantly) so they're in the sky
// and not in the middle of platforms. Typical platform range is y 295-620, so clouds go at y 60-180.
const CLOUD_DEFS={
3:[{x:-820,y:160,w:128},{x:-400,y:100,w:96},{x:-80,y:130,w:112},{x:340,y:90,w:96},{x:720,y:150,w:128},{x:1100,y:110,w:96}],
4:[{x:-960,y:140,w:144},{x:-480,y:80,w:112},{x:0,y:120,w:128},{x:480,y:70,w:96},{x:900,y:140,w:128},{x:1200,y:100,w:112}],
5:[{x:-880,y:170,w:112},{x:-320,y:110,w:128},{x:160,y:80,w:96},{x:600,y:150,w:112},{x:1000,y:90,w:128},{x:1280,y:160,w:96}]
};
function initCloudPlatforms(mapId){
cloudPlatforms=[];
const defs=CLOUD_DEFS[mapId];
if(defs)for(let d of defs)cloudPlatforms.push(new CloudPlatform(d.x,d.y,d.w));
}
function getEffectivePlats(){
const clouds=cloudPlatforms.filter(c=>c.isSolid());
return [...platforms,...clouds];
}
/* ======= WATER ZONES ======= */
// Water zones sit at ground level at the LEFT and RIGHT edges of the map.
// Ground ends at x=-1600 (left) and x=1600 (right). Water fills the 100px gap on each side
// between the ground edge and the map boundary (xMin=-1700, xMax=1700), plus extends inward.
// Players can walk off the ground edge and wade into water on either side equally.
// A solid waterfloor platform at the bottom of each zone stops players from sinking through.
const WATER_SURF_Y=800;
const WATER_DEPTH=300;
const WATER_ZONES_GRASS=[
{x:-1700,y:WATER_SURF_Y,w:200,h:WATER_DEPTH},
{x:1500,y:WATER_SURF_Y,w:200,h:WATER_DEPTH}
];
let waterZones=[];
// Water collision platforms — prevent falling through water on right side
let waterPlatforms=[];
function initWaterZones(mapId){
if(mapId>=3){
waterZones=WATER_ZONES_GRASS.map(z=>({...z}));
// Create invisible solid floor at the bottom of each water zone
waterPlatforms=WATER_ZONES_GRASS.map(z=>({
x:z.x, y:z.y+z.h-10, width:z.w, height:20, style:'waterfloor'
}));
// Also create solid side walls for each water zone so players can't fall out the sides
// Create a thin solid platform at the water surface that acts as a trigger zone
} else {
waterZones=[];
waterPlatforms=[];
}
}
function isGrassMap(id){return id>=3&&id<=5;}
function getEffectivePlatsWithWater(){
const base=getEffectivePlats();
return [...base,...waterPlatforms];
}
function updateWater(players){
for(let p of players){
p.inWater=false;
for(let wz of waterZones){
if(p.x+p.w>wz.x&&p.x<wz.x+wz.w&&p.y+p.h>wz.y&&p.y<wz.y+wz.h){
p.inWater=true;
if(p.vy>0)p.vy*=0.55;
if(p.y>wz.y+10)p.vy-=0.18;
if(p.vy>2.5)p.vy=2.5;
p.vx*=0.82;
// Keep player from going below water bottom
const waterBottom=wz.y+wz.h-20;
if(p.y+p.h>waterBottom){p.y=waterBottom-p.h;p.vy=Math.min(p.vy,-0.5);}
p.jumps=Math.min(p.jumps,1);
p.waterDmgT=(p.waterDmgT||0)+1;
if(p.waterDmgT>=90){p.waterDmgT=0;p.takeDmg(5);}
}
}
if(!p.inWater)p.waterDmgT=0;
}
}
function drawWater(c,camX,camY,vx,vy,vw,vh){
if(!waterZones.length)return;
const t=Date.now()/800;
for(let wz of waterZones){
const sx=vx+(wz.x-camX),sy=vy+(wz.y-camY);
if(sx+wz.w<vx||sx>vx+vw)continue;
c.fillStyle='rgba(30,100,200,0.72)';c.fillRect(sx,sy,wz.w,wz.h);
c.fillStyle='rgba(60,160,255,0.3)';
for(let row=0;row<wz.h;row+=12){c.fillRect(sx,sy+row,wz.w,5);}
c.fillStyle='rgba(120,200,255,0.85)';
for(let wx=0;wx<wz.w;wx+=8){
const wave=Math.floor(Math.sin(t+wx*0.4)*3);
c.fillRect(sx+wx,sy+wave,8,5);
}
c.fillStyle='rgba(180,230,255,0.5)';c.fillRect(sx,sy,wz.w,3);
c.fillStyle='rgba(255,255,255,0.4)';
for(let bx=0;bx<wz.w;bx+=14){
const by=Math.floor(Math.sin(t*1.3+bx)*4);
c.fillRect(sx+bx,sy+4+by,4,4);
}
c.fillStyle='rgba(255,80,80,0.6)';
c.fillRect(sx+wz.w/2-20,sy+25,40,6);
c.fillRect(sx+wz.w/2-20,sy+37,40,6);
}
}
/* ======= PLAYER ======= */
class Player{
constructor(x,y,col,ctrl,name){
this.spawnX=x;this.spawnY=y;this.x=x;this.y=y;
this.w=40;this.h=40;this.width=40;this.height=40;
this.col=col;this.vx=0;this.vy=0;
this.speed=6;this.jumpForce=13;this.gravity=0.5;
this.grounded=false;this.jumps=0;this.maxJumps=2;this.wallJumped=false;
this.ctrl=ctrl;this.health=100;this.faceR=true;this.name=name;
this.jkp=false;this.pkp=false;this.inv=0;
this.powerup=null;this.powerupT=0;this.weapon=null;this.weaponT=0;
this.isBot=false;this.bL=false;this.bR=false;this.bJ=false;this.bP=false;this.bW=0;
this.camX=undefined;this.camY=undefined;
this.inWater=false;this.waterDmgT=0;
}
botUpdate(tgt,plats,itms,diff){
let sm=0.1+(diff-1)*0.1;
if(this.bW>0){this.bW--;this.bL=this.bR=this.bJ=this.bP=false;return;}
if(Math.random()>sm*.8+.2){this.bW=Math.floor(Math.random()*(20-diff*2+2));return;}
let to=tgt;
if(sm>.4&&itms.length>0){let ci=null,md=Infinity;for(let it of itms){let d=Math.hypot(it.x-this.x,it.y-this.y);if(d<md){md=d;ci=it;}}if(md<Math.hypot(tgt.x-this.x,tgt.y-this.y)||(this.health<50&&ci&&ci.type==='health'))to=ci;}
let tx=to.x+(to.w||0)/2,ty=to.y+(to.h||0)/2;
if(diff>=7&&to===tgt){tx+=tgt.vx*15;ty+=tgt.vy*15;}
let dx=tx-(this.x+this.w/2),dy=ty-(this.y+this.h/2);
this.bL=this.bR=this.bJ=this.bP=false;
if(dx>20)this.bR=true;else if(dx<-20)this.bL=true;
if(dy<-30){if(this.grounded&&Math.random()<sm)this.bJ=true;else if(!this.grounded&&this.vy>0&&this.jumps<this.maxJumps&&Math.random()<sm)this.bJ=true;}
if((this.bL||this.bR)&&Math.abs(this.vx)<.5&&this.grounded&&Math.random()<sm)this.bJ=true;
if(this.weapon==='blaster'&&Math.random()<sm*.5&&Math.abs(dy)<40&&((this.faceR&&dx>0)||(!this.faceR&&dx<0)))this.bP=true;
}
update(plats){
if(this.health<=0)return;
if(this.inv>0)this.inv--;
if(this.powerupT>0)this.powerupT--;else this.powerup=null;
if(this.weaponT>0)this.weaponT--;else this.weapon=null;
let sp=this.speed*(this.powerup==='speed'?1.5:1);
let L=this.isBot?this.bL:keys[this.ctrl.left];
let R=this.isBot?this.bR:keys[this.ctrl.right];
let J=this.isBot?this.bJ:keys[this.ctrl.jump];
let P=this.isBot?this.bP:keys[this.ctrl.power];
if(L){this.vx-=1.5;this.faceR=false;}else if(R){this.vx+=1.5;this.faceR=true;}else this.vx*=.8;
this.vx=Math.max(-sp,Math.min(sp,this.vx));
let onLW=false,onRW=false;
for(let p of plats){if(p.style==='cloud'&&!p.isSolid&&!p.isSolid())continue;if(this.y<p.y+p.height&&this.y+this.h>p.y){if(Math.abs(this.x+this.w-p.x)<6)onRW=true;if(Math.abs(this.x-(p.x+p.width))<6)onLW=true;}}
if(J&&!this.jkp){
if(this.grounded||this.jumps<this.maxJumps||this.inWater){this.vy=-this.jumpForce;this.grounded=false;this.jumps++;this.jkp=true;spawnParts(this.x+this.w/2,this.y+this.h,'#fff',5);playJump();}
else if((onLW||onRW)&&!this.wallJumped){this.vy=-this.jumpForce;this.vx=onLW?this.speed:-this.speed;this.wallJumped=true;this.jkp=true;spawnParts(this.x+(onLW?0:this.w),this.y+this.h/2,'#fff',8);playJump();}
}
if(!J)this.jkp=false;
if(P&&!this.pkp){this.usePower();this.pkp=true;}
if(!P)this.pkp=false;
if(!this.inWater)this.vy+=this.gravity;
else this.vy+=this.gravity*0.2;
this.x+=this.vx;this.doCol(plats,true);
this.y+=this.vy;this.grounded=false;this.doCol(plats,false);
if(this.grounded)this.wallJumped=false;
const xMin=isGrassMap(selectedMap)?-1700:-1600;
const xMax=isGrassMap(selectedMap)?1700:1560;
this.x=Math.max(xMin,Math.min(xMax,this.x));
if(this.y>3000){this.takeDmg(20);this.x=this.spawnX;this.y=this.spawnY;this.vx=this.vy=0;}
}
usePower(){if(this.weapon==='blaster'){projectiles.push(new Proj(this.x+(this.faceR?this.w:0),this.y+this.h/2,this.faceR?15:-15,this.col,this.name));spawnParts(this.x+this.w/2,this.y+this.h/2,'#fff',5);}}
takeDmg(amt){
if(this.inv>0)return;
if(this.powerup==='shield'){this.powerup=null;this.powerupT=0;this.inv=60;spawnParts(this.x+20,this.y+20,'#fff',20);playDmg();return;}
this.health=Math.max(0,this.health-amt);this.inv=30;spawnParts(this.x+20,this.y+20,this.col,15);playDmg();
}
doCol(plats,horiz){
for(let p of plats){
if(p.style==='waterfloor')continue; // water floors handled by updateWater
if(p.style==='cloud'&&p.isSolid&&!p.isSolid())continue;
if(this.x<p.x+p.width&&this.x+this.w>p.x&&this.y<p.y+p.height&&this.y+this.h>p.y){
if(horiz){if(this.vx>0)this.x=p.x-this.w;else if(this.vx<0)this.x=p.x+p.width;this.vx=0;}
else{if(this.vy>0){this.y=p.y-this.h;this.grounded=true;this.jumps=0;}else if(this.vy<0)this.y=p.y+p.height;this.vy=0;}
}
}
}
draw(c){
if(this.health<=0)return;
if(this.inv>0&&Math.floor(Date.now()/100)%2===0)c.globalAlpha=.5;
if(this.powerup==='shield'){c.strokeStyle='#55ffff';c.lineWidth=4;c.strokeRect(this.x-8,this.y-8,this.w+16,this.h+16);}
if(this.weapon==='blaster'){let gx=this.faceR?this.x+this.w:this.x-15;c.fillStyle='#aaa';c.fillRect(gx,this.y+20,15,8);c.strokeStyle='#000';c.lineWidth=2;c.strokeRect(gx,this.y+20,15,8);}
if(this.inWater){c.strokeStyle='rgba(100,180,255,0.5)';c.lineWidth=3;c.strokeRect(this.x-4,this.y-4,this.w+8,this.h+8);}
c.fillStyle='rgba(0,0,0,.5)';c.fillRect(this.x+6,this.y+6,this.w,this.h);
c.fillStyle='#000';c.fillRect(this.x-4,this.y-4,this.w+8,this.h+8);
c.fillStyle=this.col;c.fillRect(this.x,this.y,this.w,this.h);
c.fillStyle='rgba(255,255,255,.4)';c.fillRect(this.x,this.y,this.w,8);c.fillRect(this.x,this.y,8,this.h);
c.fillStyle='#fff';let ex=this.faceR?18:6;c.fillRect(this.x+ex,this.y+10,8,12);c.fillRect(this.x+ex+12,this.y+10,8,12);
c.fillStyle='#000';let px=this.faceR?4:0;c.fillRect(this.x+ex+px,this.y+14,4,4);c.fillRect(this.x+ex+12+px,this.y+14,4,4);
c.globalAlpha=1;
}
}
/* ======= PROJECTILE ======= */
class Proj{
constructor(x,y,vx,col,owner){this.x=x;this.y=y;this.vx=vx;this.width=12;this.height=8;this.col=col;this.owner=owner;this.life=100;}
update(plats,players){
this.x+=this.vx;this.life--;
for(let p of plats)if(this.x<p.x+p.width&&this.x+this.width>p.x&&this.y<p.y+p.height&&this.y+this.height>p.y)this.life=0;
for(let p of players)if(p.name!==this.owner&&p.health>0&&this.x<p.x+p.w&&this.x+this.width>p.x&&this.y<p.y+p.h&&this.y+this.height>p.y){p.takeDmg(10);this.life=0;}
}
draw(c){c.fillStyle='#000';c.fillRect(this.x-2,this.y-2,this.width+4,this.height+4);c.fillStyle=this.col;c.fillRect(this.x,this.y,this.width,this.height);}
}
/* ======= ITEM ======= */
class Item{
constructor(x,y,type){this.x=x;this.y=y;this.w=30;this.h=30;this.width=30;this.height=30;this.type=type;this.bob=0;}
update(){this.bob=Math.sin(Date.now()/200)*8;}
draw(c){
let dy=this.y+this.bob;
c.fillStyle='rgba(0,0,0,.5)';c.fillRect(this.x+4,dy+4,this.w,this.h);
c.fillStyle='#000';c.fillRect(this.x-4,dy-4,this.w+8,this.h+8);
c.fillStyle='#12122a';c.fillRect(this.x,dy,this.w,this.h);
const ps=3,cx=this.x+this.w/2,cy=dy+this.h/2;
const dp=(pts,col)=>{c.fillStyle=col;for(let p of pts)c.fillRect(cx+p[0]*ps-ps/2,cy+p[1]*ps-ps/2,ps,ps);};
if(this.type==='health')dp([[-2,-2],[-1,-3],[0,-2],[1,-3],[2,-2],[-2,-1],[-1,-1],[0,-1],[1,-1],[2,-1],[-1,0],[0,0],[1,0],[0,1]],'#ff3333');
if(this.type==='shield')dp([[-2,-2],[-1,-2],[0,-2],[1,-2],[2,-2],[-2,-1],[-1,-1],[0,-1],[1,-1],[2,-1],[-2,0],[-1,0],[0,0],[1,0],[2,0],[-1,1],[0,1],[1,1],[0,2]],'#33ccff');
if(this.type==='speed')dp([[0,-3],[1,-3],[-1,-2],[0,-2],[-2,-1],[-1,-1],[0,-1],[-1,0],[0,0],[-2,1],[-1,1],[-2,2]],'#ffff33');
if(this.type==='blaster'){dp([[-2,-1],[-1,-1],[0,-1],[1,-1],[2,-1],[-2,0],[-1,0],[0,0],[-2,1]],'#aaaaaa');dp([[3,-1]],'#ff3333');}
c.fillStyle='rgba(255,255,255,.2)';c.fillRect(this.x,dy,this.w,7);
}
}
let projectiles=[],items=[];
const itemTypes=['health','shield','speed','blaster'];
function spawnItem(){
if(!platforms||items.length>=6)return;
const inner=platforms.filter(p=>p.height<80&&p.style!=='water'&&p.style!=='hill');
if(!inner.length)return;
const pl=inner[Math.floor(Math.random()*inner.length)];
items.push(new Item(pl.x+Math.random()*Math.max(0,pl.width-30),pl.y-55,itemTypes[Math.floor(Math.random()*4)]));
}
setInterval(spawnItem,4000);
/* ======= MAP DATA ======= */
const BW=32,BH=16;
const EDGE_WALLS=[
{x:-1680,y:-800,width:80,height:1760,style:'wall'},
{x:1600,y:-800,width:80,height:1760,style:'wall'},
];
const MAP0=[
{x:-1600,y:800,width:BW*100,height:BH*5},
{x:-1280,y:656,width:BW*8,height:BH*2},{x:-896,y:640,width:BW*6,height:BH*2},
{x:-576,y:656,width:BW*7,height:BH*2},{x:-192,y:640,width:BW*10,height:BH*2},
{x:192,y:640,width:BW*10,height:BH*2},{x:512,y:656,width:BW*7,height:BH*2},
{x:848,y:640,width:BW*6,height:BH*2},{x:1152,y:656,width:BW*8,height:BH*2},
{x:-1120,y:496,width:BW*6,height:BH*2},{x:-752,y:480,width:BW*7,height:BH*2},
{x:-384,y:496,width:BW*6,height:BH*2},{x:-64,y:464,width:BW*11,height:BH*2},
{x:384,y:496,width:BW*6,height:BH*2},{x:672,y:480,width:BW*7,height:BH*2},{x:992,y:496,width:BW*6,height:BH*2},
{x:-960,y:352,width:BW*5,height:BH*2},{x:-640,y:336,width:BW*6,height:BH*2},
{x:-288,y:352,width:BW*6,height:BH*2},{x:32,y:320,width:BW*8,height:BH*2},
{x:352,y:352,width:BW*6,height:BH*2},{x:608,y:336,width:BW*6,height:BH*2},{x:864,y:352,width:BW*5,height:BH*2},
{x:-736,y:208,width:BW*5,height:BH*2},{x:-416,y:192,width:BW*5,height:BH*2},
{x:-112,y:176,width:BW*7,height:BH*2},{x:240,y:192,width:BW*5,height:BH*2},{x:560,y:208,width:BW*5,height:BH*2},
...EDGE_WALLS
];
const MAP1=[
{x:-1600,y:800,width:BW*100,height:BH*5},
{x:-1408,y:720,width:BW*4,height:BH*2},{x:-1120,y:720,width:BW*4,height:BH*2},
{x:-832,y:720,width:BW*4,height:BH*2},{x:-544,y:720,width:BW*4,height:BH*2},
{x:-256,y:720,width:BW*4,height:BH*2},{x:32,y:720,width:BW*4,height:BH*2},
{x:320,y:720,width:BW*4,height:BH*2},{x:608,y:720,width:BW*4,height:BH*2},
{x:896,y:720,width:BW*4,height:BH*2},{x:1184,y:720,width:BW*4,height:BH*2},
{x:-1248,y:576,width:BW*7,height:BH*2},{x:-800,y:560,width:BW*8,height:BH*2},
{x:-320,y:576,width:BW*7,height:BH*2},{x:96,y:544,width:BW*9,height:BH*2},
{x:512,y:576,width:BW*7,height:BH*2},{x:896,y:560,width:BW*7,height:BH*2},
{x:-1056,y:416,width:BW*6,height:BH*2},{x:-640,y:400,width:BW*7,height:BH*2},
{x:-224,y:416,width:BW*7,height:BH*2},{x:192,y:384,width:BW*8,height:BH*2},
{x:576,y:416,width:BW*7,height:BH*2},{x:864,y:400,width:BW*6,height:BH*2},
{x:-896,y:256,width:BW*5,height:BH*2},{x:-512,y:240,width:BW*6,height:BH*2},
{x:-128,y:224,width:BW*7,height:BH*2},{x:256,y:240,width:BW*6,height:BH*2},{x:576,y:256,width:BW*5,height:BH*2},
{x:-416,y:112,width:BW*5,height:BH*2},{x:0,y:96,width:BW*6,height:BH*2},{x:352,y:112,width:BW*5,height:BH*2},
...EDGE_WALLS
];
const MAP2=[
{x:-1600,y:800,width:BW*100,height:BH*5},
{x:-1440,y:640,width:BW*12,height:BH*2},{x:-752,y:624,width:BW*12,height:BH*2},
{x:256,y:624,width:BW*12,height:BH*2},{x:944,y:640,width:BW*12,height:BH*2},
{x:-1200,y:464,width:BW*10,height:BH*2},{x:-320,y:448,width:BW*14,height:BH*2},{x:608,y:464,width:BW*10,height:BH*2},
{x:-832,y:304,width:BW*8,height:BH*2},{x:-128,y:288,width:BW*10,height:BH*2},{x:576,y:304,width:BW*8,height:BH*2},
{x:-480,y:144,width:BW*8,height:BH*2},{x:160,y:128,width:BW*8,height:BH*2},
...EDGE_WALLS
];
const MAP3=[
{x:-1600,y:800,width:BW*100,height:BH*5,style:'grass-ground'},
{x:-1500,y:750,width:BW*12,height:BH*3,style:'hill'},
{x:-960,y:762,width:BW*8,height:BH*3,style:'hill'},
{x:-320,y:755,width:BW*10,height:BH*3,style:'hill'},
{x:280,y:760,width:BW*9,height:BH*3,style:'hill'},
{x:820,y:754,width:BW*11,height:BH*3,style:'hill'},
{x:1380,y:762,width:BW*8,height:BH*3,style:'hill'},
{x:-1300,y:620,width:BW*11,height:BH*2,style:'grass'},
{x:-740,y:608,width:BW*10,height:BH*2,style:'grass'},
{x:-120,y:620,width:BW*12,height:BH*2,style:'grass'},
{x:480,y:608,width:BW*10,height:BH*2,style:'grass'},
{x:1060,y:620,width:BW*9,height:BH*2,style:'grass'},
{x:-1080,y:460,width:BW*8,height:BH*2,style:'grass'},
{x:-480,y:445,width:BW*9,height:BH*2,style:'grass'},
{x:96,y:460,width:BW*8,height:BH*2,style:'grass'},
{x:640,y:445,width:BW*9,height:BH*2,style:'grass'},
{x:1120,y:460,width:BW*7,height:BH*2,style:'grass'},
{x:-900,y:310,width:BW*6,height:BH*2,style:'grass'},
{x:-380,y:295,width:BW*7,height:BH*2,style:'grass'},
{x:180,y:310,width:BW*6,height:BH*2,style:'grass'},
{x:700,y:295,width:BW*7,height:BH*2,style:'grass'},
{x:1150,y:310,width:BW*5,height:BH*2,style:'grass'},
];
const MAP4=[
{x:-1600,y:800,width:BW*100,height:BH*5,style:'grass-ground'},
{x:-1400,y:745,width:BW*14,height:BH*3,style:'hill'},
{x:-600,y:758,width:BW*10,height:BH*3,style:'hill'},
{x:200,y:750,width:BW*13,height:BH*3,style:'hill'},
{x:1100,y:758,width:BW*10,height:BH*3,style:'hill'},
{x:-1280,y:600,width:BW*14,height:BH*2,style:'grass'},
{x:-560,y:585,width:BW*13,height:BH*2,style:'grass'},
{x:224,y:600,width:BW*14,height:BH*2,style:'grass'},
{x:1000,y:585,width:BW*11,height:BH*2,style:'grass'},
{x:-1100,y:430,width:BW*10,height:BH*2,style:'grass'},
{x:-256,y:415,width:BW*12,height:BH*2,style:'grass'},
{x:640,y:430,width:BW*10,height:BH*2,style:'grass'},
{x:1200,y:415,width:BW*8,height:BH*2,style:'grass'},
{x:-880,y:270,width:BW*9,height:BH*2,style:'grass'},
{x:-80,y:255,width:BW*11,height:BH*2,style:'grass'},
{x:800,y:270,width:BW*9,height:BH*2,style:'grass'},
];
const MAP5=[
{x:-1600,y:800,width:BW*100,height:BH*5,style:'grass-ground'},
{x:-1520,y:752,width:BW*9,height:BH*3,style:'hill'},
{x:-800,y:765,width:BW*7,height:BH*3,style:'hill'},
{x:-80,y:758,width:BW*11,height:BH*3,style:'hill'},
{x:700,y:762,width:BW*8,height:BH*3,style:'hill'},
{x:1300,y:756,width:BW*9,height:BH*3,style:'hill'},
{x:-1420,y:630,width:BW*8,height:BH*2,style:'grass'},
{x:-1060,y:610,width:BW*8,height:BH*2,style:'grass'},
{x:-660,y:630,width:BW*9,height:BH*2,style:'grass'},
{x:-200,y:615,width:BW*9,height:BH*2,style:'grass'},
{x:240,y:630,width:BW*8,height:BH*2,style:'grass'},
{x:660,y:615,width:BW*9,height:BH*2,style:'grass'},
{x:1080,y:630,width:BW*8,height:BH*2,style:'grass'},
{x:-1240,y:470,width:BW*7,height:BH*2,style:'grass'},
{x:-800,y:450,width:BW*8,height:BH*2,style:'grass'},
{x:-340,y:475,width:BW*7,height:BH*2,style:'grass'},
{x:120,y:450,width:BW*8,height:BH*2,style:'grass'},
{x:560,y:470,width:BW*7,height:BH*2,style:'grass'},
{x:1020,y:450,width:BW*8,height:BH*2,style:'grass'},
{x:-1000,y:300,width:BW*7,height:BH*2,style:'grass'},
{x:-480,y:280,width:BW*8,height:BH*2,style:'grass'},
{x:80,y:300,width:BW*7,height:BH*2,style:'grass'},
{x:620,y:280,width:BW*8,height:BH*2,style:'grass'},
{x:1100,y:300,width:BW*6,height:BH*2,style:'grass'},
];
const MAPS=[MAP0,MAP1,MAP2,MAP3,MAP4,MAP5];
let platforms=MAP0;
/* ======= MAP THEMES ======= */
const THEMES=[
{
skyTop:'#05050f',skyMid:'#0b0920',skyBot:'#16102e',
farPal:['#0c0c1e','#0a0a18','#0e0e24'],midPal:['#121228','#141430','#101024'],nearPal:['#0a0a16','#0c0c1a'],
winLit:'#ffe566',winDark:'#111128',ant:'#cc2222',moonCol:'#e0d89a',moonStr:'#aaa050',
starA:'#8899dd',starB:'#ffffaa',glow:[50,30,100],
platBody:'#23233a',platJoint:'#191928',platTop:'#2e2e50',platStripe:'#b09000',platGlow:'rgba(255,255,255,0.1)',
roadBody:'#16161f',roadLine:'#c8a000',roadSide:'#22222e',divR:100,divG:80,divB:255
},
{
skyTop:'#0f0508',skyMid:'#160808',skyBot:'#1e0a0a',
farPal:['#180808','#1a0a08','#140606'],midPal:['#1e0c0c','#1a0808','#200e0e'],nearPal:['#0e0404','#120808'],
winLit:'#ff9944',winDark:'#180808',ant:'#ff4422',moonCol:'#f0b870',moonStr:'#b08030',
starA:'#dd8877',starB:'#ffcc99',glow:[100,40,20],
platBody:'#301818',platJoint:'#201010',platTop:'#442222',platStripe:'#aa4400',platGlow:'rgba(255,180,100,0.12)',
roadBody:'#1a0c08',roadLine:'#cc5500',roadSide:'#220c08',divR:255,divG:80,divB:30
},
{
skyTop:'#040410',skyMid:'#060820',skyBot:'#082040',
farPal:['#080820','#06061e','#0a0a28'],midPal:['#0c0c2e','#0a0a28','#0e0e32'],nearPal:['#060618','#080822'],
winLit:'#44ccff',winDark:'#060620',ant:'#0088ff',moonCol:'#c0d8f0',moonStr:'#4488cc',
starA:'#aaccff',starB:'#cceeff',glow:[20,60,120],
platBody:'#10203a',platJoint:'#0a1828',platTop:'#1a3055',platStripe:'#008fcc',platGlow:'rgba(50,180,255,0.15)',
roadBody:'#0c1828',roadLine:'#0088cc',roadSide:'#0a1428',divR:50,divG:160,divB:255
},
{
skyTop:'#f0c0a0',skyMid:'#f8ddb0',skyBot:'#d0f0e8',
glow:[80,200,120],
platBody:'#3a7a30',platJoint:'#2e6228',platTop:'#54aa44',platStripe:'#88dd55',platGlow:'rgba(100,220,60,0.18)',
roadBody:'#5a7830',roadLine:'#88aa44',roadSide:'#4a6828',divR:80,divG:210,divB:100
},
{
skyTop:'#3ab4e0',skyMid:'#60ccf0',skyBot:'#a8e8ff',
glow:[60,180,60],
platBody:'#357028',platJoint:'#285820',platTop:'#50a03c',platStripe:'#7ed048',platGlow:'rgba(80,200,40,0.2)',
roadBody:'#507030',roadLine:'#80a040',roadSide:'#406028',divR:50,divG:220,divB:80
},
{
skyTop:'#e05010',skyMid:'#f08020',skyBot:'#f8c060',
glow:[200,120,20],
platBody:'#4a6030',platJoint:'#384825',platTop:'#608040',platStripe:'#90b055',platGlow:'rgba(140,200,60,0.2)',
roadBody:'#4a5828',roadLine:'#78903a',roadSide:'#384820',divR:255,divG:140,divB:40
}
];
/* ======= BUILDING DATA ======= */
function makeWins(bw,bh,cols,rows){
let wins=[];
const cw=Math.floor(bw/(cols+1)),ww=Math.max(5,Math.min(cw-4,18)),wh=10,rh=Math.floor((bh-20)/(rows+1));
for(let r=0;r<rows;r++)for(let c=0;c<cols;c++){const rx=cw+(cw+ww)*c,ry=rh*(r+1);if(rx+ww<=bw&&ry+wh<=bh)wins.push({rx,ry,rw:ww,rh:wh,lit:Math.random()<.55,ci:Math.floor(Math.random()*3)});}
return wins;
}
const BPOS_FAR=[
{x:-2000,w:160,h:540,ci:0},{x:-1750,w:200,h:620,ci:1},{x:-1500,w:140,h:460,ci:2},
{x:-1250,w:180,h:580,ci:0},{x:-1000,w:150,h:500,ci:1},{x:-760,w:200,h:660,ci:2},
{x:-500,w:170,h:520,ci:0},{x:-280,w:220,h:700,ci:1},{x:-30,w:160,h:560,ci:2},
{x:200,w:160,h:560,ci:0},{x:430,w:220,h:700,ci:1},{x:690,w:170,h:520,ci:2},
{x:950,w:200,h:660,ci:0},{x:1200,w:150,h:500,ci:1},{x:1440,w:180,h:580,ci:2},
{x:1700,w:140,h:460,ci:0},{x:1940,w:200,h:620,ci:1},{x:2200,w:160,h:540,ci:2},
];
const BPOS_MID=[
{x:-1700,w:180,h:380,ci:0},{x:-1440,w:220,h:460,ci:1},{x:-1150,w:160,h:340,ci:2},
{x:-880,w:200,h:440,ci:0},{x:-600,w:240,h:500,ci:1},{x:-280,w:180,h:420,ci:2},
{x:-30,w:240,h:520,ci:0},{x:230,w:180,h:420,ci:1},{x:490,w:240,h:500,ci:2},
{x:800,w:200,h:440,ci:0},{x:1060,w:160,h:340,ci:1},{x:1300,w:220,h:460,ci:2},{x:1580,w:180,h:380,ci:0},
];
const BPOS_NEAR=[
{x:-1700,w:140,h:260,ci:0},{x:-1460,w:190,h:320,ci:1},{x:-1200,w:160,h:290,ci:0},
{x:-1000,w:210,h:360,ci:1},{x:-760,w:170,h:300,ci:0},{x:-480,w:230,h:390,ci:1},
{x:-240,w:120,h:240,ci:0},{x:-60,w:120,h:240,ci:1},
{x:120,w:230,h:390,ci:0},{x:410,w:170,h:300,ci:1},{x:660,w:210,h:360,ci:0},
{x:940,w:160,h:290,ci:1},{x:1180,w:190,h:320,ci:0},{x:1440,w:140,h:260,ci:1},{x:1700,w:190,h:320,ci:0},
];
const BLDG_FAR=BPOS_FAR.map(b=>({...b,wins:makeWins(b.w,b.h,3,Math.floor(b.h/80))}));
const BLDG_MID=BPOS_MID.map(b=>({...b,wins:makeWins(b.w,b.h,4,Math.floor(b.h/65))}));
const BLDG_NEAR=BPOS_NEAR.map(b=>({...b,wins:makeWins(b.w,b.h,3,Math.floor(b.h/55))}));
setInterval(()=>{
for(let layer of[BLDG_FAR,BLDG_MID,BLDG_NEAR]){const b=layer[Math.floor(Math.random()*layer.length)];if(b&&b.wins.length)b.wins[Math.floor(Math.random()*b.wins.length)].lit^=Math.random()<.3;}
},700);
/* ======= GRASS DECORATIONS ======= */
const GRASS_TREES=Array.from({length:28},(_,i)=>({
wx:-2200+i*180+Math.sin(i*1.9)*55,wy:800,
h:55+Math.floor(Math.sin(i*2.3)*22),tw:12+Math.floor(Math.cos(i*1.1)*3),cr:20+Math.floor(Math.sin(i*0.9)*7)
}));
const GRASS_CLOUDS_BG=Array.from({length:12},(_,i)=>({
wx:-2000+i*380+Math.sin(i*2.1)*100,wy:-180-Math.floor(Math.random()*280),
w:90+Math.floor(Math.random()*90),h:26+Math.floor(Math.random()*18)
}));
const GRASS_FLOWERS=Array.from({length:80},(_,i)=>({
wx:-2200+i*60+Math.sin(i*3.7)*18,
col:['#ff6688','#ffee44','#ff9944','#ff55aa','#ffffff','#ff99cc'][i%6]
}));
const STARS=Array.from({length:200},()=>({wx:(Math.random()-.5)*6000,wy:-100-Math.random()*900,sz:Math.random()<.65?2:4,br:Math.random()}));
const GY=800;
/* ======= DRAW HELPERS — CITY ======= */
function drawSky(c,vx,vy,vw,vh,th){
const sky=c.createLinearGradient(vx,vy,vx,vy+vh);
sky.addColorStop(0,th.skyTop);sky.addColorStop(.55,th.skyMid);sky.addColorStop(1,th.skyBot);
c.fillStyle=sky;c.fillRect(vx,vy,vw,vh);
}
function drawStarsC(c,camX,camY,vx,vy,vw,vh,th){
c.save();c.beginPath();c.rect(vx,vy,vw,vh);c.clip();
for(let s of STARS){
let sx=vx+((s.wx-camX*.04)%vw+vw)%vw,sy=vy+((s.wy-camY*.04)%vh+vh)%vh;
c.globalAlpha=.4+s.br*.6;c.fillStyle=s.sz===2?th.starA:th.starB;c.fillRect(sx,sy,s.sz,s.sz);
}
c.globalAlpha=1;c.restore();
}
function drawMoonC(c,camX,camY,vx,vy,vw,vh,th){
const mx=vx+vw*.8-camX*.02,my=vy+vh*.15-camY*.02;
const grd=c.createRadialGradient(mx,my,20,mx,my,70);
grd.addColorStop(0,'rgba(220,210,145,.2)');grd.addColorStop(1,'rgba(0,0,0,0)');
c.fillStyle=grd;c.fillRect(mx-70,my-70,140,140);
c.fillStyle=th.moonCol;c.fillRect(mx-24,my-24,48,48);
c.fillStyle=th.moonCol+'cc';c.fillRect(mx-20,my-24,40,10);
c.fillStyle=th.moonStr;c.fillRect(mx+6,my+6,14,14);c.fillRect(mx-16,my+10,10,10);
c.strokeStyle=th.moonStr;c.lineWidth=3;c.strokeRect(mx-24,my-24,48,48);
}
function drawBldgLayer(c,bldgs,camX,camY,par,vx,vy,vw,vh,th,palKey){
const pal=th[palKey];const gsy=vy+(GY-camY);
for(let b of bldgs){
const sx=vx+(b.x-camX*par),sy=gsy-b.h;
if(sx+b.w<vx||sx>vx+vw)continue;
c.save();c.beginPath();c.rect(sx,sy,b.w,b.h);c.clip();
c.fillStyle=pal[b.ci%pal.length];c.fillRect(sx,sy,b.w,b.h);
c.fillStyle='rgba(255,255,255,.03)';c.fillRect(sx,sy,3,b.h);c.fillRect(sx+b.w-3,sy,3,b.h);
c.fillStyle='rgba(255,255,255,.06)';c.fillRect(sx,sy,b.w,6);
for(let w of b.wins){
const wx=sx+w.rx,wy=sy+w.ry;if(wy>vy+vh||wy+w.rh<vy)continue;
if(w.lit){c.fillStyle=th.winLit;c.fillRect(wx,wy,w.rw,w.rh);c.fillStyle='rgba(255,240,100,.35)';c.fillRect(wx,wy,w.rw,3);}
else{c.fillStyle=th.winDark;c.fillRect(wx,wy,w.rw,w.rh);}
}
c.restore();
c.fillStyle=th.ant;c.fillRect(sx+b.w/2-2,sy-20,4,20);
c.fillStyle='#ff2222';c.fillRect(sx+b.w/2-3,sy-24,6,6);
}
}
function drawGroundGlow(c,camY,vx,vy,vw,vh,th){
const gsy=vy+(GY-camY);
if(gsy>vy-40&&gsy<vy+vh+40){
const ng=c.createLinearGradient(vx,gsy-40,vx,gsy);
ng.addColorStop(0,'rgba(0,0,0,0)');ng.addColorStop(1,'rgba('+th.glow[0]+','+th.glow[1]+','+th.glow[2]+',.55)');
c.fillStyle=ng;c.fillRect(vx,gsy-40,vw,40);
}
}
/* ======= DRAW HELPERS — GRASS ======= */
function drawGrassSky(c,vx,vy,vw,vh,th,mapId){
const sky=c.createLinearGradient(vx,vy,vx,vy+vh);
sky.addColorStop(0,th.skyTop);sky.addColorStop(.6,th.skyMid);sky.addColorStop(1,th.skyBot);
c.fillStyle=sky;c.fillRect(vx,vy,vw,vh);
}
function drawSunC(c,camX,camY,vx,vy,vw,vh,mapId){
const sunX=mapId===3?0.15:(mapId===4?0.5:0.85);
const sunY=mapId===3?0.18:(mapId===4?0.1:0.2);
const sx=vx+vw*sunX-camX*.012,sy=vy+vh*sunY-camY*.012;
const sunColors={3:['#ffe090','#ffcc60'],4:['#ffffc0','#ffe860'],5:['#ff8820','#ff5500']};
const [sc1,sc2]=sunColors[mapId]||['#ffe090','#ffcc60'];
const grd=c.createRadialGradient(sx,sy,16,sx,sy,80);
grd.addColorStop(0,'rgba(255,240,100,.4)');grd.addColorStop(1,'rgba(255,200,0,0)');
c.fillStyle=grd;c.fillRect(sx-80,sy-80,160,160);
c.fillStyle=sc1;c.fillRect(sx-20,sy-20,40,40);
c.fillStyle=sc2;c.fillRect(sx-16,sy-20,32,10);
c.strokeStyle=sc2;c.lineWidth=3;c.strokeRect(sx-20,sy-20,40,40);
c.strokeStyle='rgba(255,220,50,.3)';c.lineWidth=2;
for(let i=0;i<8;i++){const ang=i*Math.PI/4;c.beginPath();c.moveTo(sx+Math.cos(ang)*24,sy+Math.sin(ang)*24);c.lineTo(sx+Math.cos(ang)*46,sy+Math.sin(ang)*46);c.stroke();}
}
function drawGrassBackground(c,camX,camY,vx,vy,vw,vh,mapId){
const gsy=vy+(GY-camY);
for(let cl of GRASS_CLOUDS_BG){
const cx2=vx+((cl.wx-camX*.05)%(vw+400)+vw+400)%(vw+400)-200,cy2=vy+cl.wy-camY*.025;
if(cx2+cl.w<vx||cx2>vx+vw)continue;
c.globalAlpha=.75;
c.fillStyle='rgba(255,255,255,.85)';c.fillRect(cx2,cy2,cl.w,cl.h);
c.fillStyle='rgba(200,230,255,.6)';c.fillRect(cx2,cy2+cl.h*.6,cl.w,cl.h*.4);
c.fillStyle='rgba(255,255,255,.5)';c.fillRect(cx2-cl.h*.3,cy2+cl.h*.25,cl.w+cl.h*.6,cl.h*.45);
c.globalAlpha=1;
}
for(let t of GRASS_TREES){
const tx=vx+((t.wx-camX*.28)%(vw+500)+vw+500)%(vw+500)-250,ty=gsy-t.h;
if(tx+t.cr*2.5<vx||tx-t.cr*2.5>vx+vw)continue;
c.fillStyle='#3d2010';c.fillRect(tx-t.tw/2,ty,t.tw,t.h);
c.fillStyle='#4a2a14';c.fillRect(tx-t.tw/2,ty,t.tw/3,t.h);
c.fillStyle='#257018';c.fillRect(tx-t.cr,ty-t.cr*.5,t.cr*2,t.cr*1.2);
c.fillStyle='#2e8820';c.fillRect(tx-t.cr*.7,ty-t.cr*1.0,t.cr*1.4,t.cr*.9);
c.fillStyle='#3aa828';c.fillRect(tx-t.cr*.45,ty-t.cr*1.45,t.cr*.9,t.cr*.6);
c.fillStyle='rgba(255,255,255,.05)';c.fillRect(tx-t.cr,ty-t.cr*.5,t.cr*.25,t.cr*.9);
}
for(let fl of GRASS_FLOWERS){
const fx=vx+((fl.wx-camX*.62)%(vw+240)+vw+240)%(vw+240)-120;
if(fx<vx-8||fx>vx+vw+8)continue;
const fy=gsy;
c.fillStyle='#3a5c18';c.fillRect(fx,fy-9,2,9);
c.fillStyle=fl.col;c.fillRect(fx-3,fy-15,8,6);
c.fillStyle='#ffff88';c.fillRect(fx-1,fy-13,4,4);
}
}
function drawGrassPlatformStyle(c,pl,th){
const{x,y,width:pw,height:ph,style}=pl;
if(style==='grass-ground'){
c.fillStyle='#224018';c.fillRect(x,y,pw,ph);
c.fillStyle='#40882c';c.fillRect(x,y,pw,16);
c.fillStyle='#54aa38';c.fillRect(x,y,pw,7);
c.fillStyle='#68cc4a';c.fillRect(x,y,pw,3);
c.fillStyle='#2a1a08';c.fillRect(x,y+16,pw,ph-16);
for(let dx=x;dx<x+pw;dx+=44){c.fillStyle='rgba(0,0,0,.1)';c.fillRect(dx,y+16,22,ph-16);}
} else if(style==='hill'){
c.fillStyle='#2e6820';c.fillRect(x,y,pw,ph);
c.fillStyle='#48962e';c.fillRect(x,y,pw,12);
c.fillStyle='#5ab838';c.fillRect(x,y,pw,5);
} else if(style==='grass'){
c.fillStyle=th.platBody;c.fillRect(x,y,pw,ph);
c.fillStyle=th.platJoint;for(let ty=y;ty<y+ph;ty+=BH)c.fillRect(x,ty,pw,2);
c.fillStyle='#48962e';c.fillRect(x,y,pw,12);
c.fillStyle='#5ab838';c.fillRect(x,y,pw,5);
c.fillStyle='#70d850';c.fillRect(x,y,pw,2);
c.fillStyle='rgba(100,60,20,.22)';c.fillRect(x,y+12,pw,ph-12);
for(let gx=x+10;gx<x+pw-10;gx+=16){
c.fillStyle='#4aa030';c.fillRect(gx,y-4,3,6);c.fillRect(gx+6,y-6,2,7);c.fillRect(gx+10,y-4,3,5);
}
c.fillStyle='rgba(60,35,8,.28)';c.fillRect(x,y+ph-4,pw,4);
c.strokeStyle='#1a3808';c.lineWidth=2;c.strokeRect(x+1,y+1,pw-2,ph-2);
}
}
function drawPlatforms(c,plats,th){
for(let pl of plats){
const{x,y,width:pw,height:ph,style}=pl;
if(style==='cloud'){pl.draw(c);continue;}
if(style==='waterfloor')continue; // invisible, skip drawing
if(style==='grass'||style==='grass-ground'||style==='hill'){drawGrassPlatformStyle(c,pl,th);continue;}
c.save();c.beginPath();c.rect(x,y,pw,ph);c.clip();
if(style==='wall'){
c.fillStyle='#060612';c.fillRect(x,y,pw,ph);
const wrows=Math.floor(ph/38);