Spaces:
Running
Running
Update index.html
Browse files- index.html +895 -350
index.html
CHANGED
@@ -1,399 +1,944 @@
|
|
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 |
-
width: 40px;
|
95 |
-
height: 40px;
|
96 |
-
border: 2px solid #00ff00;
|
97 |
-
border-radius: 50%;
|
98 |
-
z-index: 1001;
|
99 |
-
pointer-events: none;
|
100 |
-
transition: all 0.2s ease;
|
101 |
-
}
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
background: #00ff00;
|
115 |
-
transition: all 0.2s ease;
|
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 |
-
position: absolute;
|
162 |
-
bottom: 20px;
|
163 |
-
right: 20px;
|
164 |
-
color: #0f0;
|
165 |
-
background: rgba(0,20,0,0.7);
|
166 |
-
padding: 10px;
|
167 |
-
font-size: 20px;
|
168 |
-
z-index: 1001;
|
169 |
-
border: 1px solid #0f0;
|
170 |
-
border-radius: 5px;
|
171 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
z-index: 1001;
|
184 |
-
border: 1px solid #0f0;
|
185 |
-
border-radius: 5px;
|
186 |
-
text-transform: uppercase;
|
187 |
-
letter-spacing: 2px;
|
188 |
}
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
|
|
|
|
200 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
|
202 |
-
|
203 |
-
position: absolute;
|
204 |
-
top: 50%;
|
205 |
-
left: 50%;
|
206 |
-
transform: translate(-50%, -50%);
|
207 |
-
color: #ff0000;
|
208 |
-
font-size: 24px;
|
209 |
-
font-weight: bold;
|
210 |
-
display: none;
|
211 |
-
z-index: 1002;
|
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 |
-
left: 50%;
|
244 |
-
width: 50%;
|
245 |
-
height: 2px;
|
246 |
-
background: #0f0;
|
247 |
-
transform-origin: left center;
|
248 |
-
animation: radar-sweep 4s infinite linear;
|
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 |
-
color: #0f0;
|
274 |
-
background: rgba(0,20,0,0.7);
|
275 |
-
padding: 10px;
|
276 |
-
font-size: 16px;
|
277 |
-
z-index: 1001;
|
278 |
-
border: 1px solid #0f0;
|
279 |
-
border-radius: 5px;
|
280 |
-
text-align: right;
|
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 |
-
<p>ESC - Pause</p>
|
341 |
-
</div>
|
342 |
-
</div>
|
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 |
-
"three": "https://unpkg.com/[email protected]/build/three.module.js",
|
377 |
-
"three/addons/": "https://unpkg.com/[email protected]/examples/jsm/"
|
378 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
379 |
}
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
386 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
387 |
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import * as THREE from 'three';
|
2 |
+
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
3 |
+
|
4 |
+
// ๊ฒ์ ์์
|
5 |
+
const GAME_CONSTANTS = {
|
6 |
+
MISSION_DURATION: 180,
|
7 |
+
MAP_SIZE: 15000,
|
8 |
+
MAX_ALTITUDE: 12000,
|
9 |
+
MIN_ALTITUDE: 100,
|
10 |
+
MAX_SPEED: 800,
|
11 |
+
STALL_SPEED: 120,
|
12 |
+
GRAVITY: 9.8,
|
13 |
+
MOUSE_SENSITIVITY: 0.001, // ๋ง์ฐ์ค ๊ฐ๋ ๋ฎ์ถค
|
14 |
+
MAX_G_FORCE: 12.0,
|
15 |
+
ENEMY_COUNT: 4,
|
16 |
+
MISSILE_COUNT: 6,
|
17 |
+
AMMO_COUNT: 300
|
18 |
+
};
|
19 |
+
|
20 |
+
// ์ ํฌ๊ธฐ ํด๋์ค
|
21 |
+
class Fighter {
|
22 |
+
constructor() {
|
23 |
+
this.mesh = null;
|
24 |
+
this.isLoaded = false;
|
25 |
|
26 |
+
// ๋ฌผ๋ฆฌ ์์ฑ
|
27 |
+
this.position = new THREE.Vector3(0, 2000, 0);
|
28 |
+
this.velocity = new THREE.Vector3(0, 0, 150); // ์ด๊ธฐ ์ ์ง ์๋
|
29 |
+
this.acceleration = new THREE.Vector3(0, 0, 0);
|
30 |
+
this.rotation = new THREE.Euler(0, 0, 0);
|
31 |
+
|
32 |
+
// ๋นํ ์ ์ด (์์ฌ๋ ์คํ์ผ)
|
33 |
+
this.baseSpeed = 150; // ๊ธฐ๋ณธ ์๋
|
34 |
+
this.throttle = 0.5; // ๊ธฐ๋ณธ ์ค๋กํ 50%
|
35 |
+
this.speed = 150;
|
36 |
+
this.altitude = 2000;
|
37 |
+
this.gForce = 1.0;
|
38 |
+
this.health = 100;
|
39 |
+
|
40 |
+
// ์กฐ์ข
์
๋ ฅ ์์คํ
|
41 |
+
this.pitchInput = 0; // ๋ง์ฐ์ค Y -> ๊ธฐ์ ์ํ
|
42 |
+
this.rollInput = 0; // ๋ง์ฐ์ค X -> ์ข์ฐ ํ์ (๋กค)
|
43 |
+
this.yawInput = 0; // A/D ํค -> ๋ฌ๋
|
44 |
+
|
45 |
+
// ๋ง์ฐ์ค ๋์ ์
๋ ฅ
|
46 |
+
this.mousePitch = 0;
|
47 |
+
this.mouseRoll = 0;
|
48 |
+
|
49 |
+
// ๋ถ๋๋ฌ์ด ํ์ ์ ์ํ ๋ชฉํ๊ฐ
|
50 |
+
this.targetPitch = 0;
|
51 |
+
this.targetRoll = 0;
|
52 |
+
this.targetYaw = 0;
|
53 |
+
|
54 |
+
// ๋ฌด๊ธฐ
|
55 |
+
this.missiles = GAME_CONSTANTS.MISSILE_COUNT;
|
56 |
+
this.ammo = GAME_CONSTANTS.AMMO_COUNT;
|
57 |
+
this.bullets = [];
|
58 |
+
this.lastShootTime = 0;
|
59 |
+
|
60 |
+
// ์นด๋ฉ๋ผ ์ค์
|
61 |
+
this.cameraDistance = 40;
|
62 |
+
this.cameraHeight = 10;
|
63 |
+
this.cameraLag = 0.08; // ์นด๋ฉ๋ผ ๋ฐ๋ผ์ค๋ ์๋
|
64 |
+
}
|
65 |
|
66 |
+
async initialize(scene, loader) {
|
67 |
+
try {
|
68 |
+
const result = await loader.loadAsync('models/f-15.glb');
|
69 |
+
this.mesh = result.scene;
|
70 |
+
this.mesh.position.copy(this.position);
|
71 |
+
this.mesh.scale.set(2, 2, 2);
|
72 |
+
|
73 |
+
// ๊ทธ๋ฆผ์ ์ค์
|
74 |
+
this.mesh.traverse((child) => {
|
75 |
+
if (child.isMesh) {
|
76 |
+
child.castShadow = true;
|
77 |
+
child.receiveShadow = true;
|
78 |
+
}
|
79 |
+
});
|
80 |
+
|
81 |
+
scene.add(this.mesh);
|
82 |
+
this.isLoaded = true;
|
83 |
+
|
84 |
+
console.log('F-15 ์ ํฌ๊ธฐ ๋ก๋ฉ ์๋ฃ');
|
85 |
+
} catch (error) {
|
86 |
+
console.error('F-15 ๋ชจ๋ธ ๋ก๋ฉ ์คํจ:', error);
|
87 |
+
this.createFallbackModel(scene);
|
88 |
}
|
89 |
+
}
|
90 |
+
|
91 |
+
createFallbackModel(scene) {
|
92 |
+
const group = new THREE.Group();
|
93 |
+
|
94 |
+
// ๋์ฒด
|
95 |
+
const fuselageGeometry = new THREE.CylinderGeometry(0.8, 1.5, 12, 8);
|
96 |
+
const fuselageMaterial = new THREE.MeshLambertMaterial({ color: 0x606060 });
|
97 |
+
const fuselage = new THREE.Mesh(fuselageGeometry, fuselageMaterial);
|
98 |
+
fuselage.rotation.x = Math.PI / 2;
|
99 |
+
group.add(fuselage);
|
100 |
+
|
101 |
+
// ์ฃผ์ต
|
102 |
+
const wingGeometry = new THREE.BoxGeometry(16, 0.3, 4);
|
103 |
+
const wingMaterial = new THREE.MeshLambertMaterial({ color: 0x404040 });
|
104 |
+
const wings = new THREE.Mesh(wingGeometry, wingMaterial);
|
105 |
+
wings.position.z = -1;
|
106 |
+
group.add(wings);
|
107 |
+
|
108 |
+
// ์์ง ์์ ํ
|
109 |
+
const tailGeometry = new THREE.BoxGeometry(0.3, 4, 3);
|
110 |
+
const tailMaterial = new THREE.MeshLambertMaterial({ color: 0x404040 });
|
111 |
+
const tail = new THREE.Mesh(tailGeometry, tailMaterial);
|
112 |
+
tail.position.z = -5;
|
113 |
+
tail.position.y = 1.5;
|
114 |
+
group.add(tail);
|
115 |
+
|
116 |
+
// ์ํ ์์ ํ
|
117 |
+
const horizontalTailGeometry = new THREE.BoxGeometry(6, 0.2, 2);
|
118 |
+
const horizontalTail = new THREE.Mesh(horizontalTailGeometry, tailMaterial);
|
119 |
+
horizontalTail.position.z = -5;
|
120 |
+
horizontalTail.position.y = 0.5;
|
121 |
+
group.add(horizontalTail);
|
122 |
+
|
123 |
+
this.mesh = group;
|
124 |
+
this.mesh.position.copy(this.position);
|
125 |
+
this.mesh.scale.set(2, 2, 2);
|
126 |
+
scene.add(this.mesh);
|
127 |
+
this.isLoaded = true;
|
128 |
+
|
129 |
+
console.log('Fallback ์ ํฌ๊ธฐ ๋ชจ๋ธ ์์ฑ ์๋ฃ');
|
130 |
+
}
|
131 |
|
132 |
+
// ์์ฌ๋ ์คํ์ผ ๋ง์ฐ์ค ์
๋ ฅ ์ฒ๋ฆฌ
|
133 |
+
updateMouseInput(deltaX, deltaY) {
|
134 |
+
// ๋ง์ฐ์ค X = ๋กค (์ข์ฐ ๊ธฐ์ธ๊ธฐ)
|
135 |
+
// ๋ง์ฐ์ค Y = ํผ์น (๊ธฐ์ ์ํ)
|
136 |
+
this.mouseRoll += deltaX * GAME_CONSTANTS.MOUSE_SENSITIVITY;
|
137 |
+
this.mousePitch += deltaY * GAME_CONSTANTS.MOUSE_SENSITIVITY;
|
138 |
+
|
139 |
+
// ์
๋ ฅ ์ ํ (ยฑ1)
|
140 |
+
this.mouseRoll = Math.max(-1, Math.min(1, this.mouseRoll));
|
141 |
+
this.mousePitch = Math.max(-1, Math.min(1, this.mousePitch));
|
142 |
+
}
|
143 |
+
|
144 |
+
// ํค๋ณด๋ ์
๋ ฅ ์ฒ๋ฆฌ
|
145 |
+
updateControls(keys, deltaTime) {
|
146 |
+
// W/S: ์ค๋กํ ์กฐ์
|
147 |
+
if (keys.w) {
|
148 |
+
this.throttle = Math.min(1.0, this.throttle + deltaTime * 0.8);
|
149 |
+
}
|
150 |
+
if (keys.s) {
|
151 |
+
this.throttle = Math.max(0.1, this.throttle - deltaTime * 0.8);
|
152 |
}
|
153 |
+
|
154 |
+
// A/D: ๋ฌ๋ (์ ํ์ )
|
155 |
+
this.yawInput = 0;
|
156 |
+
if (keys.a) this.yawInput = -0.5;
|
157 |
+
if (keys.d) this.yawInput = 0.5;
|
158 |
+
|
159 |
+
// ํ์ฌ ์
๋ ฅ์ ์กฐ์ข
์
๋ ฅ์ผ๋ก ์ค์
|
160 |
+
this.pitchInput = this.mousePitch;
|
161 |
+
this.rollInput = this.mouseRoll;
|
162 |
+
|
163 |
+
// ๋ชฉํ ํ์ ๊ฐ ๊ณ์ฐ (๋ถ๋๋ฌ์ด ์ ์ด)
|
164 |
+
const maxPitchAngle = Math.PI / 6; // 30๋
|
165 |
+
const maxRollAngle = Math.PI / 4; // 45๋
|
166 |
+
|
167 |
+
this.targetPitch = this.pitchInput * maxPitchAngle;
|
168 |
+
this.targetRoll = this.rollInput * maxRollAngle;
|
169 |
+
this.targetYaw += this.yawInput * deltaTime * 1.5;
|
170 |
+
|
171 |
+
// ๋ง์ฐ์ค ์
๋ ฅ ์์ฐ์ค๋ฝ๊ฒ ๊ฐ์
|
172 |
+
this.mouseRoll *= 0.95;
|
173 |
+
this.mousePitch *= 0.95;
|
174 |
+
}
|
175 |
|
176 |
+
// ๋ฌผ๋ฆฌ ์๋ฎฌ๋ ์ด์
|
177 |
+
updatePhysics(deltaTime) {
|
178 |
+
if (!this.mesh) return;
|
179 |
+
|
180 |
+
// ํ์ ๋ถ๋๋ฝ๊ฒ ๋ณด๊ฐ
|
181 |
+
const rotationSpeed = deltaTime * 3.0;
|
182 |
+
this.rotation.x = THREE.MathUtils.lerp(this.rotation.x, this.targetPitch, rotationSpeed);
|
183 |
+
this.rotation.y = THREE.MathUtils.lerp(this.rotation.y, this.targetYaw, rotationSpeed);
|
184 |
+
this.rotation.z = THREE.MathUtils.lerp(this.rotation.z, this.targetRoll, rotationSpeed);
|
185 |
+
|
186 |
+
// ์ค๋กํ์ ๋ฐ๋ฅธ ์๋ ๊ณ์ฐ
|
187 |
+
const minSpeed = 100; // ์ต์ ์๋
|
188 |
+
const maxSpeed = 300; // ์ต๋ ์๋
|
189 |
+
const targetSpeed = minSpeed + (maxSpeed - minSpeed) * this.throttle;
|
190 |
+
|
191 |
+
// ์๋ ๋ถ๋๋ฝ๊ฒ ๋ณํ
|
192 |
+
this.speed = THREE.MathUtils.lerp(this.speed, targetSpeed, deltaTime * 2);
|
193 |
+
|
194 |
+
// ์ ์ง ๋ฐฉํฅ ๋ฒกํฐ ๊ณ์ฐ
|
195 |
+
const forward = new THREE.Vector3(0, 0, 1);
|
196 |
+
forward.applyEuler(this.rotation);
|
197 |
+
|
198 |
+
// ์๋ ๋ฒกํฐ ์ค์ (ํญ์ ์ ์ง)
|
199 |
+
this.velocity = forward.multiplyScalar(this.speed);
|
200 |
+
|
201 |
+
// ์์น ์
๋ฐ์ดํธ
|
202 |
+
this.position.add(this.velocity.clone().multiplyScalar(deltaTime));
|
203 |
+
|
204 |
+
// ๊ณ ๋ ์ ํ
|
205 |
+
if (this.position.y < GAME_CONSTANTS.MIN_ALTITUDE) {
|
206 |
+
this.position.y = GAME_CONSTANTS.MIN_ALTITUDE;
|
207 |
+
if (this.velocity.y < 0) this.velocity.y = 0;
|
208 |
+
}
|
209 |
+
|
210 |
+
if (this.position.y > GAME_CONSTANTS.MAX_ALTITUDE) {
|
211 |
+
this.position.y = GAME_CONSTANTS.MAX_ALTITUDE;
|
212 |
+
if (this.velocity.y > 0) this.velocity.y = 0;
|
213 |
}
|
214 |
+
|
215 |
+
// ๋งต ๊ฒฝ๊ณ ์ํ (๋ฌดํ ๋งต)
|
216 |
+
const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2;
|
217 |
+
if (this.position.x > mapLimit) this.position.x = -mapLimit;
|
218 |
+
if (this.position.x < -mapLimit) this.position.x = mapLimit;
|
219 |
+
if (this.position.z > mapLimit) this.position.z = -mapLimit;
|
220 |
+
if (this.position.z < -mapLimit) this.position.z = mapLimit;
|
221 |
+
|
222 |
+
// ๋ฉ์ ์
๋ฐ์ดํธ
|
223 |
+
this.mesh.position.copy(this.position);
|
224 |
+
this.mesh.rotation.copy(this.rotation);
|
225 |
+
|
226 |
+
// ํ์ฌ ๊ฐ ์
๋ฐ์ดํธ
|
227 |
+
this.altitude = this.position.y;
|
228 |
+
|
229 |
+
// G-Force ๊ณ์ฐ (ํ์ ๊ฐ๋์ ๋ฐ๋ผ)
|
230 |
+
const rotationIntensity = Math.abs(this.targetPitch) + Math.abs(this.targetRoll);
|
231 |
+
this.gForce = 1.0 + rotationIntensity * 3;
|
232 |
+
}
|
233 |
|
234 |
+
// ๋ฐ์ฌ ์์คํ
|
235 |
+
shoot(scene) {
|
236 |
+
const currentTime = Date.now();
|
237 |
+
if (currentTime - this.lastShootTime < 100 || this.ammo <= 0) return;
|
238 |
+
|
239 |
+
this.lastShootTime = currentTime;
|
240 |
+
this.ammo--;
|
241 |
+
|
242 |
+
// ์ด์ ์์ฑ
|
243 |
+
const bulletGeometry = new THREE.SphereGeometry(0.2);
|
244 |
+
const bulletMaterial = new THREE.MeshBasicMaterial({
|
245 |
+
color: 0xffff00,
|
246 |
+
emissive: 0xffff00,
|
247 |
+
emissiveIntensity: 0.7
|
248 |
+
});
|
249 |
+
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
250 |
+
|
251 |
+
// ์ด๊ตฌ ์์น (์ ํฌ๊ธฐ ์์ชฝ)
|
252 |
+
const muzzleOffset = new THREE.Vector3(0, 0, 8);
|
253 |
+
muzzleOffset.applyEuler(this.rotation);
|
254 |
+
bullet.position.copy(this.position).add(muzzleOffset);
|
255 |
+
|
256 |
+
// ์ด์ ์๋ (์ ํฌ๊ธฐ ์๋ + ์ด์ ์๋)
|
257 |
+
const bulletSpeed = 1000;
|
258 |
+
const direction = new THREE.Vector3(0, 0, 1);
|
259 |
+
direction.applyEuler(this.rotation);
|
260 |
+
bullet.velocity = direction.multiplyScalar(bulletSpeed).add(this.velocity);
|
261 |
+
|
262 |
+
scene.add(bullet);
|
263 |
+
this.bullets.push(bullet);
|
264 |
+
|
265 |
+
// ๋ฐ์ฌ์
|
266 |
+
try {
|
267 |
+
const audio = new Audio('sounds/gunfire.ogg');
|
268 |
+
audio.volume = 0.3;
|
269 |
+
audio.play();
|
270 |
+
} catch (e) {
|
271 |
+
console.log('Sound file not found');
|
272 |
}
|
273 |
+
}
|
274 |
|
275 |
+
// ์ด์ ์
๋ฐ์ดํธ
|
276 |
+
updateBullets(scene, deltaTime) {
|
277 |
+
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
278 |
+
const bullet = this.bullets[i];
|
279 |
+
bullet.position.add(bullet.velocity.clone().multiplyScalar(deltaTime));
|
280 |
+
|
281 |
+
// ์ด์ ์ ๊ฑฐ ์กฐ๊ฑด
|
282 |
+
if (bullet.position.distanceTo(this.position) > 8000 ||
|
283 |
+
bullet.position.y < 0 ||
|
284 |
+
bullet.position.y > GAME_CONSTANTS.MAX_ALTITUDE + 500) {
|
285 |
+
scene.remove(bullet);
|
286 |
+
this.bullets.splice(i, 1);
|
287 |
+
}
|
288 |
}
|
289 |
+
}
|
290 |
|
291 |
+
// ํผํด ์์คํ
|
292 |
+
takeDamage(damage) {
|
293 |
+
this.health -= damage;
|
294 |
+
return this.health <= 0;
|
295 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
|
297 |
+
// ์นด๋ฉ๋ผ ์์น ๊ณ์ฐ (์ ํฌ๊ธฐ ๋ค์ชฝ์์ ์ถ์ )
|
298 |
+
getCameraPosition() {
|
299 |
+
// ์ ํฌ๊ธฐ ๋ค์ชฝ ๋ฐฉํฅ ๊ณ์ฐ
|
300 |
+
const backward = new THREE.Vector3(0, 0, -1);
|
301 |
+
backward.applyEuler(this.rotation);
|
302 |
+
|
303 |
+
// ์นด๋ฉ๋ผ ์์น = ์ ํฌ๊ธฐ ์์น + ๋ค์ชฝ ๋ฐฉํฅ * ๊ฑฐ๋ฆฌ + ๋์ด
|
304 |
+
const cameraPos = this.position.clone()
|
305 |
+
.add(backward.multiplyScalar(this.cameraDistance))
|
306 |
+
.add(new THREE.Vector3(0, this.cameraHeight, 0));
|
307 |
+
|
308 |
+
return cameraPos;
|
309 |
+
}
|
310 |
|
311 |
+
// ์นด๋ฉ๋ผ ํ๊ฒ (์ ํฌ๊ธฐ๋ฅผ ๋ฐ๋ผ๋ด)
|
312 |
+
getCameraTarget() {
|
313 |
+
return this.position.clone().add(new THREE.Vector3(0, 0, 0));
|
314 |
+
}
|
|
|
|
|
315 |
}
|
316 |
|
317 |
+
// ์ ์ ํฌ๊ธฐ ํด๋์ค (๊ฐ๋จํ ๋ฒ์ )
|
318 |
+
class EnemyFighter {
|
319 |
+
constructor(scene, position) {
|
320 |
+
this.mesh = null;
|
321 |
+
this.isLoaded = false;
|
322 |
+
this.scene = scene;
|
323 |
+
this.position = position.clone();
|
324 |
+
this.velocity = new THREE.Vector3(0, 0, 120);
|
325 |
+
this.rotation = new THREE.Euler(0, 0, 0);
|
326 |
+
this.health = 100;
|
327 |
+
this.speed = 120;
|
328 |
+
this.bullets = [];
|
329 |
+
this.lastShootTime = 0;
|
330 |
+
|
331 |
+
// AI ์ํ
|
332 |
+
this.aiState = 'patrol';
|
333 |
+
this.targetPosition = position.clone();
|
334 |
+
this.patrolCenter = position.clone();
|
335 |
+
this.patrolRadius = 2000;
|
336 |
+
this.lastStateChange = 0;
|
337 |
+
}
|
338 |
|
339 |
+
async initialize(loader) {
|
340 |
+
try {
|
341 |
+
const result = await loader.loadAsync('models/mig-29.glb');
|
342 |
+
this.mesh = result.scene;
|
343 |
+
this.mesh.position.copy(this.position);
|
344 |
+
this.mesh.scale.set(1.5, 1.5, 1.5);
|
345 |
+
|
346 |
+
this.mesh.traverse((child) => {
|
347 |
+
if (child.isMesh) {
|
348 |
+
child.castShadow = true;
|
349 |
+
child.receiveShadow = true;
|
350 |
+
}
|
351 |
+
});
|
352 |
+
|
353 |
+
this.scene.add(this.mesh);
|
354 |
+
this.isLoaded = true;
|
355 |
+
|
356 |
+
console.log('MiG-29 ์ ๊ธฐ ๋ก๋ฉ ์๋ฃ');
|
357 |
+
} catch (error) {
|
358 |
+
console.error('MiG-29 ๋ชจ๋ธ ๋ก๋ฉ ์คํจ:', error);
|
359 |
+
this.createFallbackModel();
|
360 |
+
}
|
361 |
+
}
|
362 |
|
363 |
+
createFallbackModel() {
|
364 |
+
const group = new THREE.Group();
|
365 |
+
|
366 |
+
const fuselageGeometry = new THREE.CylinderGeometry(0.6, 1.0, 8, 8);
|
367 |
+
const fuselageMaterial = new THREE.MeshLambertMaterial({ color: 0x800000 });
|
368 |
+
const fuselage = new THREE.Mesh(fuselageGeometry, fuselageMaterial);
|
369 |
+
fuselage.rotation.x = Math.PI / 2;
|
370 |
+
group.add(fuselage);
|
371 |
+
|
372 |
+
const wingGeometry = new THREE.BoxGeometry(12, 0.3, 3);
|
373 |
+
const wingMaterial = new THREE.MeshLambertMaterial({ color: 0x600000 });
|
374 |
+
const wings = new THREE.Mesh(wingGeometry, wingMaterial);
|
375 |
+
wings.position.z = -0.5;
|
376 |
+
group.add(wings);
|
377 |
+
|
378 |
+
this.mesh = group;
|
379 |
+
this.mesh.position.copy(this.position);
|
380 |
+
this.mesh.scale.set(1.5, 1.5, 1.5);
|
381 |
+
this.scene.add(this.mesh);
|
382 |
+
this.isLoaded = true;
|
383 |
+
|
384 |
+
console.log('Fallback ์ ๊ธฐ ๋ชจ๋ธ ์์ฑ ์๋ฃ');
|
385 |
+
}
|
386 |
|
387 |
+
update(playerPosition, deltaTime) {
|
388 |
+
if (!this.mesh || !this.isLoaded) return;
|
389 |
+
|
390 |
+
const currentTime = Date.now();
|
391 |
+
const distanceToPlayer = this.position.distanceTo(playerPosition);
|
392 |
+
|
393 |
+
// ๊ฐ๋จํ AI: ํ๋ ์ด์ด ์ถ์
|
394 |
+
if (distanceToPlayer < 5000) {
|
395 |
+
const direction = new THREE.Vector3()
|
396 |
+
.subVectors(playerPosition, this.position)
|
397 |
+
.normalize();
|
398 |
+
|
399 |
+
this.velocity = direction.multiplyScalar(this.speed);
|
400 |
+
this.rotation.y = Math.atan2(direction.x, direction.z);
|
401 |
+
|
402 |
+
// ๊ณต๊ฒฉ
|
403 |
+
if (distanceToPlayer < 2000 && currentTime - this.lastShootTime > 1500) {
|
404 |
+
this.shoot();
|
405 |
+
}
|
406 |
+
} else {
|
407 |
+
// ์์ฐฐ
|
408 |
+
if (this.position.distanceTo(this.targetPosition) < 300) {
|
409 |
+
const angle = Math.random() * Math.PI * 2;
|
410 |
+
this.targetPosition = this.patrolCenter.clone().add(
|
411 |
+
new THREE.Vector3(
|
412 |
+
Math.cos(angle) * this.patrolRadius,
|
413 |
+
(Math.random() - 0.5) * 1000,
|
414 |
+
Math.sin(angle) * this.patrolRadius
|
415 |
+
)
|
416 |
+
);
|
417 |
+
}
|
418 |
+
|
419 |
+
const direction = new THREE.Vector3()
|
420 |
+
.subVectors(this.targetPosition, this.position)
|
421 |
+
.normalize();
|
422 |
+
|
423 |
+
this.velocity = direction.multiplyScalar(this.speed * 0.7);
|
424 |
+
this.rotation.y = Math.atan2(direction.x, direction.z);
|
425 |
}
|
426 |
+
|
427 |
+
// ์์น ์
๋ฐ์ดํธ
|
428 |
+
this.position.add(this.velocity.clone().multiplyScalar(deltaTime));
|
429 |
+
|
430 |
+
// ๊ณ ๋ ์ ํ
|
431 |
+
if (this.position.y < GAME_CONSTANTS.MIN_ALTITUDE) {
|
432 |
+
this.position.y = GAME_CONSTANTS.MIN_ALTITUDE;
|
433 |
}
|
434 |
+
if (this.position.y > GAME_CONSTANTS.MAX_ALTITUDE) {
|
435 |
+
this.position.y = GAME_CONSTANTS.MAX_ALTITUDE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
436 |
}
|
437 |
+
|
438 |
+
// ๋งต ๊ฒฝ๊ณ ์ํ
|
439 |
+
const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2;
|
440 |
+
if (this.position.x > mapLimit) this.position.x = -mapLimit;
|
441 |
+
if (this.position.x < -mapLimit) this.position.x = mapLimit;
|
442 |
+
if (this.position.z > mapLimit) this.position.z = -mapLimit;
|
443 |
+
if (this.position.z < -mapLimit) this.position.z = mapLimit;
|
444 |
+
|
445 |
+
// ๋ฉ์ ์
๋ฐ์ดํธ
|
446 |
+
this.mesh.position.copy(this.position);
|
447 |
+
this.mesh.rotation.copy(this.rotation);
|
448 |
+
|
449 |
+
// ์ด์ ์
๋ฐ์ดํธ
|
450 |
+
this.updateBullets(deltaTime);
|
451 |
+
}
|
452 |
+
|
453 |
+
shoot() {
|
454 |
+
this.lastShootTime = Date.now();
|
455 |
+
|
456 |
+
const bulletGeometry = new THREE.SphereGeometry(0.15);
|
457 |
+
const bulletMaterial = new THREE.MeshBasicMaterial({
|
458 |
+
color: 0xff0000,
|
459 |
+
emissive: 0xff0000,
|
460 |
+
emissiveIntensity: 0.5
|
461 |
+
});
|
462 |
+
const bullet = new THREE.Mesh(bulletGeometry, bulletMaterial);
|
463 |
+
|
464 |
+
const muzzleOffset = new THREE.Vector3(0, 0, 6);
|
465 |
+
muzzleOffset.applyEuler(this.rotation);
|
466 |
+
bullet.position.copy(this.position).add(muzzleOffset);
|
467 |
+
|
468 |
+
const direction = new THREE.Vector3(0, 0, 1);
|
469 |
+
direction.applyEuler(this.rotation);
|
470 |
+
bullet.velocity = direction.multiplyScalar(800);
|
471 |
+
|
472 |
+
this.scene.add(bullet);
|
473 |
+
this.bullets.push(bullet);
|
474 |
+
}
|
475 |
|
476 |
+
updateBullets(deltaTime) {
|
477 |
+
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
478 |
+
const bullet = this.bullets[i];
|
479 |
+
bullet.position.add(bullet.velocity.clone().multiplyScalar(deltaTime));
|
480 |
+
|
481 |
+
if (bullet.position.distanceTo(this.position) > 5000 ||
|
482 |
+
bullet.position.y < 0) {
|
483 |
+
this.scene.remove(bullet);
|
484 |
+
this.bullets.splice(i, 1);
|
485 |
+
}
|
|
|
|
|
|
|
|
|
|
|
486 |
}
|
487 |
+
}
|
488 |
+
|
489 |
+
takeDamage(damage) {
|
490 |
+
this.health -= damage;
|
491 |
+
return this.health <= 0;
|
492 |
+
}
|
493 |
+
|
494 |
+
destroy() {
|
495 |
+
if (this.mesh) {
|
496 |
+
this.scene.remove(this.mesh);
|
497 |
+
this.bullets.forEach(bullet => this.scene.remove(bullet));
|
498 |
+
this.bullets = [];
|
499 |
+
this.isLoaded = false;
|
500 |
}
|
501 |
+
}
|
502 |
+
}
|
503 |
+
|
504 |
+
// ๋ฉ์ธ ๊ฒ์ ํด๋์ค
|
505 |
+
class Game {
|
506 |
+
constructor() {
|
507 |
+
this.scene = new THREE.Scene();
|
508 |
+
this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 50000);
|
509 |
+
this.renderer = new THREE.WebGLRenderer({ antialias: true });
|
510 |
+
this.renderer.setSize(window.innerWidth, window.innerHeight);
|
511 |
+
this.renderer.shadowMap.enabled = true;
|
512 |
+
this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
513 |
+
this.renderer.setClearColor(0x87CEEB);
|
514 |
+
this.renderer.setPixelRatio(window.devicePixelRatio);
|
515 |
|
516 |
+
document.getElementById('gameContainer').appendChild(this.renderer.domElement);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
517 |
|
518 |
+
this.loader = new GLTFLoader();
|
519 |
+
this.fighter = new Fighter();
|
520 |
+
this.enemies = [];
|
521 |
+
this.isLoaded = false;
|
522 |
+
this.isGameOver = false;
|
523 |
+
this.gameTime = GAME_CONSTANTS.MISSION_DURATION;
|
524 |
+
this.score = 0;
|
525 |
+
this.lastTime = performance.now();
|
526 |
+
this.gameTimer = null;
|
527 |
+
this.animationFrameId = null;
|
528 |
+
|
529 |
+
// ์ค๋์ค ์์คํ
|
530 |
+
this.bgm = null;
|
531 |
+
this.bgmPlaying = false;
|
532 |
+
|
533 |
+
// ์
๋ ฅ ์ํ
|
534 |
+
this.keys = { w: false, a: false, s: false, d: false };
|
535 |
+
this.isStarted = false;
|
536 |
+
|
537 |
+
// ๊ธฐ๋ณธ ์ด๊ธฐํ
|
538 |
+
this.setupScene();
|
539 |
+
this.setupEventListeners();
|
540 |
+
this.preloadGame();
|
541 |
+
}
|
542 |
+
|
543 |
+
async preloadGame() {
|
544 |
+
try {
|
545 |
+
console.log('๊ฒ์ ๋ฆฌ์์ค ์ฌ์ ๋ก๋ฉ ์ค...');
|
546 |
+
|
547 |
+
// ์ ํฌ๊ธฐ ์ฌ์ ๋ก๋ฉ
|
548 |
+
await this.fighter.initialize(this.scene, this.loader);
|
549 |
+
|
550 |
+
if (!this.fighter.isLoaded) {
|
551 |
+
throw new Error('์ ํฌ๊ธฐ ๋ก๋ฉ ์คํจ');
|
552 |
+
}
|
553 |
+
|
554 |
+
// ์ด๊ธฐ ์นด๋ฉ๋ผ ์์น ์ค์
|
555 |
+
const initialCameraPos = this.fighter.getCameraPosition();
|
556 |
+
this.camera.position.copy(initialCameraPos);
|
557 |
+
this.camera.lookAt(this.fighter.position);
|
558 |
+
|
559 |
+
// ์ ์์ฑ
|
560 |
+
await this.preloadEnemies();
|
561 |
+
|
562 |
+
this.isLoaded = true;
|
563 |
+
console.log('๊ฒ์ ๋ฆฌ์์ค ๋ก๋ฉ ์๋ฃ');
|
564 |
+
|
565 |
+
// ๋ก๋ฉ ํ๋ฉด ์จ๊ธฐ๊ธฐ
|
566 |
+
document.getElementById('loading').style.display = 'none';
|
567 |
+
|
568 |
+
// ๋ ๋๋ง ์์
|
569 |
+
this.animate();
|
570 |
+
|
571 |
+
} catch (error) {
|
572 |
+
console.error('๊ฒ์ ์ฌ์ ๋ก๋ฉ ์คํจ:', error);
|
573 |
+
document.getElementById('loading').innerHTML =
|
574 |
+
'<div class="loading-text" style="color: red;">๋ก๋ฉ ์คํจ. ํ์ด์ง๋ฅผ ์๋ก๊ณ ์นจํด์ฃผ์ธ์.</div>';
|
575 |
}
|
576 |
+
}
|
577 |
+
|
578 |
+
async preloadEnemies() {
|
579 |
+
for (let i = 0; i < GAME_CONSTANTS.ENEMY_COUNT; i++) {
|
580 |
+
const angle = (i / GAME_CONSTANTS.ENEMY_COUNT) * Math.PI * 2;
|
581 |
+
const distance = 6000 + Math.random() * 3000;
|
582 |
+
|
583 |
+
const position = new THREE.Vector3(
|
584 |
+
Math.cos(angle) * distance,
|
585 |
+
2500 + Math.random() * 2000,
|
586 |
+
Math.sin(angle) * distance
|
587 |
+
);
|
588 |
+
|
589 |
+
const enemy = new EnemyFighter(this.scene, position);
|
590 |
+
await enemy.initialize(this.loader);
|
591 |
+
this.enemies.push(enemy);
|
592 |
}
|
593 |
+
}
|
594 |
+
|
595 |
+
setupScene() {
|
596 |
+
// ํ๋ ๋ฐฐ๊ฒฝ
|
597 |
+
this.scene.background = new THREE.Color(0x87CEEB);
|
598 |
+
this.scene.fog = new THREE.Fog(0x87CEEB, 1000, 30000);
|
599 |
|
600 |
+
// ์กฐ๋ช
|
601 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
|
602 |
+
this.scene.add(ambientLight);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
603 |
|
604 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 1.0);
|
605 |
+
directionalLight.position.set(8000, 10000, 8000);
|
606 |
+
directionalLight.castShadow = true;
|
607 |
+
directionalLight.shadow.mapSize.width = 2048;
|
608 |
+
directionalLight.shadow.mapSize.height = 2048;
|
609 |
+
directionalLight.shadow.camera.near = 0.5;
|
610 |
+
directionalLight.shadow.camera.far = 20000;
|
611 |
+
directionalLight.shadow.camera.left = -10000;
|
612 |
+
directionalLight.shadow.camera.right = 10000;
|
613 |
+
directionalLight.shadow.camera.top = 10000;
|
614 |
+
directionalLight.shadow.camera.bottom = -10000;
|
615 |
+
this.scene.add(directionalLight);
|
616 |
|
617 |
+
// ์งํ
|
618 |
+
const groundGeometry = new THREE.PlaneGeometry(GAME_CONSTANTS.MAP_SIZE, GAME_CONSTANTS.MAP_SIZE);
|
619 |
+
const groundMaterial = new THREE.MeshLambertMaterial({
|
620 |
+
color: 0x8FBC8F,
|
621 |
+
transparent: true,
|
622 |
+
opacity: 0.8
|
623 |
+
});
|
624 |
+
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
625 |
+
ground.rotation.x = -Math.PI / 2;
|
626 |
+
ground.receiveShadow = true;
|
627 |
+
this.scene.add(ground);
|
628 |
+
|
629 |
+
// ๊ตฌ๋ฆ ์ถ๊ฐ
|
630 |
+
this.addClouds();
|
631 |
+
}
|
632 |
+
|
633 |
+
addClouds() {
|
634 |
+
const cloudGeometry = new THREE.SphereGeometry(100, 8, 6);
|
635 |
+
const cloudMaterial = new THREE.MeshLambertMaterial({
|
636 |
+
color: 0xffffff,
|
637 |
+
transparent: true,
|
638 |
+
opacity: 0.5
|
639 |
+
});
|
640 |
+
|
641 |
+
for (let i = 0; i < 100; i++) {
|
642 |
+
const cloud = new THREE.Mesh(cloudGeometry, cloudMaterial);
|
643 |
+
cloud.position.set(
|
644 |
+
(Math.random() - 0.5) * GAME_CONSTANTS.MAP_SIZE,
|
645 |
+
Math.random() * 4000 + 1000,
|
646 |
+
(Math.random() - 0.5) * GAME_CONSTANTS.MAP_SIZE
|
647 |
+
);
|
648 |
+
cloud.scale.set(
|
649 |
+
Math.random() * 3 + 1,
|
650 |
+
Math.random() * 2 + 0.5,
|
651 |
+
Math.random() * 3 + 1
|
652 |
+
);
|
653 |
+
this.scene.add(cloud);
|
654 |
+
}
|
655 |
+
}
|
656 |
+
|
657 |
+
setupEventListeners() {
|
658 |
+
// ํค๋ณด๋ ์ด๋ฒคํธ
|
659 |
+
document.addEventListener('keydown', (event) => {
|
660 |
+
if (!this.isStarted || this.isGameOver) return;
|
661 |
+
|
662 |
+
switch(event.code) {
|
663 |
+
case 'KeyW': this.keys.w = true; break;
|
664 |
+
case 'KeyA': this.keys.a = true; break;
|
665 |
+
case 'KeyS': this.keys.s = true; break;
|
666 |
+
case 'KeyD': this.keys.d = true; break;
|
667 |
+
}
|
668 |
+
});
|
669 |
+
|
670 |
+
document.addEventListener('keyup', (event) => {
|
671 |
+
switch(event.code) {
|
672 |
+
case 'KeyW': this.keys.w = false; break;
|
673 |
+
case 'KeyA': this.keys.a = false; break;
|
674 |
+
case 'KeyS': this.keys.s = false; break;
|
675 |
+
case 'KeyD': this.keys.d = false; break;
|
676 |
}
|
677 |
+
});
|
678 |
+
|
679 |
+
// ๋ง์ฐ์ค ์ด๋ฒคํธ
|
680 |
+
document.addEventListener('mousemove', (event) => {
|
681 |
+
if (!document.pointerLockElement || !this.isStarted || this.isGameOver) return;
|
682 |
+
|
683 |
+
const deltaX = event.movementX || 0;
|
684 |
+
const deltaY = event.movementY || 0;
|
685 |
+
|
686 |
+
this.fighter.updateMouseInput(deltaX, deltaY);
|
687 |
+
});
|
688 |
+
|
689 |
+
document.addEventListener('click', () => {
|
690 |
+
if (!this.isStarted) return;
|
691 |
+
|
692 |
+
if (!document.pointerLockElement) {
|
693 |
+
document.body.requestPointerLock();
|
694 |
+
} else if (!this.isGameOver && this.fighter.isLoaded) {
|
695 |
+
this.fighter.shoot(this.scene);
|
696 |
}
|
697 |
+
});
|
698 |
+
|
699 |
+
// ์๋์ฐ ๋ฆฌ์ฌ์ด์ฆ
|
700 |
+
window.addEventListener('resize', () => {
|
701 |
+
this.camera.aspect = window.innerWidth / window.innerHeight;
|
702 |
+
this.camera.updateProjectionMatrix();
|
703 |
+
this.renderer.setSize(window.innerWidth, window.innerHeight);
|
704 |
+
});
|
705 |
+
}
|
706 |
|
707 |
+
startGame() {
|
708 |
+
if (!this.isLoaded) {
|
709 |
+
console.log('๊ฒ์์ด ์์ง ๋ก๋ฉ ์ค์
๋๋ค...');
|
710 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
711 |
}
|
712 |
+
|
713 |
+
this.isStarted = true;
|
714 |
+
this.startBGM();
|
715 |
+
this.startGameTimer();
|
716 |
+
|
717 |
+
console.log('๊ฒ์ ์์!');
|
718 |
+
}
|
719 |
|
720 |
+
startBGM() {
|
721 |
+
if (this.bgmPlaying) return;
|
722 |
+
|
723 |
+
try {
|
724 |
+
this.bgm = new Audio('sounds/main_bgm.ogg');
|
725 |
+
this.bgm.volume = 0.5;
|
726 |
+
this.bgm.loop = true;
|
727 |
+
this.bgm.play();
|
728 |
+
this.bgmPlaying = true;
|
729 |
+
console.log('BGM ์ฌ์ ์์');
|
730 |
+
} catch (error) {
|
731 |
+
console.log('BGM ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค:', error);
|
732 |
}
|
733 |
+
}
|
734 |
+
|
735 |
+
startGameTimer() {
|
736 |
+
this.gameTimer = setInterval(() => {
|
737 |
+
if (!this.isGameOver) {
|
738 |
+
this.gameTime--;
|
739 |
+
|
740 |
+
if (this.gameTime <= 0) {
|
741 |
+
this.endGame(true);
|
742 |
+
}
|
743 |
+
}
|
744 |
+
}, 1000);
|
745 |
+
}
|
746 |
|
747 |
+
updateUI() {
|
748 |
+
if (this.fighter.isLoaded) {
|
749 |
+
const speedKnots = Math.round(this.fighter.speed * 1.94384);
|
750 |
+
const altitudeFeet = Math.round(this.fighter.altitude * 3.28084);
|
751 |
+
|
752 |
+
document.getElementById('score').textContent = `Score: ${this.score}`;
|
753 |
+
document.getElementById('time').textContent = `Time: ${this.gameTime}s`;
|
754 |
+
document.getElementById('health').style.width = `${this.fighter.health}%`;
|
755 |
+
document.getElementById('ammoDisplay').textContent = `AMMO: ${this.fighter.ammo}`;
|
756 |
+
|
757 |
+
const gameStats = document.getElementById('gameStats');
|
758 |
+
if (gameStats) {
|
759 |
+
gameStats.innerHTML = `
|
760 |
+
<div>Score: ${this.score}</div>
|
761 |
+
<div>Time: ${this.gameTime}s</div>
|
762 |
+
<div>Speed: ${speedKnots} KT</div>
|
763 |
+
<div>Alt: ${altitudeFeet} FT</div>
|
764 |
+
<div>Throttle: ${Math.round(this.fighter.throttle * 100)}%</div>
|
765 |
+
<div>G-Force: ${this.fighter.gForce.toFixed(1)}</div>
|
766 |
+
<div>Targets: ${this.enemies.length}</div>
|
767 |
+
`;
|
768 |
+
}
|
769 |
}
|
770 |
+
}
|
771 |
+
|
772 |
+
updateRadar() {
|
773 |
+
const radar = document.getElementById('radar');
|
774 |
+
if (!radar) return;
|
775 |
|
776 |
+
const oldDots = radar.getElementsByClassName('enemy-dot');
|
777 |
+
while (oldDots[0]) {
|
778 |
+
oldDots[0].remove();
|
779 |
}
|
780 |
+
|
781 |
+
const radarCenter = { x: 100, y: 100 };
|
782 |
+
const radarRange = 10000;
|
783 |
+
|
784 |
+
this.enemies.forEach(enemy => {
|
785 |
+
if (!enemy.mesh || !enemy.isLoaded) return;
|
786 |
+
|
787 |
+
const distance = this.fighter.position.distanceTo(enemy.position);
|
788 |
+
if (distance <= radarRange) {
|
789 |
+
const relativePos = enemy.position.clone().sub(this.fighter.position);
|
790 |
+
const angle = Math.atan2(relativePos.x, relativePos.z);
|
791 |
+
const relativeDistance = distance / radarRange;
|
792 |
+
|
793 |
+
const dotX = radarCenter.x + Math.sin(angle) * (radarCenter.x * relativeDistance);
|
794 |
+
const dotY = radarCenter.y + Math.cos(angle) * (radarCenter.y * relativeDistance);
|
795 |
+
|
796 |
+
const dot = document.createElement('div');
|
797 |
+
dot.className = 'enemy-dot';
|
798 |
+
dot.style.left = `${dotX}px`;
|
799 |
+
dot.style.top = `${dotY}px`;
|
800 |
+
radar.appendChild(dot);
|
801 |
+
}
|
802 |
+
});
|
803 |
+
}
|
804 |
|
805 |
+
checkCollisions() {
|
806 |
+
// ํ๋ ์ด์ด ์ด์๊ณผ ์ ์ถฉ๋
|
807 |
+
for (let i = this.fighter.bullets.length - 1; i >= 0; i--) {
|
808 |
+
const bullet = this.fighter.bullets[i];
|
809 |
+
|
810 |
+
for (let j = this.enemies.length - 1; j >= 0; j--) {
|
811 |
+
const enemy = this.enemies[j];
|
812 |
+
if (!enemy.mesh || !enemy.isLoaded) continue;
|
813 |
+
|
814 |
+
const distance = bullet.position.distanceTo(enemy.position);
|
815 |
+
if (distance < 25) {
|
816 |
+
this.scene.remove(bullet);
|
817 |
+
this.fighter.bullets.splice(i, 1);
|
818 |
+
|
819 |
+
if (enemy.takeDamage(30)) {
|
820 |
+
enemy.destroy();
|
821 |
+
this.enemies.splice(j, 1);
|
822 |
+
this.score += 100;
|
823 |
+
}
|
824 |
+
break;
|
825 |
+
}
|
826 |
+
}
|
827 |
}
|
828 |
+
|
829 |
+
// ์ ์ด์๊ณผ ํ๋ ์ด์ด ์ถฉ๋
|
830 |
+
this.enemies.forEach(enemy => {
|
831 |
+
enemy.bullets.forEach((bullet, index) => {
|
832 |
+
const distance = bullet.position.distanceTo(this.fighter.position);
|
833 |
+
if (distance < 30) {
|
834 |
+
this.scene.remove(bullet);
|
835 |
+
enemy.bullets.splice(index, 1);
|
836 |
+
|
837 |
+
if (this.fighter.takeDamage(20)) {
|
838 |
+
this.endGame(false);
|
839 |
+
}
|
840 |
+
}
|
841 |
+
});
|
842 |
+
});
|
843 |
+
}
|
|
|
|
|
|
|
844 |
|
845 |
+
animate() {
|
846 |
+
if (this.isGameOver) return;
|
847 |
+
|
848 |
+
this.animationFrameId = requestAnimationFrame(() => this.animate());
|
849 |
+
|
850 |
+
const currentTime = performance.now();
|
851 |
+
const deltaTime = Math.min((currentTime - this.lastTime) / 1000, 0.1);
|
852 |
+
this.lastTime = currentTime;
|
853 |
+
|
854 |
+
if (this.isLoaded && this.fighter.isLoaded) {
|
855 |
+
if (this.isStarted) {
|
856 |
+
// ์ ํฌ๊ธฐ ์
๋ฐ์ดํธ
|
857 |
+
this.fighter.updateControls(this.keys, deltaTime);
|
858 |
+
this.fighter.updatePhysics(deltaTime);
|
859 |
+
this.fighter.updateBullets(this.scene, deltaTime);
|
860 |
+
|
861 |
+
// ์ ์
๋ฐ์ดํธ
|
862 |
+
this.enemies.forEach(enemy => {
|
863 |
+
enemy.update(this.fighter.position, deltaTime);
|
864 |
+
});
|
865 |
+
|
866 |
+
// ์ถฉ๋ ๊ฒ์ฌ
|
867 |
+
this.checkCollisions();
|
868 |
+
|
869 |
+
// UI ์
๋ฐ์ดํธ
|
870 |
+
this.updateUI();
|
871 |
+
this.updateRadar();
|
872 |
+
|
873 |
+
// ์น๋ฆฌ ์กฐ๊ฑด ํ์ธ
|
874 |
+
if (this.enemies.length === 0) {
|
875 |
+
this.endGame(true);
|
876 |
+
}
|
|
|
|
|
877 |
}
|
878 |
+
|
879 |
+
// ์นด๋ฉ๋ผ ์
๋ฐ์ดํธ (๋ถ๋๋ฝ๊ฒ ๋ฐ๋ผ๊ฐ๊ธฐ)
|
880 |
+
const targetCameraPos = this.fighter.getCameraPosition();
|
881 |
+
const targetCameraTarget = this.fighter.getCameraTarget();
|
882 |
+
|
883 |
+
this.camera.position.lerp(targetCameraPos, this.fighter.cameraLag);
|
884 |
+
this.camera.lookAt(targetCameraTarget);
|
885 |
}
|
886 |
+
|
887 |
+
this.renderer.render(this.scene, this.camera);
|
888 |
+
}
|
889 |
+
|
890 |
+
endGame(victory = false) {
|
891 |
+
this.isGameOver = true;
|
892 |
+
|
893 |
+
if (this.bgm) {
|
894 |
+
this.bgm.pause();
|
895 |
+
this.bgm = null;
|
896 |
+
this.bgmPlaying = false;
|
897 |
+
}
|
898 |
+
|
899 |
+
if (this.gameTimer) {
|
900 |
+
clearInterval(this.gameTimer);
|
901 |
}
|
902 |
+
|
903 |
+
document.exitPointerLock();
|
904 |
+
|
905 |
+
const gameOverDiv = document.createElement('div');
|
906 |
+
gameOverDiv.className = 'start-screen';
|
907 |
+
gameOverDiv.innerHTML = `
|
908 |
+
<h1 style="color: ${victory ? '#0f0' : '#f00'}; font-size: 48px;">
|
909 |
+
${victory ? 'MISSION ACCOMPLISHED!' : 'SHOT DOWN!'}
|
910 |
+
</h1>
|
911 |
+
<div style="color: #0f0; font-size: 24px; margin: 20px 0;">
|
912 |
+
Final Score: ${this.score}<br>
|
913 |
+
Enemies Destroyed: ${GAME_CONSTANTS.ENEMY_COUNT - this.enemies.length}<br>
|
914 |
+
Mission Time: ${GAME_CONSTANTS.MISSION_DURATION - this.gameTime}s
|
915 |
+
</div>
|
916 |
+
<button class="start-button" onclick="location.reload()">
|
917 |
+
New Mission
|
918 |
+
</button>
|
919 |
+
`;
|
920 |
+
|
921 |
+
document.body.appendChild(gameOverDiv);
|
922 |
+
}
|
923 |
+
}
|
924 |
|
925 |
+
// ๊ฒ์ ์ธ์คํด์ค
|
926 |
+
let gameInstance = null;
|
927 |
+
|
928 |
+
// ์ ์ญ ํจ์
|
929 |
+
window.startGame = function() {
|
930 |
+
document.getElementById('startScreen').style.display = 'none';
|
931 |
+
document.body.requestPointerLock();
|
932 |
+
|
933 |
+
if (gameInstance && gameInstance.isLoaded) {
|
934 |
+
gameInstance.startGame();
|
935 |
+
} else {
|
936 |
+
console.log('๊ฒ์์ด ์์ง ์ค๋น๋์ง ์์์ต๋๋ค...');
|
937 |
+
}
|
938 |
+
};
|
939 |
+
|
940 |
+
// ๊ฒ์ ์ด๊ธฐํ
|
941 |
+
document.addEventListener('DOMContentLoaded', () => {
|
942 |
+
console.log('์ ํฌ๊ธฐ ์๋ฎฌ๋ ์ดํฐ ์ด๊ธฐํ ์ค...');
|
943 |
+
gameInstance = new Game();
|
944 |
+
});
|