Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -282,30 +282,35 @@ class Fighter {
|
|
| 282 |
updateControls(keys, deltaTime) {
|
| 283 |
// ๋๋ฒ๊น
์ ์ํ ๋ก๊ทธ
|
| 284 |
if (keys.w || keys.s || keys.a || keys.d) {
|
| 285 |
-
console.log('
|
| 286 |
w: keys.w,
|
| 287 |
a: keys.a,
|
| 288 |
s: keys.s,
|
| 289 |
d: keys.d,
|
| 290 |
-
|
| 291 |
-
|
|
|
|
| 292 |
});
|
| 293 |
}
|
| 294 |
|
| 295 |
// W/S: ์ค๋กํ๋ง ์ ์ด (๊ฐ์/๊ฐ์)
|
| 296 |
if (keys.w) {
|
| 297 |
this.throttle = Math.min(1.0, this.throttle + deltaTime * 0.5);
|
|
|
|
| 298 |
}
|
| 299 |
if (keys.s) {
|
| 300 |
this.throttle = Math.max(0.1, this.throttle - deltaTime * 0.5);
|
|
|
|
| 301 |
}
|
| 302 |
|
| 303 |
// A/D: ๋ณด์กฐ ์ ์ ์ด (๋ฌ๋) - ๋ฐ์์ฑ ๊ฐ์
|
| 304 |
if (keys.a) {
|
| 305 |
this.targetYaw -= deltaTime * 1.2;
|
|
|
|
| 306 |
}
|
| 307 |
if (keys.d) {
|
| 308 |
this.targetYaw += deltaTime * 1.2;
|
|
|
|
| 309 |
}
|
| 310 |
}
|
| 311 |
|
|
@@ -2830,92 +2835,93 @@ class Game {
|
|
| 2830 |
const deltaTime = Math.min((currentTime - this.lastTime) / 1000, 0.1);
|
| 2831 |
this.lastTime = currentTime;
|
| 2832 |
|
| 2833 |
-
if (this.isLoaded && this.fighter.isLoaded) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2834 |
// Fํค ์ํ๋ฅผ Fighter์ ์ ๋ฌ
|
| 2835 |
this.fighter.escapeKeyPressed = this.keys.f;
|
| 2836 |
|
| 2837 |
-
//
|
| 2838 |
-
|
| 2839 |
-
this.fighter.updateControls(this.keys, deltaTime);
|
| 2840 |
-
}
|
| 2841 |
|
|
|
|
| 2842 |
this.fighter.updatePhysics(deltaTime);
|
|
|
|
|
|
|
| 2843 |
this.fighter.updateBullets(this.scene, deltaTime, this);
|
| 2844 |
|
| 2845 |
-
|
| 2846 |
-
|
| 2847 |
-
|
| 2848 |
-
|
| 2849 |
-
|
| 2850 |
-
|
| 2851 |
-
this.lastShootTime = currentShootTime;
|
| 2852 |
-
}
|
| 2853 |
}
|
| 2854 |
-
|
| 2855 |
-
|
| 2856 |
-
|
| 2857 |
-
|
| 2858 |
-
|
| 2859 |
-
|
| 2860 |
-
|
| 2861 |
-
|
| 2862 |
-
|
| 2863 |
-
|
| 2864 |
-
|
| 2865 |
-
|
| 2866 |
-
|
| 2867 |
-
|
| 2868 |
-
|
| 2869 |
-
|
| 2870 |
-
|
| 2871 |
-
|
| 2872 |
-
|
| 2873 |
-
|
| 2874 |
-
return;
|
| 2875 |
-
}
|
| 2876 |
-
|
| 2877 |
-
this.updateUI();
|
| 2878 |
-
this.updateRadar();
|
| 2879 |
-
|
| 2880 |
-
if (this.enemies.length === 0) {
|
| 2881 |
-
this.endGame(true);
|
| 2882 |
-
}
|
| 2883 |
-
}
|
| 2884 |
-
|
| 2885 |
-
// ๊ตฌ๋ฆ ์ ๋๋ฉ์ด์
|
| 2886 |
-
if (this.clouds) {
|
| 2887 |
-
this.clouds.forEach(cloud => {
|
| 2888 |
-
cloud.userData.time += deltaTime;
|
| 2889 |
-
// ์ข์ฐ ๋๋ฆฌํํธ
|
| 2890 |
-
cloud.position.x += cloud.userData.driftSpeed;
|
| 2891 |
-
// ์ํ ๋ถ์
|
| 2892 |
-
cloud.position.y = cloud.userData.initialY +
|
| 2893 |
-
Math.sin(cloud.userData.time * cloud.userData.floatSpeed) * 20;
|
| 2894 |
-
|
| 2895 |
-
// ๋งต ๊ฒฝ๊ณ ์ฒ๋ฆฌ
|
| 2896 |
-
const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2;
|
| 2897 |
-
if (cloud.position.x > mapLimit) cloud.position.x = -mapLimit;
|
| 2898 |
-
if (cloud.position.x < -mapLimit) cloud.position.x = mapLimit;
|
| 2899 |
-
});
|
| 2900 |
-
}
|
| 2901 |
-
|
| 2902 |
-
const targetCameraPos = this.fighter.getCameraPosition();
|
| 2903 |
-
const targetCameraTarget = this.fighter.getCameraTarget();
|
| 2904 |
-
|
| 2905 |
-
this.camera.position.lerp(targetCameraPos, this.fighter.cameraLag);
|
| 2906 |
-
|
| 2907 |
-
this.camera.lookAt(targetCameraTarget);
|
| 2908 |
-
} else {
|
| 2909 |
-
if (this.fighter.isLoaded) {
|
| 2910 |
-
const initialCameraPos = this.fighter.getCameraPosition();
|
| 2911 |
-
const initialTarget = this.fighter.getCameraTarget();
|
| 2912 |
-
this.camera.position.copy(initialCameraPos);
|
| 2913 |
-
this.camera.lookAt(initialTarget);
|
| 2914 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2915 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2916 |
|
| 2917 |
-
this.
|
|
|
|
| 2918 |
}
|
|
|
|
|
|
|
|
|
|
| 2919 |
|
| 2920 |
endGame(victory = false, reason = "") {
|
| 2921 |
this.isGameOver = true;
|
|
|
|
| 282 |
updateControls(keys, deltaTime) {
|
| 283 |
// ๋๋ฒ๊น
์ ์ํ ๋ก๊ทธ
|
| 284 |
if (keys.w || keys.s || keys.a || keys.d) {
|
| 285 |
+
console.log('updateControls called:', {
|
| 286 |
w: keys.w,
|
| 287 |
a: keys.a,
|
| 288 |
s: keys.s,
|
| 289 |
d: keys.d,
|
| 290 |
+
throttle_before: this.throttle,
|
| 291 |
+
targetYaw_before: this.targetYaw,
|
| 292 |
+
deltaTime: deltaTime
|
| 293 |
});
|
| 294 |
}
|
| 295 |
|
| 296 |
// W/S: ์ค๋กํ๋ง ์ ์ด (๊ฐ์/๊ฐ์)
|
| 297 |
if (keys.w) {
|
| 298 |
this.throttle = Math.min(1.0, this.throttle + deltaTime * 0.5);
|
| 299 |
+
console.log('W pressed - New throttle:', this.throttle);
|
| 300 |
}
|
| 301 |
if (keys.s) {
|
| 302 |
this.throttle = Math.max(0.1, this.throttle - deltaTime * 0.5);
|
| 303 |
+
console.log('S pressed - New throttle:', this.throttle);
|
| 304 |
}
|
| 305 |
|
| 306 |
// A/D: ๋ณด์กฐ ์ ์ ์ด (๋ฌ๋) - ๋ฐ์์ฑ ๊ฐ์
|
| 307 |
if (keys.a) {
|
| 308 |
this.targetYaw -= deltaTime * 1.2;
|
| 309 |
+
console.log('A pressed - New targetYaw:', this.targetYaw);
|
| 310 |
}
|
| 311 |
if (keys.d) {
|
| 312 |
this.targetYaw += deltaTime * 1.2;
|
| 313 |
+
console.log('D pressed - New targetYaw:', this.targetYaw);
|
| 314 |
}
|
| 315 |
}
|
| 316 |
|
|
|
|
| 2835 |
const deltaTime = Math.min((currentTime - this.lastTime) / 1000, 0.1);
|
| 2836 |
this.lastTime = currentTime;
|
| 2837 |
|
| 2838 |
+
if (this.isLoaded && this.fighter.isLoaded && this.isStarted) {
|
| 2839 |
+
// ํค ์ํ ๋๋ฒ๊น
|
| 2840 |
+
if (this.keys.w || this.keys.s || this.keys.a || this.keys.d) {
|
| 2841 |
+
console.log('animate() - Keys state:', this.keys);
|
| 2842 |
+
}
|
| 2843 |
+
|
| 2844 |
// Fํค ์ํ๋ฅผ Fighter์ ์ ๋ฌ
|
| 2845 |
this.fighter.escapeKeyPressed = this.keys.f;
|
| 2846 |
|
| 2847 |
+
// ์ปจํธ๋กค ์
๋ฐ์ดํธ - ๋ฐ๋์ ๋ฌผ๋ฆฌ ์
๋ฐ์ดํธ ์ ์ ํธ์ถ
|
| 2848 |
+
this.fighter.updateControls(this.keys, deltaTime);
|
|
|
|
|
|
|
| 2849 |
|
| 2850 |
+
// ๋ฌผ๋ฆฌ ์
๋ฐ์ดํธ
|
| 2851 |
this.fighter.updatePhysics(deltaTime);
|
| 2852 |
+
|
| 2853 |
+
// ํํ ์
๋ฐ์ดํธ
|
| 2854 |
this.fighter.updateBullets(this.scene, deltaTime, this);
|
| 2855 |
|
| 2856 |
+
// ๋ง์ฐ์ค ๋๋ฆ ์ํ์ผ ๋ ์ฐ์ ๋ฐ์ฌ
|
| 2857 |
+
if (this.fighter.isMouseDown) {
|
| 2858 |
+
const currentShootTime = Date.now();
|
| 2859 |
+
if (!this.lastShootTime || currentShootTime - this.lastShootTime >= 100) {
|
| 2860 |
+
this.fighter.shoot(this.scene);
|
| 2861 |
+
this.lastShootTime = currentShootTime;
|
|
|
|
|
|
|
| 2862 |
}
|
| 2863 |
+
}
|
| 2864 |
+
|
| 2865 |
+
// ์ ๊ธฐ ์
๋ฐ์ดํธ
|
| 2866 |
+
this.enemies.forEach(enemy => {
|
| 2867 |
+
enemy.nearbyEnemies = this.enemies;
|
| 2868 |
+
});
|
| 2869 |
+
|
| 2870 |
+
this.enemies.forEach(enemy => {
|
| 2871 |
+
enemy.update(this.fighter.position, deltaTime);
|
| 2872 |
+
});
|
| 2873 |
+
|
| 2874 |
+
// ์ถฉ๋ ์ฒดํฌ
|
| 2875 |
+
this.checkCollisions();
|
| 2876 |
+
|
| 2877 |
+
// ๊ฒ์ ์ข
๋ฃ ์กฐ๊ฑด ์ฒดํฌ
|
| 2878 |
+
if (this.fighter.health <= 0) {
|
| 2879 |
+
if (this.fighter.position.y <= 0) {
|
| 2880 |
+
this.endGame(false, "GROUND COLLISION");
|
| 2881 |
+
} else {
|
| 2882 |
+
this.endGame(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2883 |
}
|
| 2884 |
+
return;
|
| 2885 |
+
}
|
| 2886 |
+
|
| 2887 |
+
// UI ์
๋ฐ์ดํธ
|
| 2888 |
+
this.updateUI();
|
| 2889 |
+
this.updateRadar();
|
| 2890 |
+
|
| 2891 |
+
// ์ ์ด ๋ชจ๋ ์ ๊ฑฐ๋์๋์ง ์ฒดํฌ
|
| 2892 |
+
if (this.enemies.length === 0) {
|
| 2893 |
+
this.endGame(true);
|
| 2894 |
}
|
| 2895 |
+
} else if (this.isLoaded && this.fighter.isLoaded) {
|
| 2896 |
+
// ๊ฒ์์ด ์์๋์ง ์์์ ๋๋ ๋ฌผ๋ฆฌ๋ ์
๋ฐ์ดํธ (์นด๋ฉ๋ผ ์์ง์์ ์ํด)
|
| 2897 |
+
this.fighter.updatePhysics(deltaTime);
|
| 2898 |
+
}
|
| 2899 |
+
|
| 2900 |
+
// ๊ตฌ๋ฆ ์ ๋๋ฉ์ด์
|
| 2901 |
+
if (this.clouds) {
|
| 2902 |
+
this.clouds.forEach(cloud => {
|
| 2903 |
+
cloud.userData.time += deltaTime;
|
| 2904 |
+
cloud.position.x += cloud.userData.driftSpeed;
|
| 2905 |
+
cloud.position.y = cloud.userData.initialY +
|
| 2906 |
+
Math.sin(cloud.userData.time * cloud.userData.floatSpeed) * 20;
|
| 2907 |
+
|
| 2908 |
+
const mapLimit = GAME_CONSTANTS.MAP_SIZE / 2;
|
| 2909 |
+
if (cloud.position.x > mapLimit) cloud.position.x = -mapLimit;
|
| 2910 |
+
if (cloud.position.x < -mapLimit) cloud.position.x = mapLimit;
|
| 2911 |
+
});
|
| 2912 |
+
}
|
| 2913 |
+
|
| 2914 |
+
// ์นด๋ฉ๋ผ ์
๋ฐ์ดํธ
|
| 2915 |
+
if (this.fighter.isLoaded) {
|
| 2916 |
+
const targetCameraPos = this.fighter.getCameraPosition();
|
| 2917 |
+
const targetCameraTarget = this.fighter.getCameraTarget();
|
| 2918 |
|
| 2919 |
+
this.camera.position.lerp(targetCameraPos, this.fighter.cameraLag);
|
| 2920 |
+
this.camera.lookAt(targetCameraTarget);
|
| 2921 |
}
|
| 2922 |
+
|
| 2923 |
+
this.renderer.render(this.scene, this.camera);
|
| 2924 |
+
}
|
| 2925 |
|
| 2926 |
endGame(victory = false, reason = "") {
|
| 2927 |
this.isGameOver = true;
|