File size: 15,603 Bytes
e4c0247
 
 
bafb03c
a6d36b3
e4c0247
a6d36b3
 
 
26e2815
a6d36b3
0d86eb7
 
 
 
 
 
 
 
 
 
 
a6d36b3
 
 
 
 
 
 
 
 
 
a7d011b
a6d36b3
 
0d86eb7
975cece
0d86eb7
 
 
 
a7d011b
0d86eb7
 
975cece
 
 
 
 
 
 
a7d011b
 
975cece
a7d011b
975cece
a7d011b
975cece
 
 
 
 
a7d011b
975cece
 
 
 
 
 
 
 
 
 
a7d011b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
975cece
 
0d86eb7
e4c0247
 
 
0d86eb7
 
a7d011b
 
975cece
26e2815
0d86eb7
a6d36b3
a7d011b
975cece
 
 
a7d011b
a6d36b3
 
 
 
 
 
 
 
 
0d86eb7
e4c0247
a6d36b3
 
 
 
a7d011b
26e2815
 
 
 
bafb03c
26e2815
a7d011b
 
a6d36b3
26e2815
 
 
a7d011b
975cece
a7d011b
26e2815
a7d011b
26e2815
a7d011b
 
 
 
 
0d86eb7
26e2815
 
a6d36b3
26e2815
 
a6d36b3
26e2815
bafb03c
a7d011b
a6d36b3
26e2815
a6d36b3
 
 
 
 
26e2815
 
a6d36b3
 
26e2815
bafb03c
a6d36b3
 
5ccac0e
26e2815
 
0d86eb7
26e2815
 
975cece
26e2815
 
 
 
975cece
26e2815
 
 
 
 
 
975cece
bafb03c
26e2815
bafb03c
 
26e2815
bafb03c
26e2815
bafb03c
975cece
26e2815
bafb03c
 
26e2815
a7d011b
 
bafb03c
 
a7d011b
bafb03c
 
 
 
975cece
26e2815
 
975cece
 
26e2815
 
bafb03c
 
26e2815
 
bafb03c
a7d011b
26e2815
bafb03c
 
 
26e2815
bafb03c
 
 
 
 
 
 
 
 
 
a7d011b
975cece
 
a6d36b3
 
26e2815
a7d011b
26e2815
a7d011b
bafb03c
a7d011b
 
 
0d86eb7
26e2815
 
 
 
 
 
 
 
 
0d86eb7
 
 
bafb03c
26e2815
 
0d86eb7
 
26e2815
0d86eb7
 
 
975cece
26e2815
0d86eb7
a7d011b
 
 
 
26e2815
 
 
 
 
 
 
bafb03c
 
26e2815
 
 
 
 
 
0d86eb7
 
26e2815
 
 
a7d011b
26e2815
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ccac0e
 
bafb03c
26e2815
 
 
 
 
5ccac0e
a7d011b
5ccac0e
26e2815
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5ccac0e
 
 
26e2815
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a6d36b3
26e2815
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b01cf37
 
