File size: 33,423 Bytes
da852f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3D Rocket Launcher with Tanks</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/controls/OrbitControls.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/loaders/GLTFLoader.min.js"></script>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            font-family: 'Arial', sans-serif;
        }
        #canvas-container {
            position: absolute;
            width: 100%;
            height: 100%;
        }
        #ui {
            position: absolute;
            top: 20px;
            left: 20px;
            z-index: 100;
            color: white;
            text-shadow: 1px 1px 2px black;
        }
        #flag {
            position: absolute;
            width: 40px;
            height: 60px;
            background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="red" d="M14.4 6L14 4H5v17h2v-7h5.6l.4 2h7V6z"/></svg>');
            background-size: contain;
            background-repeat: no-repeat;
            cursor: move;
            z-index: 50;
            user-select: none;
        }
        #launch-btn {
            position: absolute;
            bottom: 30px;
            left: 50%;
            transform: translateX(-50%);
            padding: 12px 24px;
            background: linear-gradient(to right, #ff5e62, #ff9966);
            color: white;
            border: none;
            border-radius: 30px;
            font-size: 18px;
            font-weight: bold;
            cursor: pointer;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
            z-index: 100;
            transition: all 0.3s;
        }
        #launch-btn:hover {
            transform: translateX(-50%) scale(1.05);
            box-shadow: 0 6px 20px rgba(0,0,0,0.3);
        }
        #launch-btn:active {
            transform: translateX(-50%) scale(0.98);
        }
        .explosion-particle {
            position: absolute;
            width: 8px;
            height: 8px;
            border-radius: 50%;
            pointer-events: none;
        }
        #counter {
            position: absolute;
            top: 20px;
            right: 20px;
            color: white;
            font-size: 18px;
            text-shadow: 1px 1px 2px black;
            z-index: 100;
        }
        #tank-counter {
            position: absolute;
            top: 50px;
            right: 20px;
            color: white;
            font-size: 18px;
            text-shadow: 1px 1px 2px black;
            z-index: 100;
        }
        #message {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: rgba(0,0,0,0.7);
            color: white;
            padding: 20px 40px;
            border-radius: 10px;
            font-size: 24px;
            font-weight: bold;
            opacity: 0;
            transition: opacity 0.5s;
            pointer-events: none;
            z-index: 200;
        }
    </style>
