-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmicrojets.html
More file actions
1718 lines (1536 loc) · 72.2 KB
/
microjets.html
File metadata and controls
1718 lines (1536 loc) · 72.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,user-scalable=no">
<title>MICROJET: HEAVY ARSENAL v9.0 FINAL</title>
<style>
*{margin:0;padding:0;box-sizing:border-box;overflow:hidden}
body{background:#000;font-family:monospace}
canvas{display:block;position:absolute;top:0;left:0;width:100%;height:100%}
#introScreen{
position:fixed;inset:0;background:radial-gradient(ellipse at center,#001a08 0%,#000 100%);
display:flex;flex-direction:column;align-items:center;justify-content:center;z-index:200;
color:#0f0;text-align:center;font-family:'Courier New',monospace;transition:opacity 0.8s;
}
#introScreen h1{font-size:clamp(34px,7vw,68px);text-shadow:0 0 20px #0f0;margin-bottom:10px}
#startBtn,#immortalBtn{
background:transparent;border:2px solid #0f0;color:#0f0;font-size:20px;padding:12px 36px;
margin:10px;cursor:pointer;border-radius:40px;transition:0.2s;font-family:monospace;
}
#startBtn:hover,#immortalBtn:hover{background:#0f0;color:#000}
.imm-btn.on{background:#0ff;border-color:#0ff;color:#000;box-shadow:0 0 20px #0ff}
#ptrMsg{
position:fixed;bottom:50px;left:50%;transform:translateX(-50%);
background:rgba(0,0,0,0.7);color:#ffaa00;padding:10px 22px;border-radius:40px;
font-size:18px;border:2px solid #ffaa00;pointer-events:none;z-index:30;opacity:0;
}
#weaponHUD{
position:fixed;bottom:20px;left:50%;transform:translateX(-50%);
display:flex;gap:20px;z-index:100;
}
.weaponBox{
background:rgba(0,20,0,0.8);border:2px solid #0f0;color:#0f0;padding:8px 16px;
font-family:monospace;font-size:14px;text-align:center;min-width:120px;
}
.weaponBox.active{background:rgba(0,60,0,0.9);box-shadow:0 0 15px #0f0;}
.weaponBox .ammo{color:#ff0;font-size:18px;font-weight:bold;}
</style>
</head>
<body>
<canvas id="gameCanvas"></canvas>
<div id="introScreen">
<h1>MICROJET</h1>
<div style="margin-bottom:20px">HEAVY ARSENAL v9.0 FINAL</div>
<div>
<button id="startBtn">▶ LAUNCH</button>
<button id="immortalBtn" class="imm-btn">☠ IMMORTAL: OFF</button>
</div>
<div style="font-size:12px;margin-top:20px">
<div style="color:#ff0">LMB: Gatling | RMB: Heavy Torpedo | R: Homing Nuke</div>
<div>WASD · Shift boost · Q/E roll · M map</div>
</div>
</div>
<div id="ptrMsg">🔒 Click to enable mouse steering</div>
<div id="weaponHUD" style="display:none">
<div class="weaponBox active" id="hudGatling">
<div>GATLING</div>
<div class="ammo" id="ammoGatling">∞</div>
</div>
<div class="weaponBox" id="hudSidewinder">
<div>TORPEDO</div>
<div class="ammo" id="ammoSidewinder">6</div>
</div>
<div class="weaponBox" id="hudNuke">
<div>NUKE</div>
<div class="ammo" id="ammoNuke">READY</div>
</div>
</div>
<script type="importmap">{"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.168.0/build/three.module.js","three/addons/":"https://cdn.jsdelivr.net/npm/three@0.168.0/examples/jsm/"}}</script>
<script type="module">
import * as THREE from 'three';
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
import { RenderPass } from 'three/addons/postprocessing/RenderPass.js';
import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
const ZONES = {"1": {"name": "AURORA SECTOR", "planetColor": 65280, "planetEmit": 17442, "ringColor": 65280, "skyColor": 66568, "fogDensity": 0.00018, "zoneRadius": 900, "enemies": 6, "tanks": 2, "gunships": 0, "kamikaze": 3, "bossName": null, "planetDesc": "Emerald gas giant. First contact."}, "2": {"name": "CRIMSON NEBULA", "planetColor": 16724736, "planetEmit": 3342336, "ringColor": 16728064, "skyColor": 526601, "fogDensity": 0.0002, "zoneRadius": 1000, "enemies": 8, "tanks": 3, "gunships": 1, "kamikaze": 4, "bossName": null, "planetDesc": "Crimson lava world. Heat sensors offline."}, "3": {"name": "AZURE DRIFT", "planetColor": 26367, "planetEmit": 4420, "ringColor": 43775, "skyColor": 66320, "fogDensity": 0.00022, "zoneRadius": 1100, "enemies": 10, "tanks": 3, "gunships": 2, "kamikaze": 5, "bossName": null, "planetDesc": "Ocean world. Tidal storms."}, "4": {"name": "VOID EXPANSE", "planetColor": 11141120, "planetEmit": 2231364, "ringColor": 13369344, "skyColor": 131080, "fogDensity": 0.00015, "zoneRadius": 1200, "enemies": 12, "tanks": 4, "gunships": 2, "kamikaze": 6, "bossName": null, "planetDesc": "Dark matter zone. Nav systems disrupted."}, "5": {"name": "SULFUR CROWN", "planetColor": 16763904, "planetEmit": 4460544, "ringColor": 16768708, "skyColor": 328704, "fogDensity": 0.00025, "zoneRadius": 1300, "enemies": 14, "tanks": 5, "gunships": 3, "kamikaze": 7, "bossName": "ALPHA-CMD", "planetDesc": "Sulfur giant. Alpha commander deployed."}, "6": {"name": "FROST DOMINION", "planetColor": 8967423, "planetEmit": 1122867, "ringColor": 11206655, "skyColor": 66824, "fogDensity": 0.0002, "zoneRadius": 1400, "enemies": 16, "tanks": 5, "gunships": 3, "kamikaze": 8, "bossName": null, "planetDesc": "Ice world. Frozen fleet detected."}, "7": {"name": "MAGMA RIFT", "planetColor": 16737792, "planetEmit": 4464640, "ringColor": 16728064, "skyColor": 526850, "fogDensity": 0.00022, "zoneRadius": 1500, "enemies": 18, "tanks": 6, "gunships": 4, "kamikaze": 10, "bossName": null, "planetDesc": "Volcanic instability. Terrain unstable."}, "8": {"name": "NEON GRAVEYARD", "planetColor": 65404, "planetEmit": 13124, "ringColor": 65280, "skyColor": 2056, "fogDensity": 0.00018, "zoneRadius": 1600, "enemies": 20, "tanks": 7, "gunships": 4, "kamikaze": 12, "bossName": "BETA-CMD", "planetDesc": "Dead fleet sector. Beta commander rallies."}, "9": {"name": "QUANTUM STORM", "planetColor": 16711978, "planetEmit": 4456450, "ringColor": 16727884, "skyColor": 327685, "fogDensity": 0.00016, "zoneRadius": 1700, "enemies": 22, "tanks": 8, "gunships": 5, "kamikaze": 14, "bossName": null, "planetDesc": "Quantum distortion. Weapons charged."}, "10": {"name": "TRIOS COMMAND", "planetColor": 16711680, "planetEmit": 5570560, "ringColor": 16721920, "skyColor": 524288, "fogDensity": 0.00014, "zoneRadius": 1800, "enemies": 25, "tanks": 8, "gunships": 6, "kamikaze": 15, "bossName": "TRIOS FLEET CMD", "planetDesc": "TRIOS command world. Final battle."}};
const scene = new THREE.Scene();
const renderer = new THREE.WebGLRenderer({canvas:document.getElementById('gameCanvas'),antialias:true});
renderer.setSize(innerWidth,innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio,2));
renderer.shadowMap.enabled = true;
const camera = new THREE.PerspectiveCamera(72, innerWidth/innerHeight, 0.1, 8000);
const clock = new THREE.Clock();
window.addEventListener('resize',()=>{
camera.aspect = innerWidth/innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth,innerHeight);
});
const composer = new EffectComposer(renderer);
composer.addPass(new RenderPass(scene, camera));
composer.addPass(new UnrealBloomPass(new THREE.Vector2(window.innerWidth, window.innerHeight), 1.8, 0.4, 0.85));
scene.add(new THREE.AmbientLight(0x223344,1.2));
const sun = new THREE.DirectionalLight(0xfff8e8,1.5);
sun.position.set(200,300,100); sun.castShadow=true; scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x0044ff,0.6);
rimLight.position.set(-200,-100,-200); scene.add(rimLight);
const starGeo = new THREE.BufferGeometry();
const starPos = new Float32Array(12000*3);
for(let i=0;i<36000;i++) starPos[i]=(Math.random()-0.5)*10000;
starGeo.setAttribute('position',new THREE.BufferAttribute(starPos,3));
const starField = new THREE.Points(starGeo,new THREE.PointsMaterial({color:0xffffff,size:1.1}));
scene.add(starField);
let starRotSpeed = 0.00015;
let planetGroup = new THREE.Group();
scene.add(planetGroup);
const PLANET_DIST_Z = -900;
const PLANET_HEIGHT_Y = 400;
function buildPlanet(zoneNum){
while(planetGroup.children.length) planetGroup.remove(planetGroup.children[0]);
const z = ZONES[zoneNum];
const pc = z.planetColor, pe = z.planetEmit, rc = z.ringColor;
const R = 140 + zoneNum*8;
scene.background = new THREE.Color(z.skyColor);
scene.fog = new THREE.FogExp2(z.skyColor, z.fogDensity);
const sphere = new THREE.Mesh(new THREE.SphereGeometry(R,128,64),
new THREE.MeshStandardMaterial({color:pc,emissive:pe,roughness:0.7,metalness:0.15}));
planetGroup.add(sphere);
const ringMat = new THREE.MeshStandardMaterial({color:rc,emissive:new THREE.Color(rc).multiplyScalar(0.25)});
for(let i=0;i<3;i++){
const ring = new THREE.Mesh(new THREE.TorusGeometry(R+4+i*5,1.4-i*0.2,24,200),ringMat);
ring.rotation.x = Math.PI/2+i*0.28; ring.rotation.z=i*0.52; planetGroup.add(ring);
}
const core = new THREE.Mesh(new THREE.SphereGeometry(R*0.28,32,16),
new THREE.MeshStandardMaterial({color:rc,emissive:new THREE.Color(rc).multiplyScalar(0.5)}));
planetGroup.add(core);
const dotMat = new THREE.MeshStandardMaterial({color:rc,emissive:new THREE.Color(rc).multiplyScalar(0.4)});
for(let i=0;i<60;i++){
const dot = new THREE.Mesh(new THREE.SphereGeometry(1.6,4),dotMat);
const th=Math.random()*Math.PI*2, ph=Math.acos(2*Math.random()-1);
dot.position.set(R*Math.sin(ph)*Math.cos(th), R*Math.sin(ph)*Math.sin(th), R*Math.cos(ph));
planetGroup.add(dot);
}
if(zoneNum>=5){
for(let m=0;m<Math.floor(zoneNum/3);m++){
const moonR=22+m*8;
const moon = new THREE.Mesh(new THREE.SphereGeometry(moonR,16,16),
new THREE.MeshStandardMaterial({color:rc,emissive:pe,roughness:0.8}));
const ma = m/3*Math.PI*2;
moon.position.set(Math.cos(ma)*(R+moonR+40), Math.sin(ma*0.5)*30, Math.sin(ma)*(R+moonR+40));
planetGroup.add(moon);
}
}
const pl = new THREE.PointLight(rc,4,500); pl.position.set(50,30,40); planetGroup.add(pl);
const pl2 = new THREE.PointLight(rc,2,400); pl2.position.set(-30,-40,60); planetGroup.add(pl2);
planetGroup.position.set(0, PLANET_HEIGHT_Y, PLANET_DIST_Z);
}
const FLOOR_Y = -220;
const floorGeometry = new THREE.PlaneGeometry(6000, 6000, 80, 80);
const floorMaterial = new THREE.MeshBasicMaterial({
color: 0x004400,
wireframe: true,
transparent: true,
opacity: 0.6
});
const floorMesh = new THREE.Mesh(floorGeometry, floorMaterial);
floorMesh.rotation.x = -Math.PI / 2;
floorMesh.position.y = FLOOR_Y;
scene.add(floorMesh);
function createMicroJet7(){
const g = new THREE.Group();
const bodyMat=new THREE.MeshStandardMaterial({color:0x1a2a3a,emissive:0x001122,roughness:0.4,metalness:0.8});
const accentMat=new THREE.MeshStandardMaterial({color:0x0055aa,emissive:0x002255,roughness:0.3,metalness:0.9});
const glowMat=new THREE.MeshStandardMaterial({color:0x00ccff,emissive:0x0055ff});
const neonMat=new THREE.MeshStandardMaterial({color:0x00ff88,emissive:0x00ff44});
const fuse=new THREE.Mesh(new THREE.CylinderGeometry(0.6,1.1,9,8),bodyMat);
fuse.rotation.x=Math.PI/2;g.add(fuse);
const nose=new THREE.Mesh(new THREE.ConeGeometry(0.6,4,8),accentMat);
nose.rotation.x=Math.PI/2;nose.position.z=6.5;g.add(nose);
const noseTip=new THREE.Mesh(new THREE.ConeGeometry(0.1,1.5,6),glowMat);
noseTip.rotation.x=Math.PI/2;noseTip.position.z=9;g.add(noseTip);
const cockpit=new THREE.Mesh(new THREE.SphereGeometry(0.7,12,8),
new THREE.MeshStandardMaterial({color:0x88ccff,emissive:0x002244,roughness:0.1,metalness:0.5,transparent:true,opacity:0.85}));
cockpit.scale.set(0.8,0.55,1.0);cockpit.position.set(0,0.6,3.5);g.add(cockpit);
const wShape=new THREE.Shape();
wShape.moveTo(0,0);wShape.lineTo(-4.5,-0.1);wShape.lineTo(-3.2,-3.8);wShape.lineTo(1.2,-0.1);
const wGeo=new THREE.ExtrudeGeometry(wShape,{depth:0.18,bevelEnabled:false});
const wingL=new THREE.Mesh(wGeo,bodyMat);wingL.position.set(-0.5,-0.1,1.5);wingL.rotation.x=-Math.PI/2;g.add(wingL);
const wingR=new THREE.Mesh(wGeo,bodyMat);wingR.position.set(0.5,-0.1,1.5);wingR.rotation.x=-Math.PI/2;wingR.rotation.z=Math.PI;g.add(wingR);
const gunGeo=new THREE.CylinderGeometry(0.09,0.09,2.8,5);
const gunMat=new THREE.MeshStandardMaterial({color:0x334455,metalness:0.9});
for(let sx of[-1,1]){
const gun=new THREE.Mesh(gunGeo,gunMat);gun.rotation.x=Math.PI/2;gun.position.set(sx*4.2,-0.2,0.6);g.add(gun);
const barrel=new THREE.Mesh(new THREE.CylinderGeometry(0.08,0.08,1.2,4),glowMat);
barrel.rotation.x=Math.PI/2;barrel.position.set(sx*4.2,-0.2,2.4);g.add(barrel);
}
const finGeo=new THREE.BoxGeometry(0.12,2.0,1.8);
for(const [px,py,rz] of[[-0.8,1.0,0.15],[0.8,1.0,-0.15],[-0.8,-1.0,-0.15],[0.8,-1.0,0.15]]){
const fin=new THREE.Mesh(finGeo,accentMat);fin.position.set(px,py,-2.8);fin.rotation.z=rz;g.add(fin);
}
const engMat=new THREE.MeshStandardMaterial({color:0x222233,emissive:0x001122});
for(let sx of[-1.2,1.2]){
const pod=new THREE.Mesh(new THREE.CylinderGeometry(0.55,0.55,4.5,8),engMat);
pod.rotation.x=Math.PI/2;pod.position.set(sx,-0.4,-1.5);g.add(pod);
const noz=new THREE.Mesh(new THREE.CylinderGeometry(0.55,0.75,1.0,8),engMat);
noz.rotation.x=Math.PI/2;noz.position.set(sx,-0.4,-3.8);g.add(noz);
const glow=new THREE.PointLight(0xff6600,5,12);glow.position.set(sx,-0.4,-4.5);g.add(glow);
}
const strip=new THREE.Mesh(new THREE.BoxGeometry(0.15,0.12,6),neonMat);
strip.position.set(0,-1.0,0.5);g.add(strip);
return g;
}
// COLOR-CODED HITBOX SYSTEM
// Tanks: Orange (0xff8800), Drones: Cyan (0x00ffff), Kamikazes: Magenta (0xff00ff), Boss: Red (0xff0000)
function createHitbox(size, color, parent) {
const geometry = new THREE.BoxGeometry(size.x, size.y, size.z);
const edges = new THREE.EdgesGeometry(geometry);
const material = new THREE.LineBasicMaterial({
color: color,
transparent: true,
opacity: 0.9,
linewidth: 3
});
const hitbox = new THREE.LineSegments(edges, material);
const canvas = document.createElement('canvas');
canvas.width = 64; canvas.height = 64;
const ctx = canvas.getContext('2d');
const gradient = ctx.createRadialGradient(32,32,0,32,32,32);
const r = (color>>16)&255, g = (color>>8)&255, b = color&255;
gradient.addColorStop(0, `rgba(${r},${g},${b},0.5)`);
gradient.addColorStop(1, 'rgba(0,0,0,0)');
ctx.fillStyle = gradient;
ctx.fillRect(0,0,64,64);
const spriteMap = new THREE.CanvasTexture(canvas);
const spriteMat = new THREE.SpriteMaterial({
map: spriteMap,
transparent: true,
opacity: 0.6,
blending: THREE.AdditiveBlending,
depthTest: false
});
const glow = new THREE.Sprite(spriteMat);
glow.scale.set(size.x*2.5, size.y*2.5, 1);
const group = new THREE.Group();
group.add(hitbox);
group.add(glow);
parent.add(group);
return {
mesh: group,
baseColor: color,
flash: function() {
hitbox.material.color.setHex(0xffffff);
hitbox.material.opacity = 1.0;
glow.material.opacity = 1.0;
setTimeout(() => {
hitbox.material.color.setHex(color);
hitbox.material.opacity = 0.9;
glow.material.opacity = 0.6;
}, 100);
},
update: function(camera) {
const dist = parent.position.distanceTo(camera.position);
const scale = Math.max(0.8, Math.min(2.5, dist / 150));
group.scale.setScalar(scale);
group.lookAt(camera.position);
}
};
}
function createHunter(tier){
const g=new THREE.Group();
const cols=[0xff2244,0xff8800,0xaa00ff,0xff0044,0x00aaff];
const c=cols[tier%cols.length];
const hull=new THREE.MeshStandardMaterial({color:0x111122,emissive:0x110011,roughness:0.4,metalness:0.8});
const acc=new THREE.MeshStandardMaterial({color:c,emissive:new THREE.Color(c).multiplyScalar(0.3)});
const body=new THREE.Mesh(new THREE.CylinderGeometry(1.4,1.2,0.7,6),hull);
body.rotation.x=Math.PI/2;g.add(body);
const spike=new THREE.Mesh(new THREE.ConeGeometry(0.4,3.5,6),acc);
spike.rotation.x=Math.PI/2;spike.position.z=3.2;g.add(spike);
for(let sx of[-1,1]){
const w=new THREE.Mesh(new THREE.BoxGeometry(0.2,4.8,2.2),hull);
w.position.set(sx*2.4,0,-0.2);w.rotation.z=sx*-0.22;g.add(w);
const tip=new THREE.Mesh(new THREE.BoxGeometry(0.5,0.5,1.2),acc);
tip.position.set(sx*4.7,0,0.5);g.add(tip);
}
const el=new THREE.PointLight(c,3,18);el.position.set(0,0,-2);g.add(el);
const trailMat=new THREE.MeshBasicMaterial({color:c,transparent:true,opacity:0.75});
const trails=[];
for(let sx of[-0.9,0.9]){
const tr=new THREE.Mesh(new THREE.CylinderGeometry(0.3,0.6,1.2,6),trailMat.clone());
tr.rotation.x=Math.PI/2;tr.position.set(sx,0,-2.2);g.add(tr);trails.push(tr);
}
// DRONE HITBOX - CYAN, LARGER
const hitbox = createHitbox({x:10, y:6, z:12}, 0x00ffff, g);
g.userData={
type:'hunter',
hitbox: hitbox,
trails,speed:22+tier*8+Math.random()*8,
health:3+Math.floor(tier/2),
maxHealth:3+Math.floor(tier/2),
shootCooldown:Math.random()*2,
tier,radius:3.5
};
return g;
}
function createKamikaze(tier){
const g=new THREE.Group();
const c=0xff0044;
const mat=new THREE.MeshStandardMaterial({color:c,emissive:0x440000,roughness:0.3});
const spike=new THREE.Mesh(new THREE.ConeGeometry(0.8,4,4),mat);
spike.rotation.x=Math.PI/2;g.add(spike);
const body=new THREE.Mesh(new THREE.CylinderGeometry(0.6,0.4,2,4),mat);
body.rotation.x=Math.PI/2;body.position.z=-1;g.add(body);
const light=new THREE.PointLight(c,4,25);light.position.set(0,0,0);g.add(light);
for(let sx of[-0.5,0.5]){
const tr=new THREE.Mesh(new THREE.CylinderGeometry(0.2,0.4,3,4),new THREE.MeshBasicMaterial({color:0xffaa00}));
tr.rotation.x=Math.PI/2;tr.position.set(sx,0,-2);g.add(tr);
}
// KAMIKAZE HITBOX - MAGENTA, LARGER
const hitbox = createHitbox({x:8, y:6, z:10}, 0xff00ff, g);
g.userData={
type:'kamikaze',
hitbox: hitbox,
speed:45+tier*10,
health:2,
maxHealth:2,
tier,
radius:3,
chargeDistance:150,
exploding: false
};
return g;
}
function createTank(variant){
const g=new THREE.Group();
const tc=[0xff3355,0xff8800,0x9900ff,0xff0066,0x00aaff];
const c=tc[variant%tc.length];
const mat=new THREE.MeshStandardMaterial({color:c,emissive:0x110000,roughness:0.7,metalness:0.5});
const dark=new THREE.MeshStandardMaterial({color:0x111111,emissive:0x050505});
const hull=new THREE.Mesh(new THREE.BoxGeometry(5.5,1.8,8.0),mat);hull.position.y=0.9;g.add(hull);
for(let s of[-1,1]){
const pl=new THREE.Mesh(new THREE.BoxGeometry(0.4,1.6,6.5),dark);pl.position.set(s*2.8,0.9,0);g.add(pl);
const track=new THREE.Mesh(new THREE.BoxGeometry(1.4,1.4,8.5),new THREE.MeshStandardMaterial({color:0x222222,roughness:0.9}));
track.position.set(s*3.2,0.7,0);g.add(track);
for(let wi=0;wi<4;wi++){const w=new THREE.Mesh(new THREE.CylinderGeometry(0.7,0.7,1.5,8),new THREE.MeshStandardMaterial({color:0x222222}));w.rotation.z=Math.PI/2;w.position.set(s*3.5,0.7,-3+wi*2);g.add(w);}
}
const turBase=new THREE.Mesh(new THREE.CylinderGeometry(1.8,2.0,0.8,8),mat);turBase.position.y=2.4;g.add(turBase);
const turret=new THREE.Mesh(new THREE.BoxGeometry(3.2,1.2,3.8),mat);turret.position.y=3.2;g.add(turret);
const cannon=new THREE.Mesh(new THREE.CylinderGeometry(0.28,0.36,6.5,8),dark);cannon.rotation.x=Math.PI/2;cannon.position.set(0,3.4,4.2);g.add(cannon);
const gl=new THREE.PointLight(c,2,20);gl.position.set(0,3,5);g.add(gl);
// TANK HITBOX - ORANGE, LARGER (tanks are big)
const hitbox = createHitbox({x:12, y:8, z:14}, 0xff8800, g);
g.userData={
type:'tank',
hitbox: hitbox,
health:6+variant*3,
maxHealth:6+variant*3,
speed:4+variant,
shootCooldown:Math.random()*2,
variant,radius:6
};
return g;
}
function createGunship(){
const g=new THREE.Group();
const mat=new THREE.MeshStandardMaterial({color:0xaa2200,emissive:0x330800,roughness:0.5,metalness:0.6});
const dark=new THREE.MeshStandardMaterial({color:0x111111});
const body=new THREE.Mesh(new THREE.CylinderGeometry(1.2,1.5,3.0,7),mat);body.rotation.x=Math.PI/2;g.add(body);
const nose2=new THREE.Mesh(new THREE.ConeGeometry(0.8,2.5,7),mat);nose2.rotation.x=Math.PI/2;nose2.position.z=2.8;g.add(nose2);
const ck=new THREE.Mesh(new THREE.SphereGeometry(0.8,8,6),new THREE.MeshStandardMaterial({color:0x88aaff,emissive:0x001133,transparent:true,opacity:0.8}));
ck.scale.set(0.9,0.65,0.8);ck.position.set(0,0.8,1.8);g.add(ck);
const rHub=new THREE.Mesh(new THREE.CylinderGeometry(0.25,0.25,0.5,6),dark);rHub.position.y=1.8;g.add(rHub);
const rotorBlades=[];
for(let i=0;i<4;i++){const bl=new THREE.Mesh(new THREE.BoxGeometry(4.8,0.08,0.5),mat);bl.rotation.y=i*Math.PI/2;bl.position.y=2.0;g.add(bl);rotorBlades.push(bl);}
for(let sx of[-1.5,1.5]){
const pod2=new THREE.Mesh(new THREE.CylinderGeometry(0.35,0.35,2.2,6),dark);pod2.rotation.x=Math.PI/2;pod2.position.set(sx,-0.8,0.5);g.add(pod2);
const muz=new THREE.Mesh(new THREE.CylinderGeometry(0.15,0.15,0.8,6),new THREE.MeshStandardMaterial({color:0xff4400,emissive:0x551100}));
muz.rotation.x=Math.PI/2;muz.position.set(sx,-0.8,2.0);g.add(muz);
}
const gl2=new THREE.PointLight(0xff4400,3,20);gl2.position.set(0,-0.5,2.5);g.add(gl2);
// GUNSHIP HITBOX - YELLOW/ORANGE
const hitbox = createHitbox({x:10, y:7, z:10}, 0xffaa00, g);
g.userData={
type:'gunship',
hitbox: hitbox,
health:5,
maxHealth:5,
speed:12+Math.random()*5,
shootCooldown:Math.random()*2.5,
hoverPhase:Math.random()*Math.PI*2,
rotorBlades,radius:4
};
return g;
}
function createBoss(tier){
const g=createHunter(tier);
g.scale.setScalar(2.2);
const spk=new THREE.MeshStandardMaterial({color:0xff0000,emissive:0x440000});
for(let i=0;i<6;i++){
const a=i/6*Math.PI*2;
const s=new THREE.Mesh(new THREE.ConeGeometry(0.3,2.5,4),spk);
s.position.set(Math.cos(a)*2.5,1.5,Math.sin(a)*2.5);g.add(s);
}
// BOSS HITBOX - RED, MASSIVE
const hitbox = createHitbox({x:20, y:12, z:20}, 0xff0000, g);
g.userData.hitbox = hitbox;
g.userData.health=50;
g.userData.maxHealth=50;
g.userData.speed=15;
g.userData.isBoss=true;
g.userData.radius=8;
return g;
}
// WEAPON SYSTEMS - INCREASED DAMAGE, SLOWER FIRE
const weapons = {
gatling: { cooldown: 0, maxCooldown: 0.08, damage: 8, speed: 190, spread: 0.02 },
sidewinder: { ammo: 6, maxAmmo: 6, cooldown: 0, maxCooldown: 1.2, damage: 60, speed: 100, turnRate: 0.6 }, // Slower fire (1.2s), higher damage (60)
nuke: { cooldown: 0, maxCooldown: 12, radius: 100, damage: 200, speed: 80, turnRate: 0.4 } // Homing nuke
};
let currentWeapon = 'gatling';
let rmbPressed = false;
let lastShot = 0;
const explosions = [];
function explode(pos, clr=0xff4400, radius=12, particleCount=200){
const geo = new THREE.BufferGeometry();
const verts = new Float32Array(particleCount * 3);
const velocities = [];
for(let i=0; i<particleCount; i++){
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
const r = radius * (0.3 + Math.random() * 0.7);
verts[i*3] = pos.x + r * Math.sin(phi) * Math.cos(theta);
verts[i*3+1] = pos.y + r * Math.sin(phi) * Math.sin(theta);
verts[i*3+2] = pos.z + r * Math.cos(phi);
velocities.push({
x: (verts[i*3] - pos.x) * 2,
y: (verts[i*3+1] - pos.y) * 2,
z: (verts[i*3+2] - pos.z) * 2
});
}
geo.setAttribute('position', new THREE.BufferAttribute(verts, 3));
const mat = new THREE.PointsMaterial({
color: clr,
size: radius * 0.15,
transparent: true,
opacity: 1,
blending: THREE.AdditiveBlending
});
const pts = new THREE.Points(geo, mat);
scene.add(pts);
const ringGeo = new THREE.RingGeometry(radius*0.5, radius*0.6, 32);
const ringMat = new THREE.MeshBasicMaterial({
color: clr,
transparent: true,
opacity: 0.8,
side: THREE.DoubleSide
});
const ring = new THREE.Mesh(ringGeo, ringMat);
ring.position.copy(pos);
ring.lookAt(camera.position);
scene.add(ring);
explosions.push({
pts: pts,
mat: mat,
ring: ring,
velocities: velocities,
life: 1.0,
maxLife: 1.5
});
}
function updateExplosions(dt){
for(let i=explosions.length-1; i>=0; i--){
const exp = explosions[i];
exp.life -= dt;
if(exp.life <= 0){
scene.remove(exp.pts);
scene.remove(exp.ring);
explosions.splice(i, 1);
continue;
}
const positions = exp.pts.geometry.attributes.position.array;
for(let j=0; j<exp.velocities.length; j++){
positions[j*3] += exp.velocities[j].x * dt;
positions[j*3+1] += exp.velocities[j].y * dt;
positions[j*3+2] += exp.velocities[j].z * dt;
exp.velocities[j].x *= 0.98;
exp.velocities[j].y *= 0.98;
exp.velocities[j].z *= 0.98;
}
exp.pts.geometry.attributes.position.needsUpdate = true;
exp.mat.opacity = exp.life / exp.maxLife;
exp.mat.size = exp.mat.size * (1 + dt * 0.5);
exp.ring.scale.multiplyScalar(1 + dt * 2);
exp.ring.material.opacity = 0.8 * (exp.life / exp.maxLife);
}
}
const gatlingRounds = [];
const sidewinders = [];
const nukes = [];
function fireGatling(){
if(!gameActive) return;
const now = performance.now();
if(now - lastShot < 80) return;
lastShot = now;
const fwd = new THREE.Vector3(0,0,-1).applyQuaternion(ship.quaternion);
fwd.x += (Math.random() - 0.5) * weapons.gatling.spread;
fwd.y += (Math.random() - 0.5) * weapons.gatling.spread;
fwd.normalize();
for(let ox of[-4.2,4.2]){
const round = new THREE.Mesh(
new THREE.CylinderGeometry(0.35, 0.35, 2.5, 6),
new THREE.MeshBasicMaterial({color:0xffaa00, emissive:0xff4400})
);
const side = new THREE.Vector3(ox,0,0).applyQuaternion(ship.quaternion);
round.position.copy(ship.position).addScaledVector(side,0.25).addScaledVector(fwd,6);
round.quaternion.copy(ship.quaternion);
round.rotateX(Math.PI/2);
round.userData = {
vel: fwd.clone().multiplyScalar(weapons.gatling.speed),
life: 2.0,
damage: weapons.gatling.damage,
radius: 2.5,
type: 'gatling'
};
scene.add(round);
gatlingRounds.push(round);
}
}
// HEAVY TORPEDO - LARGER, SLOWER, MORE DAMAGE
function fireSidewinder(){
if(!gameActive || weapons.sidewinder.ammo <= 0 || weapons.sidewinder.cooldown > 0) return;
weapons.sidewinder.ammo--;
weapons.sidewinder.cooldown = weapons.sidewinder.maxCooldown;
updateWeaponHUD();
let nearest = null;
let nearestDist = Infinity;
const allEnemies = [...enemies, ...kamikazes, ...gunships, ...groundTanks, ...(bossMesh?[bossMesh]:[])];
for(const e of allEnemies){
const d = ship.position.distanceTo(e.position);
if(d < nearestDist && d < 800){
nearestDist = d;
nearest = e;
}
}
const missile = new THREE.Group();
// LARGER Torpedo body (radius 0.6 vs 0.3, length 5.5 vs 3.5)
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.6, 0.6, 5.5, 16),
new THREE.MeshStandardMaterial({
color: 0x888899,
metalness: 0.9,
roughness: 0.2,
emissive: 0x222244,
emissiveIntensity: 0.3
})
);
body.rotation.x = Math.PI/2;
missile.add(body);
// Nose cone
const nose = new THREE.Mesh(
new THREE.ConeGeometry(0.6, 1.2, 16),
new THREE.MeshStandardMaterial({color: 0xaaaaaa, metalness: 0.95, roughness: 0.1})
);
nose.rotation.x = Math.PI/2;
nose.position.z = 3.35;
missile.add(nose);
// Larger tail fins
const finMat = new THREE.MeshStandardMaterial({color: 0xff4400, emissive: 0x441100});
for(let i=0; i<4; i++){
const fin = new THREE.Mesh(
new THREE.BoxGeometry(0.08, 1.4, 0.9),
finMat
);
fin.position.z = -3.0;
fin.rotation.z = (i * Math.PI) / 2;
fin.rotation.x = 0.4;
missile.add(fin);
}
// Engine glow
const engineGlow = new THREE.Mesh(
new THREE.SphereGeometry(0.4, 12, 12),
new THREE.MeshBasicMaterial({color: 0x00ffff})
);
engineGlow.position.z = -2.8;
missile.add(engineGlow);
const engineLight = new THREE.PointLight(0x00ffff, 4, 20);
engineLight.position.z = -3.2;
missile.add(engineLight);
if(nearest){
const ring = new THREE.Mesh(
new THREE.RingGeometry(3, 3.2, 16),
new THREE.MeshBasicMaterial({color: 0x00ffff, side: THREE.DoubleSide})
);
ring.position.copy(nearest.position);
ring.userData = { target: nearest, life: 3 };
scene.add(ring);
setTimeout(() => { if(ring.parent) scene.remove(ring); }, 3000);
}
const fwd = new THREE.Vector3(0,0,-1).applyQuaternion(ship.quaternion);
missile.position.copy(ship.position).addScaledVector(fwd, 10);
missile.quaternion.copy(ship.quaternion);
missile.userData = {
vel: fwd.multiplyScalar(weapons.sidewinder.speed),
life: 6.0,
damage: weapons.sidewinder.damage,
target: nearest,
turnRate: weapons.sidewinder.turnRate,
type: 'sidewinder',
radius: 4,
trailTimer: 0
};
scene.add(missile);
sidewinders.push(missile);
if(weapons.sidewinder.ammo === weapons.sidewinder.maxAmmo - 1){
startSidewinderReload();
}
}
let sidewinderReloadInterval = null;
function startSidewinderReload(){
if(sidewinderReloadInterval) return;
sidewinderReloadInterval = setInterval(() => {
if(!gameActive){
clearInterval(sidewinderReloadInterval);
sidewinderReloadInterval = null;
return;
}
if(weapons.sidewinder.ammo < weapons.sidewinder.maxAmmo){
weapons.sidewinder.ammo++;
updateWeaponHUD();
} else {
clearInterval(sidewinderReloadInterval);
sidewinderReloadInterval = null;
}
}, 4000); // 4 seconds per missile (slower)
}
// HOMING NUKE - Seeks targets
function fireNuke(){
if(!gameActive || weapons.nuke.cooldown > 0) return;
weapons.nuke.cooldown = weapons.nuke.maxCooldown;
updateWeaponHUD();
// Find nearest target for initial heading
let nearest = null;
let nearestDist = Infinity;
const allEnemies = [...enemies, ...kamikazes, ...gunships, ...groundTanks, ...(bossMesh?[bossMesh]:[])];
for(const e of allEnemies){
const d = ship.position.distanceTo(e.position);
if(d < nearestDist && d < 1000){
nearestDist = d;
nearest = e;
}
}
const nukeGroup = new THREE.Group();
// Core sphere - bright green
const coreMat = new THREE.MeshStandardMaterial({
color: 0x88ff00,
emissive: 0x44ff00,
emissiveIntensity: 3,
transparent: true,
opacity: 0.95
});
const core = new THREE.Mesh(new THREE.SphereGeometry(2.0, 32, 32), coreMat);
nukeGroup.add(core);
// Rotating energy rings
const ring1Geo = new THREE.TorusGeometry(3.0, 0.2, 8, 32);
const ring1Mat = new THREE.MeshBasicMaterial({
color: 0xaaff00,
transparent: true,
opacity: 0.9
});
const ring1 = new THREE.Mesh(ring1Geo, ring1Mat);
ring1.rotation.x = Math.PI/2;
nukeGroup.add(ring1);
const ring2Geo = new THREE.TorusGeometry(4.0, 0.15, 8, 32);
const ring2Mat = new THREE.MeshBasicMaterial({
color: 0xffff00,
transparent: true,
opacity: 0.7
});
const ring2 = new THREE.Mesh(ring2Geo, ring2Mat);
ring2.rotation.y = Math.PI/2;
nukeGroup.add(ring2);
// Outer glow
const canvas = document.createElement('canvas');
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext('2d');
const grad = ctx.createRadialGradient(64,64,0,64,64,64);
grad.addColorStop(0, 'rgba(136,255,0,0.8)');
grad.addColorStop(0.5, 'rgba(100,200,0,0.4)');
grad.addColorStop(1, 'rgba(0,0,0,0)');
ctx.fillStyle = grad;
ctx.fillRect(0,0,128,128);
const glowTex = new THREE.CanvasTexture(canvas);
const glowSprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: glowTex,
transparent: true,
blending: THREE.AdditiveBlending
})
);
glowSprite.scale.set(12, 12, 1);
nukeGroup.add(glowSprite);
const nukeLight = new THREE.PointLight(0x88ff00, 8, 80);
nukeGroup.add(nukeLight);
const fwd = new THREE.Vector3(0,0,-1).applyQuaternion(ship.quaternion);
nukeGroup.position.copy(ship.position).addScaledVector(fwd, 12);
scene.add(nukeGroup);
nukes.push({
mesh: nukeGroup,
core: core,
ring1: ring1,
ring2: ring2,
glow: glowSprite,
vel: fwd.multiplyScalar(weapons.nuke.speed),
life: 5.0,
target: nearest, // Store target for homing
turnRate: weapons.nuke.turnRate,
armed: false,
armTime: 0.5,
pulsePhase: 0
});
}
function updateProjectiles(dt){
// Gatling
for(let i=gatlingRounds.length-1; i>=0; i--){
const p = gatlingRounds[i];
if(!p.parent) { gatlingRounds.splice(i,1); continue; }
p.position.addScaledVector(p.userData.vel, dt);
p.userData.life -= dt;
if(p.userData.life <= 0 || p.position.length() > 2000){
scene.remove(p);
gatlingRounds.splice(i, 1);
}
}
// Heavy Torpedoes
for(let i=sidewinders.length-1; i>=0; i--){
const m = sidewinders[i];
if(!m.parent) { sidewinders.splice(i,1); continue; }
m.userData.trailTimer += dt;
if(m.userData.trailTimer > 0.03){
m.userData.trailTimer = 0;
const trail = new THREE.Mesh(
new THREE.SphereGeometry(0.3, 8, 8),
new THREE.MeshBasicMaterial({color: 0x00ffff, transparent: true, opacity: 0.5})
);
trail.position.copy(m.position);
trail.position.z += 2.0;
scene.add(trail);
setTimeout(() => { if(trail.parent) scene.remove(trail); }, 600);
}
if(m.userData.target && m.userData.target.parent){
const toTarget = new THREE.Vector3().subVectors(m.userData.target.position, m.position);
const dist = toTarget.length();
const toTargetNorm = toTarget.normalize();
const forward = m.userData.vel.clone().normalize();
const dot = forward.dot(toTargetNorm);
if(dot > 0.2 && dist < 1200){
const turnAxis = new THREE.Vector3().crossVectors(forward, toTargetNorm).normalize();
const angle = Math.acos(Math.max(-1, Math.min(1, dot)));
const turnAngle = Math.min(m.userData.turnRate * dt, angle);
const q = new THREE.Quaternion().setFromAxisAngle(turnAxis, turnAngle);
forward.applyQuaternion(q);
forward.normalize();
m.userData.vel = forward.multiplyScalar(weapons.sidewinder.speed);
m.quaternion.setFromUnitVectors(new THREE.Vector3(0,0,-1), forward);
}
if(dist < 8){
explode(m.position, 0x00aaff, 25, 150);
checkNukeDamage(m.position, 25, m.userData.damage);
scene.remove(m);
sidewinders.splice(i, 1);
continue;
}
}
m.position.addScaledVector(m.userData.vel, dt);
m.userData.life -= dt;
if(m.userData.life <= 0){
scene.remove(m);
sidewinders.splice(i, 1);
}
}
// Homing Nukes
for(let i=nukes.length-1; i>=0; i--){
const nuke = nukes[i];
if(!nuke.mesh.parent) { nukes.splice(i,1); continue; }
nuke.mesh.position.addScaledVector(nuke.vel, dt);
nuke.life -= dt;
nuke.armTime -= dt;
// Homing logic
if(nuke.target && nuke.target.parent){
const toTarget = new THREE.Vector3().subVectors(nuke.target.position, nuke.mesh.position);
const dist = toTarget.length();
const toTargetNorm = toTarget.normalize();
const forward = nuke.vel.clone().normalize();
const dot = forward.dot(toTargetNorm);
// Nuke homes aggressively but slowly
if(dot > -0.5 && dist < 1500){ // Can turn around somewhat
const turnAxis = new THREE.Vector3().crossVectors(forward, toTargetNorm).normalize();
const angle = Math.acos(Math.max(-1, Math.min(1, dot)));
const turnAngle = Math.min(nuke.turnRate * dt, angle);
const q = new THREE.Quaternion().setFromAxisAngle(turnAxis, turnAngle);
forward.applyQuaternion(q);
forward.normalize();
nuke.vel = forward.multiplyScalar(weapons.nuke.speed);
// Look at target
nuke.mesh.lookAt(nuke.mesh.position.clone().add(nuke.vel));
}
}
// Visual effects
nuke.pulsePhase += dt * 4;
const pulse = 1 + Math.sin(nuke.pulsePhase) * 0.3;
nuke.core.scale.setScalar(pulse);
nuke.core.material.emissiveIntensity = 3 + Math.sin(nuke.pulsePhase * 2) * 1;
nuke.ring1.rotation.z += dt * 3;
nuke.ring1.rotation.x = Math.PI/2 + Math.sin(nuke.pulsePhase) * 0.3;
nuke.ring2.rotation.x += dt * 2;
nuke.ring2.rotation.y = Math.PI/2 + Math.cos(nuke.pulsePhase) * 0.3;
nuke.glow.material.opacity = 0.8 + Math.sin(nuke.pulsePhase * 3) * 0.2;
if(nuke.armTime <= 0 && !nuke.armed){
nuke.armed = true;
}
if(nuke.life <= 0 && nuke.armed){
const pos = nuke.mesh.position.clone();
explode(pos, 0x88ff00, weapons.nuke.radius, 800);
explode(pos, 0xffff00, weapons.nuke.radius * 0.6, 600);
camera.position.add(new THREE.Vector3(
(Math.random()-0.5)*20,
(Math.random()-0.5)*20,
(Math.random()-0.5)*20
));
const flash = document.createElement('div');
flash.style.cssText = 'position:fixed;inset:0;background:#8f0;opacity:0.4;z-index:50;pointer-events:none;transition:opacity 0.5s';
document.body.appendChild(flash);
setTimeout(() => flash.style.opacity = '0', 50);
setTimeout(() => flash.remove(), 550);
checkNukeDamage(pos, weapons.nuke.radius, weapons.nuke.damage);
scene.remove(nuke.mesh);
nukes.splice(i, 1);
} else if(nuke.life <= -2) {
scene.remove(nuke.mesh);
nukes.splice(i, 1);
}
}
if(weapons.nuke.cooldown > 0) weapons.nuke.cooldown -= dt;
if(weapons.sidewinder.cooldown > 0) weapons.sidewinder.cooldown -= dt;
updateWeaponHUD();
}
function checkNukeDamage(pos, radius, damage){
const allTargets = [
...enemies.map(e => ({obj:e, list:enemies, pts:10})),
...kamikazes.map(k => ({obj:k, list:kamikazes, pts:25})),
...groundTanks.map(t => ({obj:t, list:groundTanks, pts:30})),
...gunships.map(g => ({obj:g, list:gunships, pts:20})),
...(bossMesh?[{obj:bossMesh, list:null, pts:100}]:[])
];
for(const {obj, list, pts} of allTargets){
if(!obj.parent) continue;
const dist = pos.distanceTo(obj.position);
if(dist < radius){
const dmg = Math.floor(damage * (1 - dist/radius));
obj.userData.health -= dmg;
if(obj.userData.hitbox) obj.userData.hitbox.flash();
if(obj.userData.health <= 0){
explode(obj.position, 0xff4400, 15, 150);
scene.remove(obj);
if(list){
const idx = list.indexOf(obj);
if(idx > -1) list.splice(idx, 1);
} else {
bossMesh = null;
}
score += pts;
kills++;
killsForPayload++;
if(killsForPayload >= 5 && payloadCharges === 0){
payloadCharges = 1;
killsForPayload = 0;
flashMsg('⚡ PAYLOAD RECHARGED!', '#f0f');
}
checkZoneClear();
}
}
}
}
function updateWeaponHUD(){
const sw = document.getElementById('ammoSidewinder');
const nk = document.getElementById('ammoNuke');
if(sw) sw.textContent = weapons.sidewinder.ammo;
if(nk) nk.textContent = weapons.nuke.cooldown > 0 ? Math.ceil(weapons.nuke.cooldown) : 'READY';
}
const keys = {};
window.addEventListener('keydown', e => {
const k = e.key.toLowerCase();
keys[k] = true;
if([' ','shift','f','arrowup','arrowdown','arrowleft','arrowright'].includes(k)) e.preventDefault();