Spaces:
Running
Running
cutechicken
commited on
Commit
β’
c7fc102
1
Parent(s):
23275ba
Update game.js
Browse files
game.js
CHANGED
@@ -920,21 +920,22 @@ checkPathClear(start, end) {
|
|
920 |
|
921 |
// μμΌ νμΈ λ©μλ (κΈ°μ‘΄ μ½λ μμ )
|
922 |
checkLineOfSight(playerPosition) {
|
923 |
-
|
924 |
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
|
|
931 |
|
932 |
-
|
933 |
-
|
934 |
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
// λ체 κ²½λ‘ μ°ΎκΈ° λ©μλ
|
939 |
findAlternativePath(playerPosition) {
|
940 |
const currentPos = this.mesh.position.clone();
|
@@ -1577,7 +1578,7 @@ class Game {
|
|
1577 |
this.obstacles = [];
|
1578 |
}
|
1579 |
|
1580 |
-
const BUILDING_COUNT =
|
1581 |
const buildingModels = [
|
1582 |
'models/house1.glb',
|
1583 |
'models/house2.glb',
|
@@ -2373,47 +2374,52 @@ updateCrosshair() {
|
|
2373 |
}
|
2374 |
|
2375 |
animate() {
|
2376 |
-
|
2377 |
-
|
2378 |
-
|
2379 |
-
}
|
2380 |
-
return;
|
2381 |
-
}
|
2382 |
-
|
2383 |
-
this.animationFrameId = requestAnimationFrame(() => this.animate());
|
2384 |
-
// κ²μμ΄ μμλμ§ μμμΌλ©΄ λ λλ§λ§ μν
|
2385 |
-
if (!this.isStarted) {
|
2386 |
-
this.renderer.render(this.scene, this.camera);
|
2387 |
-
return;
|
2388 |
}
|
|
|
|
|
2389 |
|
2390 |
-
|
2391 |
-
|
2392 |
-
|
|
|
|
|
|
|
|
|
2393 |
|
2394 |
-
|
2395 |
-
|
2396 |
-
|
2397 |
-
|
2398 |
-
|
2399 |
-
|
2400 |
-
|
2401 |
-
|
2402 |
-
|
2403 |
-
|
2404 |
-
|
2405 |
-
|
2406 |
-
|
2407 |
-
|
2408 |
-
|
2409 |
-
|
2410 |
-
|
2411 |
-
|
2412 |
-
|
2413 |
-
|
2414 |
-
|
2415 |
-
|
2416 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2417 |
}
|
2418 |
|
2419 |
// Start game
|
|
|
920 |
|
921 |
// μμΌ νμΈ λ©μλ (κΈ°μ‘΄ μ½λ μμ )
|
922 |
checkLineOfSight(playerPosition) {
|
923 |
+
if (!this.mesh) return false;
|
924 |
|
925 |
+
const startPos = this.mesh.position.clone();
|
926 |
+
startPos.y += 2; // ν¬ν λμ΄μμ μμ
|
927 |
+
|
928 |
+
const direction = new THREE.Vector3()
|
929 |
+
.subVectors(playerPosition, startPos)
|
930 |
+
.normalize();
|
931 |
+
const distance = startPos.distanceTo(playerPosition);
|
932 |
|
933 |
+
const raycaster = new THREE.Raycaster(startPos, direction, 0, distance);
|
934 |
+
const intersects = raycaster.intersectObjects(window.gameInstance.obstacles, true);
|
935 |
|
936 |
+
// μ₯μ λ¬Όμ΄ μμ κ²½μ° false λ°ν
|
937 |
+
return intersects.length === 0;
|
938 |
+
}
|
939 |
// λ체 κ²½λ‘ μ°ΎκΈ° λ©μλ
|
940 |
findAlternativePath(playerPosition) {
|
941 |
const currentPos = this.mesh.position.clone();
|
|
|
1578 |
this.obstacles = [];
|
1579 |
}
|
1580 |
|
1581 |
+
const BUILDING_COUNT = 50; // λ°μ λμ κ±΄λ¬Όλ‘ λ³κ²½
|
1582 |
const buildingModels = [
|
1583 |
'models/house1.glb',
|
1584 |
'models/house2.glb',
|
|
|
2374 |
}
|
2375 |
|
2376 |
animate() {
|
2377 |
+
if (this.isGameOver) {
|
2378 |
+
if (this.animationFrameId) {
|
2379 |
+
cancelAnimationFrame(this.animationFrameId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2380 |
}
|
2381 |
+
return;
|
2382 |
+
}
|
2383 |
|
2384 |
+
this.animationFrameId = requestAnimationFrame(() => this.animate());
|
2385 |
+
|
2386 |
+
// κ²μμ΄ μμλμ§ μμμΌλ©΄ λ λλ§λ§ μν
|
2387 |
+
if (!this.isStarted) {
|
2388 |
+
this.renderer.render(this.scene, this.camera);
|
2389 |
+
return;
|
2390 |
+
}
|
2391 |
|
2392 |
+
const currentTime = performance.now();
|
2393 |
+
const deltaTime = (currentTime - this.lastTime) / 1000;
|
2394 |
+
this.lastTime = currentTime;
|
2395 |
+
|
2396 |
+
if (!this.isLoading) {
|
2397 |
+
this.handleMovement();
|
2398 |
+
this.tank.update(this.mouse.x, this.mouse.y, this.scene);
|
2399 |
+
|
2400 |
+
const tankPosition = this.tank.getPosition();
|
2401 |
+
|
2402 |
+
// κ° μ ν±ν¬ μ
λ°μ΄νΈ
|
2403 |
+
this.enemies.forEach(enemy => {
|
2404 |
+
enemy.update(tankPosition);
|
2405 |
+
|
2406 |
+
// μ μ΄ λ‘λλμκ³ , μμΌ ν보λμμ λλ§ λ°μ¬
|
2407 |
+
if (enemy.isLoaded &&
|
2408 |
+
enemy.checkLineOfSight(tankPosition) &&
|
2409 |
+
enemy.mesh.position.distanceTo(tankPosition) < ENEMY_CONFIG.ATTACK_RANGE) {
|
2410 |
+
enemy.shoot(tankPosition);
|
2411 |
+
}
|
2412 |
+
});
|
2413 |
+
|
2414 |
+
this.updateEnemyLabels();
|
2415 |
+
this.updateParticles();
|
2416 |
+
this.checkCollisions();
|
2417 |
+
this.updateUI();
|
2418 |
+
this.updateRadar();
|
2419 |
+
this.updateCrosshair();
|
2420 |
+
}
|
2421 |
+
|
2422 |
+
this.renderer.render(this.scene, this.camera);
|
2423 |
}
|
2424 |
|
2425 |
// Start game
|