</head>
<body>
    <div id="canvas-container"></div>
    <div id="ui">
        <h1 class="text-3xl font-bold">🚀 Rocket Launcher</h1>
        <p class="text-lg">Drag the flag to set target, then launch!</p>
    </div>
    <div id="counter">Rockets launched: <span id="rocket-count">0</span></div>
    <div id="tank-counter">Tanks destroyed: <span id="tank-count">0</span></div>
    <div id="message"></div>
    <div id="flag"></div>
    <button id="launch-btn">LAUNCH ROCKET</button>

    <script>
        // Scene setup
        const scene = new THREE.Scene();
        scene.background = new THREE.Color(0x87CEEB);
        scene.fog = new THREE.FogExp2(0x87CEEB, 0.002);

        // Camera
        const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
        camera.position.set(0, 10, 30);

        // Renderer
        const renderer = new THREE.WebGLRenderer({ antialias: true });
        renderer.setSize(window.innerWidth, window.innerHeight);
        renderer.shadowMap.enabled = true;
        document.getElementById('canvas-container').appendChild(renderer.domElement);

        // Controls
        const controls = new THREE.OrbitControls(camera, renderer.domElement);
        controls.enableDamping = true;
        controls.dampingFactor = 0.05;
        controls.minDistance = 10;
        controls.maxDistance = 100;

        // Lights
        const ambientLight = new THREE.AmbientLight(0x404040);
        scene.add(ambientLight);

        const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
        directionalLight.position.set(10, 20, 10);
        directionalLight.castShadow = true;
        directionalLight.shadow.mapSize.width = 2048;
        directionalLight.shadow.mapSize.height = 2048;
        scene.add(directionalLight);

        // Ground
        const groundGeometry = new THREE.PlaneGeometry(200, 200);
        const groundMaterial = new THREE.MeshStandardMaterial({ 
            color: 0x3a5f0b,
            roughness: 0.8,
            metalness: 0.2
        });
        const ground = new THREE.Mesh(groundGeometry, groundMaterial);
        ground.rotation.x = -Math.PI / 2;
        ground.receiveShadow = true;
        scene.add(ground);

        // Launch pad
        const padGeometry = new THREE.CylinderGeometry(3, 3, 0.5, 32);
        const padMaterial = new THREE.MeshStandardMaterial({ 
            color: 0x555555,
            roughness: 0.7,
            metalness: 0.3
        });
        const launchPad = new THREE.Mesh(padGeometry, padMaterial);
        launchPad.position.set(0, 0.25, 0);
        launchPad.receiveShadow = true;
        scene.add(launchPad);

        // Active rockets and smoke trails
        let activeRockets = [];
        let smokeParticles = [];
        let rocketCount = 0;
        let tankCount = 0;
        let tanks = [];
        const messageElement = document.getElementById('message');

        // Show message
        function showMessage(text, duration = 2000) {
            messageElement.textContent = text;
            messageElement.style.opacity = 1;
            setTimeout(() => {
                messageElement.style.opacity = 0;
            }, duration);
        }

        // Create a detailed tank
        function createTank(position) {
            const tankGroup = new THREE.Group();
            tankGroup.position.copy(position);
            tankGroup.userData = {
                isAlive: true,
                health: 100
            };

            // Tank body
            const bodyGeometry = new THREE.BoxGeometry(3, 1.5, 5);
            const bodyMaterial = new THREE.MeshStandardMaterial({ 
                color: 0x556b2f,
                roughness: 0.8,
                metalness: 0.3
            });
            const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
            body.position.y = 1;
            body.castShadow = true;
            body.receiveShadow = true;
            tankGroup.add(body);

            // Tank turret
            const turretGeometry = new THREE.CylinderGeometry(1.2, 1.2, 1, 32);
            const turretMaterial = new THREE.MeshStandardMaterial({ 
                color: 0x556b2f,
                roughness: 0.8,
                metalness: 0.3
            });
            const turret = new THREE.Mesh(turretGeometry, turretMaterial);
            turret.position.y = 2.2;
            turret.rotation.x = Math.PI / 2;
            turret.castShadow = true;
            turret.receiveShadow = true;
            tankGroup.add(turret);

            // Tank gun
            const gunGeometry = new THREE.CylinderGeometry(0.3, 0.3, 4, 32);
            const gunMaterial = new THREE.MeshStandardMaterial({ 
                color: 0x444444,
                roughness: 0.6,
                metalness: 0.4
            });
            const gun = new THREE.Mesh(gunGeometry, gunMaterial);
            gun.position.y = 2.2;
            gun.position.z = -2;
            gun.rotation.x = Math.PI / 2;
            gun.castShadow = true;
            gun.receiveShadow = true;
            tankGroup.add(gun);

            // Tank tracks (left)
            const leftTrackGeometry = new THREE.BoxGeometry(3.5, 0.8, 5.5);
            const leftTrackMaterial = new THREE.MeshStandardMaterial({ 
                color: 0x333333,
                roughness: 0.9,
                metalness: 0.1
            });
            const leftTrack = new THREE.Mesh(leftTrackGeometry, leftTrackMaterial);
            leftTrack.position.set(-1.8, 0.5, 0);
            leftTrack.castShadow = true;
            leftTrack.receiveShadow = true;
            tankGroup.add(leftTrack);

            // Tank tracks (right)
            const rightTrackGeometry = new THREE.BoxGeometry(3.5, 0.8, 5.5);
            const rightTrackMaterial = new THREE.MeshStandardMaterial({ 
                color: 0x333333,
                roughness: 0.9,
                metalness: 0.1
            });
            const rightTrack = new THREE.Mesh(rightTrackGeometry, rightTrackMaterial);
            rightTrack.position.set(1.8, 0.5, 0);
            rightTrack.castShadow = true;
            rightTrack.receiveShadow = true;
            tankGroup.add(rightTrack);

            // Tank details (hatch)
            const hatchGeometry = new THREE.CylinderGeometry(0.5, 0.5, 0.2, 32);
            const hatchMaterial = new THREE.MeshStandardMaterial({ 
                color: 0x666666,
                roughness: 0.7,
                metalness: 0.5
            });
            const hatch = new THREE.Mesh(hatchGeometry, hatchMaterial);
            hatch.position.set(0, 2.5, -1);
            hatch.castShadow = true;
            hatch.receiveShadow = true;
            tankGroup.add(hatch);

            // Tank details (lights)
            const lightGeometry = new THREE.SphereGeometry(0.3, 16, 16);
            const lightMaterial = new THREE.MeshStandardMaterial({ 
                color: 0xffff00,
                emissive: 0xffff00,
                emissiveIntensity: 0.5
            });
            
            // Left light
            const leftLight = new THREE.Mesh(lightGeometry, lightMaterial);
            leftLight.position.set(-1.5, 1.5, -2.5);
            leftLight.castShadow = true;
            tankGroup.add(leftLight);
            
            // Right light
            const rightLight = new THREE.Mesh(lightGeometry, lightMaterial);
            rightLight.position.set(1.5, 1.5, -2.5);
            rightLight.castShadow = true;
            tankGroup.add(rightLight);

            // Random rotation
            tankGroup.rotation.y = Math.random() * Math.PI * 2;

            // Add tank to scene
            scene.add(tankGroup);
            tanks.push(tankGroup);

            return tankGroup;
        }

        // Spawn tanks at random positions
        function spawnTanks(count) {
            for (let i = 0; i < count; i++) {
                // Random position within bounds
                const x = (Math.random() - 0.5) * 80;
                const z = (Math.random() - 0.5) * 80;
                const position = new THREE.Vector3(x, 0, z);
                
                // Make sure position is not too close to launch pad
                if (position.distanceTo(new THREE.Vector3(0, 0, 0)) > 15) {
                    createTank(position);
                }
            }
        }

        // Initialize tanks
        spawnTanks(5);

        // Rocket
        function createRocket() {
            const group = new THREE.Group();
            group.userData = {
                isFlying: false,
                startTime: 0,
                target: new THREE.Vector3(10, 0, 10),
                lastPosition: new THREE.Vector3(0, 0, 0),
                smokeTrail: [],
                hasExploded: false
            };

            // Rocket body
            const bodyGeometry = new THREE.CylinderGeometry(0.5, 0.3, 3, 32);
            const bodyMaterial = new THREE.MeshStandardMaterial({ 
                color: 0xffffff,
                roughness: 0.2,
                metalness: 0.7
            });
            const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
            body.position.y = 1.5;
            body.castShadow = true;
            group.add(body);

            // Rocket nose
            const noseGeometry = new THREE.ConeGeometry(0.5, 1, 32);
            const noseMaterial = new THREE.MeshStandardMaterial({ 
                color: 0xff0000,
                roughness: 0.2,
                metalness: 0.7
            });
            const nose = new THREE.Mesh(noseGeometry, noseMaterial);
            nose.position.y = 3.5;
            nose.castShadow = true;
            group.add(nose);

            // Fins
            const finGeometry = new THREE.BoxGeometry(0.8, 0.1, 0.5);
            const finMaterial = new THREE.MeshStandardMaterial({ 
                color: 0x0000ff,
                roughness: 0.5,
                metalness: 0.3
            });

            for (let i = 0; i < 3; i++) {
                const fin = new THREE.Mesh(finGeometry, finMaterial);
                fin.position.y = 0.5;
                fin.rotation.y = (i * Math.PI * 2) / 3;
                fin.position.x = Math.sin(fin.rotation.y) * 0.6;
                fin.position.z = Math.cos(fin.rotation.y) * 0.6;
                fin.rotation.z = Math.PI / 4;
                fin.castShadow = true;
                group.add(fin);
            }

            // Engine
            const engineGeometry = new THREE.CylinderGeometry(0.4, 0.5, 0.5, 32);
            const engineMaterial = new THREE.MeshStandardMaterial({ 
                color: 0x333333,
                roughness: 0.8,
                metalness: 0.1
            });
            const engine = new THREE.Mesh(engineGeometry, engineMaterial);
            engine.position.y = 0.25;
            engine.castShadow = true;
            group.add(engine);

            // Flame (will be animated)
            const flameGeometry = new THREE.ConeGeometry(0.6, 1.5, 32);
            const flameMaterial = new THREE.MeshStandardMaterial({ 
                color: 0xff6600,
                emissive: 0xff6600,
                emissiveIntensity: 1,
                transparent: true,
                opacity: 0.8
            });
            const flame = new THREE.Mesh(flameGeometry, flameMaterial);
            flame.position.y = -0.5;
            flame.rotation.x = Math.PI;
            group.add(flame);
            group.userData.flame = flame;

            group.position.set(0, 0, 0);
            group.scale.set(0.8, 0.8, 0.8);
            return group;
        }

        // Create smoke particle
        function createSmokeParticle(position) {
            const size = 1 + Math.random() * 2;
            const geometry = new THREE.SphereGeometry(size, 8, 8);
            const material = new THREE.MeshStandardMaterial({
                color: 0xeeeeee,
                transparent: true,
                opacity: 0.7,
                roughness: 0.9,
                metalness: 0
            });
            
            const particle = new THREE.Mesh(geometry, material);
            particle.position.copy(position);
            particle.userData = {
                createdAt: Date.now(),
                lifeTime: 3000 + Math.random() * 2000, // 3-5 seconds
                velocity: new THREE.Vector3(
                    (Math.random() - 0.5) * 0.1,
                    Math.random() * 0.05,
                    (Math.random() - 0.5) * 0.1
                ),
                growthRate: 0.02 + Math.random() * 0.03
            };
            
            scene.add(particle);
            return particle;
        }

        // Flag dragging
        const flag = document.getElementById('flag');
        let isDragging = false;
        let offsetX, offsetY;

        flag.addEventListener('mousedown', (e) => {
            isDragging = true;
            offsetX = e.clientX - flag.offsetLeft;
            offsetY = e.clientY - flag.offsetTop;
            flag.style.opacity = '0.8';
        });

        document.addEventListener('mousemove', (e) => {
            if (!isDragging) return;
            
            flag.style.left = (e.clientX - offsetX) + 'px';
            flag.style.top = (e.clientY - offsetY) + 'px';
        });

        document.addEventListener('mouseup', () => {
            isDragging = false;
            flag.style.opacity = '1';
        });

        // Convert screen position to 3D world position
        function screenToWorld(x, y) {
            const vector = new THREE.Vector3(
                (x / window.innerWidth) * 2 - 1,
                -(y / window.innerHeight) * 2 + 1,
                0.5
            );
            vector.unproject(camera);
            const dir = vector.sub(camera.position).normalize();
            const distance = -camera.position.y / dir.y;
            const pos = camera.position.clone().add(dir.multiplyScalar(distance));
            return pos;
        }

        // Launch rocket
        const launchBtn = document.getElementById('launch-btn');
        const rocketCountElement = document.getElementById('rocket-count');
        const tankCountElement = document.getElementById('tank-count');

        launchBtn.addEventListener('click', () => {
            // Get flag position in 3D world
            const flagRect = flag.getBoundingClientRect();
            const flagCenterX = flagRect.left + flagRect.width / 2;
            const flagCenterY = flagRect.top + flagRect.height / 2;
            const target = screenToWorld(flagCenterX, flagCenterY);
            
            // Create rocket
            const rocket = createRocket();
            rocket.userData.isFlying = true;
            rocket.userData.startTime = Date.now();
            rocket.userData.target = target;
            rocket.userData.lastPosition = new THREE.Vector3(0, 0, 0);
            
            scene.add(rocket);
            activeRockets.push(rocket);
            
            // Update counter
            rocketCount++;
            rocketCountElement.textContent = rocketCount;
            
            // Animate flame
            animateFlame(rocket);
        });

        // Animate rocket flame
        function animateFlame(rocket) {
            if (!rocket.userData.isFlying) return;
            
            const flame = rocket.userData.flame;
            if (flame) {
                // Randomize flame size for flickering effect
                const scale = 0.8 + Math.random() * 0.4;
                flame.scale.set(scale, scale, scale);
            }
            
            requestAnimationFrame(() => animateFlame(rocket));
        }

        // Create explosion
        function createExplosion(position, scale = 1, colorChoices = null) {
            if (!colorChoices) {
                colorChoices = [
                    new THREE.Color(0xff6600), // Orange
                    new THREE.Color(0xff0000), // Red
                    new THREE.Color(0xffff00), // Yellow
                    new THREE.Color(0xffffff)  // White
                ];
            }
            
            // Create particles
            const particleCount = Math.floor(200 * scale);
            const particles = new THREE.BufferGeometry();
            const positions = new Float32Array(particleCount * 3);
            const colors = new Float32Array(particleCount * 3);
            const sizes = new Float32Array(particleCount);
            
            for (let i = 0; i < particleCount; i++) {
                // Random position in sphere
                const theta = Math.random() * Math.PI * 2;
                const phi = Math.random() * Math.PI;
                const radius = 0.1 + Math.random() * 2 * scale;
                
                positions[i * 3] = position.x + radius * Math.sin(phi) * Math.cos(theta);
                positions[i * 3 + 1] = position.y + radius * Math.cos(phi);
                positions[i * 3 + 2] = position.z + radius * Math.sin(phi) * Math.sin(theta);
                
                // Random color
                const color = colorChoices[Math.floor(Math.random() * colorChoices.length)];
                colors[i * 3] = color.r;
                colors[i * 3 + 1] = color.g;
                colors[i * 3 + 2] = color.b;
                
                // Random size
                sizes[i] = (0.5 + Math.random() * 1.5) * scale;
            }
            
            particles.setAttribute('position', new THREE.BufferAttribute(positions, 3));
            particles.setAttribute('color', new THREE.BufferAttribute(colors, 3));
            particles.setAttribute('size', new THREE.BufferAttribute(sizes, 1));
            
            // Particle material
            const particleMaterial = new THREE.PointsMaterial({
                size: 1 * scale,
                vertexColors: true,
                transparent: true,
                opacity: 0.8,
                blending: THREE.AdditiveBlending
            });
            
            const particleSystem = new THREE.Points(particles, particleMaterial);
            scene.add(particleSystem);
            
            // Animate particles
            const startTime = Date.now();
            const duration = 2000 * scale; // 2 seconds
            
            function animateParticles() {
                const elapsed = Date.now() - startTime;
                const progress = elapsed / duration;
                
                if (progress >= 1) {
                    scene.remove(particleSystem);
                    return;
                }
                
                // Update particle positions (fly outward and fade)
                const positions = particles.attributes.position.array;
                for (let i = 0; i < particleCount; i++) {
                    // Move particles outward
                    positions[i * 3] += (positions[i * 3] - position.x) * 0.02;
                    positions[i * 3 + 1] += (positions[i * 3 + 1] - position.y) * 0.02;
                    positions[i * 3 + 2] += (positions[i * 3 + 2] - position.z) * 0.02;
                    
                    // Add some randomness
                    positions[i * 3] += (Math.random() - 0.5) * 0.2 * scale;
                    positions[i * 3 + 1] += (Math.random() - 0.5) * 0.2 * scale;
                    positions[i * 3 + 2] += (Math.random() - 0.5) * 0.2 * scale;
                }
                
                particles.attributes.position.needsUpdate = true;
                particleMaterial.opacity = 1 - progress;
                
                requestAnimationFrame(animateParticles);
            }
            
            animateParticles();
        }

        // Create tank explosion
        function createTankExplosion(position) {
            // Big explosion
            createExplosion(position, 2, [
                new THREE.Color(0xff0000), // Red
                new THREE.Color(0xffff00), // Yellow
                new THREE.Color(0x000000), // Black
                new THREE.Color(0x333333)  // Dark gray
            ]);
            
            // Secondary explosions
            for (let i = 0; i < 3; i++) {
                setTimeout(() => {
                    const offset = new THREE.Vector3(
                        (Math.random() - 0.5) * 3,
                        Math.random() * 0.5,
                        (Math.random() - 0.5) * 3
                    );
                    createExplosion(position.clone().add(offset), 0.5, [
                        new THREE.Color(0xff6600),
                        new THREE.Color(0x333333)
                    ]);
                }, 100 + Math.random() * 400);
            }
            
            // Smoke plume
            for (let i = 0; i < 10; i++) {
                setTimeout(() => {
                    const smokePos = position.clone();
                    smokePos.y += Math.random() * 2;
                    createSmokeParticle(smokePos);
                }, i * 100);
            }
        }

        // Check for rocket-tank collisions
        function checkCollisions() {
            for (let i = activeRockets.length - 1; i >= 0; i--) {
                const rocket = activeRockets[i];
                
                if (rocket.userData.hasExploded) continue;
                
                for (let j = tanks.length - 1; j >= 0; j--) {
                    const tank = tanks[j];
                    
                    if (!tank.userData.isAlive) continue;
                    
                    // Simple distance check
                    const distance = rocket.position.distanceTo(tank.position);
                    if (distance < 3) { // Collision detected
                        // Tank takes damage
                        tank.userData.health -= 50;
                        
                        // Create explosion at collision point
                        createExplosion(rocket.position);
                        rocket.userData.hasExploded = true;
                        
                        // Remove rocket
                        scene.remove(rocket);
                        activeRockets.splice(i, 1);
                        
                        // Check if tank is destroyed
                        if (tank.userData.health <= 0) {
                            tank.userData.isAlive = false;
                            createTankExplosion(tank.position);
                            scene.remove(tank);
                            tanks.splice(j, 1);
                            
                            // Update counter
                            tankCount++;
                            tankCountElement.textContent = tankCount;
                            
                            // Show message
                            const messages = [
                                "Tank Destroyed!",
                                "Direct Hit!",
                                "Boom!",
                                "Target Eliminated!"
                            ];
                            showMessage(messages[Math.floor(Math.random() * messages.length)]);
                            
                            // Spawn new tank after a delay
                            setTimeout(() => {
                                spawnTanks(1);
                            }, 3000);
                        }
                        
                        break;
                    }
                }
            }
        }

        // Update smoke particles
        function updateSmokeParticles() {
            const now = Date.now();
            
            // Update existing smoke particles
            for (let i = smokeParticles.length - 1; i >= 0; i--) {
                const particle = smokeParticles[i];
                const age = now - particle.userData.createdAt;
                
                if (age > particle.userData.lifeTime) {
                    // Remove expired particles
                    scene.remove(particle);
                    smokeParticles.splice(i, 1);
                } else {
                    // Update position and size
                    particle.position.x += particle.userData.velocity.x;
                    particle.position.y += particle.userData.velocity.y;
                    particle.position.z += particle.userData.velocity.z;
                    
                    // Grow over time
                    const scale = 1 + (particle.userData.growthRate * age / 1000);
                    particle.scale.set(scale, scale, scale);
                    
                    // Fade out
                    particle.material.opacity = 0.7 * (1 - (age / particle.userData.lifeTime));
                }
            }
            
            // Add new smoke particles for each rocket
            for (const rocket of activeRockets) {
                if (rocket.userData.isFlying && rocket.position.y > 1 && !rocket.userData.hasExploded) {
                    // Only add smoke when rocket is above ground
                    if (Math.random() < 0.3) { // Control density of smoke trail
                        const smokeParticle = createSmokeParticle(rocket.position.clone());
                        smokeParticles.push(smokeParticle);
                    }
                }
            }
        }

        // Animation loop
        function animate() {
            requestAnimationFrame(animate);
            
            // Update controls
            controls.update();
            
            // Update smoke particles
            updateSmokeParticles();
            
            // Check for collisions
            checkCollisions();
            
            // Update all active rockets
            for (let i = activeRockets.length - 1; i >= 0; i--) {
                const rocket = activeRockets[i];
                const elapsed = Date.now() - rocket.userData.startTime;
                const progress = Math.min(elapsed / 5000, 1); // 5 second flight duration
                
                if (progress >= 1 && !rocket.userData.hasExploded) {
                    // Rocket reached target - explode!
                    createExplosion(rocket.position);
                    rocket.userData.hasExploded = true;
                    scene.remove(rocket);
                    activeRockets.splice(i, 1);
                } else if (!rocket.userData.hasExploded) {
                    // Calculate bezier curve path
                    const startPoint = new THREE.Vector3(0, 0, 0);
                    const controlPoint1 = new THREE.Vector3(
                        rocket.userData.target.x * 0.3,
                        rocket.userData.target.y + 30,
                        rocket.userData.target.z * 0.3
                    );
                    const controlPoint2 = new THREE.Vector3(
                        rocket.userData.target.x * 0.7,
                        rocket.userData.target.y + 20,
                        rocket.userData.target.z * 0.7
                    );
                    const endPoint = rocket.userData.target.clone();
                    
                    // Get position on curve
                    const t = progress;
                    const u = 1 - t;
                    const tt = t * t;
                    const uu = u * u;
                    const uuu = uu * u;
                    const ttt = tt * t;
                    
                    const point = new THREE.Vector3(0, 0, 0);
                    point.x = uuu * startPoint.x;
                    point.y = uuu * startPoint.y;
                    point.z = uuu * startPoint.z;
                    
                    point.x += 3 * uu * t * controlPoint1.x;
                    point.y += 3 * uu * t * controlPoint1.y;
                    point.z += 3 * uu * t * controlPoint1.z;
                    
                    point.x += 3 * u * tt * controlPoint2.x;
                    point.y += 3 * u * tt * controlPoint2.y;
                    point.z += 3 * u * tt * controlPoint2.z;
                    
                    point.x += ttt * endPoint.x;
                    point.y += ttt * endPoint.y;
                    point.z += ttt * endPoint.z;
                    
                    // Set rocket position and rotation
                    rocket.position.copy(point);
                    
                    // Calculate direction for rotation
                    if (elapsed > 50) { // Wait a frame to have previous position
                        const direction = point.clone().sub(rocket.userData.lastPosition).normalize();
                        rocket.lookAt(point.clone().add(direction));
                        rocket.rotateX(Math.PI / 2); // Adjust because rocket model points up
                    }
                    
                    rocket.userData.lastPosition = point.clone();
                }
            }
            
            renderer.render(scene, camera);
        }

        // Handle window resize
        window.addEventListener('resize', () => {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
        });

        // Start animation
        animate();
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=LukasBe/3d-tanks-shooter" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>