bafb03c
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
<!DOCTYPE html>
<html>
<head>
    <title>Desert Combat Game</title>
    <meta charset="utf-8">
    <style>
        body { 
            margin: 0;
            overflow: hidden;
            background: #000;
        }
        #info {
            position: absolute;
            top: 10px;
            left: 10px;
            color: white;
            background: rgba(0,0,0,0.7);
            padding: 10px;
            font-family: Arial;
            font-size: 14px;
            z-index: 100;
            border-radius: 5px;
            user-select: none;
        }
        #timer {
            position: absolute;
            top: 10px;
            right: 10px;
            color: white;
            background: rgba(0,0,0,0.7);
            padding: 10px;
            font-family: Arial;
            font-size: 20px;
            z-index: 100;
            border-radius: 5px;
        }
        #crosshair {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: rgba(255, 0, 0, 0.8);
            font-size: 24px;
            z-index: 100;
            user-select: none;
            pointer-events: none;
        }
        #healthBar {
            position: absolute;
            bottom: 20px;
            left: 20px;
            width: 400px;
            height: 30px;
            background: rgba(0,0,0,0.5);
            border: 3px solid white;
            z-index: 100;
            border-radius: 15px;
            overflow: hidden;
        }
        #health {
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, #ff3333, #ff0000);
            transition: width 0.3s;
        }
        #ammo {
            position: absolute;
            bottom: 20px;
            right: 20px;
            color: white;
            background: rgba(0,0,0,0.7);
            padding: 10px;
            font-family: Arial;
            font-size: 20px;
            z-index: 100;
            border-radius: 5px;
        }
        #stage {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: white;
            background: rgba(0,0,0,0.8);
            padding: 20px;
            font-family: Arial;
            font-size: 32px;
            z-index: 100;
            border-radius: 10px;
            display: none;
        }
        #gameTimer {
            position: absolute;
            top: 60px;
            right: 10px;
            color: white;
            background: rgba(0,0,0,0.7);
            padding: 10px;
            font-family: Arial;
            font-size: 20px;
            z-index: 100;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <div id="info">
        Click to start<br>
        WASD - Move Helicopter<br>
        Mouse - Aim<br>
        Left Click - Shoot<br>
        R - Reload
    </div>
    <div id="timer">Safe Time: 10s</div>
    <div id="gameTimer">Time: 3:00</div>
    <div id="crosshair">+</div>
    <div id="healthBar"><div id="health"></div></div>
    <div id="ammo">Ammo: 30/30</div>
    <div id="stage">Stage 1</div>

    <script type="importmap">
        {
            "imports": {
                "three": "https://unpkg.com/three@0.157.0/build/three.module.js",
                "three/addons/": "https://unpkg.com/three@0.157.0/examples/jsm/"
            }
        }
    </script>

    <script type="module">
        import * as THREE from 'three';
        import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
        import { PointerLockControls } from 'three/addons/controls/PointerLockControls.js';

        // ๊ฒŒ์ž„ ์ƒ์ˆ˜
        const GAME_DURATION = 180;
        const MAP_SIZE = 2000;
        const HELICOPTER_HEIGHT = 50;
        const ENEMY_SCALE = 3;
        const MAX_HEALTH = 1000;
        const ENEMY_MODELS = ['1.GLB', '2.GLB', '3.GLB', '4.GLB'];

        // ๊ฒŒ์ž„ ๋ณ€์ˆ˜
        let scene, camera, renderer, controls;
        let enemies = [];
        let bullets = [];
        let enemyBullets = [];
        let playerHealth = MAX_HEALTH;
        let ammo = 30;
        let currentStage = 1;
        let isGameOver = false;

        // ์‚ฌ์šด๋“œ
        const sounds = {
            bgm: new Audio('Music.wav'),
            gunshot: new Audio('gun.wav')
        };
        sounds.bgm.loop = true;

        function init() {
            // Scene ์ƒ์„ฑ
            scene = new THREE.Scene();
            scene.background = new THREE.Color(0x87ceeb);  // ํ•˜๋Š˜์ƒ‰
            scene.fog = new THREE.Fog(0x87ceeb, 0, 1500);

            // Camera ์„ค์ •
            camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 3000);
            camera.position.set(0, HELICOPTER_HEIGHT, 0);

            // Renderer ์„ค์ •
            renderer = new THREE.WebGLRenderer({ antialias: true });
            renderer.setSize(window.innerWidth, window.innerHeight);
            renderer.shadowMap.enabled = true;
            document.body.appendChild(renderer.domElement);

            // ์กฐ๋ช… ์„ค์ •
            const ambientLight = new THREE.AmbientLight(0xffffff, 1.0);
            scene.add(ambientLight);

            const dirLight = new THREE.DirectionalLight(0xffffff, 1.0);
            dirLight.position.set(100, 100, 50);
            dirLight.castShadow = true;
            scene.add(dirLight);

            // ์ง€ํ˜• ์ƒ์„ฑ
            createTerrain();

            // Controls ์„ค์ •
            controls = new PointerLockControls(camera, document.body);
            
            // ์ด๋ฒคํŠธ ๋ฆฌ์Šค๋„ˆ
            document.addEventListener('click', onClick);
            document.addEventListener('keydown', onKeyDown);
            document.addEventListener('keyup', onKeyUp);

            // ์  ๋กœ๋“œ
            loadEnemies();

            // ์• ๋‹ˆ๋ฉ”์ด์…˜ ์‹œ์ž‘
            animate();
        }

        function createTerrain() {
            // ์ง€ํ˜• ์ƒ์„ฑ
            const geometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE, 200, 200);
            const material = new THREE.MeshStandardMaterial({
                color: 0xD2B48C,  // ์‚ฌ๋ง‰์ƒ‰
                roughness: 0.8,
                metalness: 0.2
            });

            // ์ง€ํ˜• ๋†’๋‚ฎ์ด ์„ค์ •
            const vertices = geometry.attributes.position.array;
            for (let i = 0; i < vertices.length; i += 3) {
                vertices[i + 2] = Math.sin(vertices[i] * 0.01) * Math.cos(vertices[i + 1] * 0.01) * 20;
            }

            geometry.attributes.position.needsUpdate = true;
            geometry.computeVertexNormals();

            const terrain = new THREE.Mesh(geometry, material);
            terrain.rotation.x = -Math.PI / 2;
            terrain.receiveShadow = true;
            scene.add(terrain);

            // ์žฅ์• ๋ฌผ ์ถ”๊ฐ€
            addObstacles();
        }

        function addObstacles() {
            // ๋ฐ”์œ„ ์ƒ์„ฑ
            const rockGeometry = new THREE.DodecahedronGeometry(10);
            const rockMaterial = new THREE.MeshStandardMaterial({
                color: 0x8B4513,
                roughness: 0.9
            });

            for (let i = 0; i < 100; i++) {
                const rock = new THREE.Mesh(rockGeometry, rockMaterial);
                rock.position.set(
                    (Math.random() - 0.5) * MAP_SIZE * 0.9,
                    Math.random() * 10,
                    (Math.random() - 0.5) * MAP_SIZE * 0.9
                );
                rock.rotation.set(
                    Math.random() * Math.PI,
                    Math.random() * Math.PI,
                    Math.random() * Math.PI
                );
                rock.castShadow = true;
                rock.receiveShadow = true;
                scene.add(rock);
            }
        }

        function loadEnemies() {
            const loader = new GLTFLoader();
            const enemyCount = 3 + currentStage;

            for (let i = 0; i < enemyCount; i++) {
                const modelPath = ENEMY_MODELS[i % ENEMY_MODELS.length];
                
                loader.load(modelPath, (gltf) => {
                    const enemy = gltf.scene;
                    enemy.scale.set(ENEMY_SCALE, ENEMY_SCALE, ENEMY_SCALE);
                    
                    // ๋žœ๋ค ์œ„์น˜์— ๋ฐฐ์น˜
                    const angle = (i / enemyCount) * Math.PI * 2;
                    const radius = 200;
                    enemy.position.set(
                        Math.cos(angle) * radius,
                        10,
                        Math.sin(angle) * radius
                    );

                    enemy.traverse((node) => {
                        if (node.isMesh) {
                            node.castShadow = true;
                            node.receiveShadow = true;
                            node.material.metalness = 0.2;
                            node.material.roughness = 0.8;
                        }
                    });

                    scene.add(enemy);
                    enemies.push({
                        model: enemy,
                        health: 100,
                        speed: 0.3 + (currentStage * 0.1)
                    });
                });
            }
        }

        function onClick() {
            if (!controls.isLocked) {
                controls.lock();
                sounds.bgm.play();
            } else if (ammo > 0) {
                shoot();
            }
        }

        function onKeyDown(event) {
            switch (event.code) {
                case 'KeyR':
                    reload();
                    break;
            }
        }

        function onKeyUp(event) {
            // ํ‚ค ํ•ด์ œ ์ฒ˜๋ฆฌ
        }

        function shoot() {
            if (ammo <= 0) return;
            
            ammo--;
            updateAmmoDisplay();
            
            const bullet = createBullet();
            bullets.push(bullet);
            
            sounds.gunshot.currentTime = 0;
            sounds.gunshot.play();
        }

        function createBullet() {
            const bulletGeometry = new THREE.SphereGeometry(0.5);
            const bulletMaterial = new THREE.MeshBasicMaterial({ color: 0xffff00 });
            const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
            
            bullet.position.copy(camera.position);
            const direction = new THREE.Vector3();
            camera.getWorldDirection(direction);
            bullet.velocity = direction.multiplyScalar(3);
            
            scene.add(bullet);
            return bullet;
        }

        function reload() {
            ammo = 30;
            updateAmmoDisplay();
        }

        function updateAmmoDisplay() {
            document.getElementById('ammo').textContent = `Ammo: ${ammo}/30`;
        }

        function animate() {
            requestAnimationFrame(animate);

            if (controls.isLocked && !isGameOver) {
                updateBullets();
                updateEnemies();
                checkGameStatus();
            }

            renderer.render(scene, camera);
        }

        function updateBullets() {
            // ์ด์•Œ ์—…๋ฐ์ดํŠธ ๋กœ์ง
            for (let i = bullets.length - 1; i >= 0; i--) {
                bullets[i].position.add(bullets[i].velocity);
                
                // ์ ๊ณผ์˜ ์ถฉ๋Œ ์ฒดํฌ
                enemies.forEach(enemy => {
                    if (bullets[i].position.distanceTo(enemy.model.position) < 5) {
                        scene.remove(bullets[i]);
                        bullets.splice(i, 1);
                        enemy.health -= 25;
                        
                        if (enemy.health <= 0) {
                            scene.remove(enemy.model);
                            enemies = enemies.filter(e => e !== enemy);
                        }
                    }
                });

                // ๋ฒ”์œ„ ๋ฒ—์–ด๋‚œ ์ด์•Œ ์ œ๊ฑฐ
                if (bullets[i] && bullets[i].position.distanceTo(camera.position) > 1000) {
                    scene.remove(bullets[i]);
                    bullets.splice(i, 1);
                }
            }
        }

        function updateEnemies() {
            enemies.forEach(enemy => {
                const direction = new THREE.Vector3();
                direction.subVectors(camera.position, enemy.model.position);
                direction.normalize();
                
                enemy.model.position.add(direction.multiplyScalar(enemy.speed));
                enemy.model.lookAt(camera.position);

                // ํ”Œ๋ ˆ์ด์–ด์™€์˜ ์ถฉ๋Œ ์ฒดํฌ
                if (enemy.model.position.distanceTo(camera.position) < 10) {
                    gameOver(false);
                }
            });
        }

        function checkGameStatus() {
            if (enemies.length === 0 && currentStage < 5) {
                currentStage++;
                loadEnemies();
            }
        }

        function gameOver(won) {
            isGameOver = true;
            controls.unlock();
            sounds.bgm.pause();
            alert(won ? 'Mission Complete!' : 'Game Over!');
            location.reload();
        }

        // ํ™”๋ฉด ํฌ๊ธฐ ์กฐ์ ˆ ์ฒ˜๋ฆฌ
        window.addEventListener('resize', () => {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
        });

        // ๊ฒŒ์ž„ ์‹œ์ž‘
        init();

        // ๋งˆ์šฐ์Šค ์ด๋™ ์†๋„ ์ œ์–ด
        const moveState = {
            forward: false,
            backward: false,
            left: false,
            right: false
        };

        // ํ‚ค๋ณด๋“œ ์ด๋ฒคํŠธ
        document.addEventListener('keydown', (event) => {
            switch(event.code) {
                case 'KeyW': moveState.forward = true; break;
                case 'KeyS': moveState.backward = true; break;
                case 'KeyA': moveState.left = true; break;
                case 'KeyD': moveState.right = true; break;
            }
        });

        document.addEventListener('keyup', (event) => {
            switch(event.code) {
                case 'KeyW': moveState.forward = false; break;
                case 'KeyS': moveState.backward = false; break;
                case 'KeyA': moveState.left = false; break;
                case 'KeyD': moveState.right = false; break;
            }
        });

        // ์ด๋™ ์—…๋ฐ์ดํŠธ
        function updateMovement() {
            if (controls.isLocked) {
                const speed = 2.0;
                if (moveState.forward) controls.moveForward(speed);
                if (moveState.backward) controls.moveForward(-speed);
                if (moveState.left) controls.moveRight(-speed);
                if (moveState.right) controls.moveRight(speed);
            }
        }

        // ๋ฉ”์ธ ๊ฒŒ์ž„ ๋ฃจํ”„์— ์ด๋™ ์—…๋ฐ์ดํŠธ ์ถ”๊ฐ€
        let lastTime = performance.now();
        function gameLoop() {
            const time = performance.now();
            const delta = (time - lastTime) / 1000;
            lastTime = time;

            if (controls.isLocked && !isGameOver) {
                updateMovement();
                updateBullets();
                updateEnemies();
                checkGameStatus();
            }

            renderer.render(scene, camera);
            requestAnimationFrame(gameLoop);
        }

        gameLoop();
    </script>
</body>
</html>