Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -735,12 +735,17 @@ class Particle {
|
|
| 735 |
// Game ν΄λμ€
|
| 736 |
class Game {
|
| 737 |
constructor() {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
this.scene = new THREE.Scene();
|
| 739 |
this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 740 |
this.renderer = new THREE.WebGLRenderer({ antialias: true });
|
| 741 |
this.renderer.setSize(window.innerWidth, window.innerHeight);
|
| 742 |
this.renderer.shadowMap.enabled = true;
|
| 743 |
document.getElementById('gameContainer').appendChild(this.renderer.domElement);
|
|
|
|
| 744 |
|
| 745 |
// λ μ΄λ κ΄λ ¨ μμ± μΆκ°
|
| 746 |
this.radarUpdateInterval = 100; // 100msλ§λ€ λ μ΄λ μ
λ°μ΄νΈ
|
|
@@ -777,6 +782,12 @@ class Game {
|
|
| 777 |
|
| 778 |
async initialize() {
|
| 779 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 780 |
// μκ° ν¨κ³Ό μ κ±°
|
| 781 |
this.scene.fog = null;
|
| 782 |
this.scene.background = new THREE.Color(0x87CEEB);
|
|
@@ -1186,6 +1197,45 @@ class Game {
|
|
| 1186 |
if (!this.tank.isLoaded || this.isGameOver) return;
|
| 1187 |
|
| 1188 |
const direction = new THREE.Vector3();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1189 |
|
| 1190 |
// 차체 μ΄λκ³Ό νμ μ μ μ§
|
| 1191 |
if (this.keys.forward) direction.z += 1;
|
|
@@ -1414,6 +1464,17 @@ class Game {
|
|
| 1414 |
checkCollisions() {
|
| 1415 |
if (this.isLoading || !this.tank.isLoaded) return;
|
| 1416 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1417 |
const tankPosition = this.tank.getPosition();
|
| 1418 |
// μ μ΄μκ³Ό νλ μ΄μ΄ ν±ν¬ μΆ©λ 체ν¬
|
| 1419 |
this.enemies.forEach(enemy => {
|
|
@@ -1422,6 +1483,11 @@ class Game {
|
|
| 1422 |
enemy.bullets.forEach(bullet => {
|
| 1423 |
const distance = bullet.position.distanceTo(tankPosition);
|
| 1424 |
if (distance < 1) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1425 |
if (this.tank.takeDamage(250)) { // λ°λ―Έμ§λ₯Ό 250μΌλ‘ μμ
|
| 1426 |
this.endGame();
|
| 1427 |
}
|
|
@@ -1442,6 +1508,11 @@ class Game {
|
|
| 1442 |
|
| 1443 |
const distance = bullet.position.distanceTo(enemy.mesh.position);
|
| 1444 |
if (distance < 2) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1445 |
if (enemy.takeDamage(50)) {
|
| 1446 |
enemy.destroy();
|
| 1447 |
this.enemies.splice(enemyIndex, 1);
|
|
|
|
| 735 |
// Game ν΄λμ€
|
| 736 |
class Game {
|
| 737 |
constructor() {
|
| 738 |
+
// μ€λμ€ κ΄λ ¨ μμ± μΆκ°
|
| 739 |
+
this.engineSound = null;
|
| 740 |
+
this.engineStopSound = null;
|
| 741 |
+
this.isEngineRunning = false;
|
| 742 |
this.scene = new THREE.Scene();
|
| 743 |
this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 744 |
this.renderer = new THREE.WebGLRenderer({ antialias: true });
|
| 745 |
this.renderer.setSize(window.innerWidth, window.innerHeight);
|
| 746 |
this.renderer.shadowMap.enabled = true;
|
| 747 |
document.getElementById('gameContainer').appendChild(this.renderer.domElement);
|
| 748 |
+
|
| 749 |
|
| 750 |
// λ μ΄λ κ΄λ ¨ μμ± μΆκ°
|
| 751 |
this.radarUpdateInterval = 100; // 100msλ§λ€ λ μ΄λ μ
λ°μ΄νΈ
|
|
|
|
| 782 |
|
| 783 |
async initialize() {
|
| 784 |
try {
|
| 785 |
+
// μμ μ¬μ΄λ μ¬μ
|
| 786 |
+
const startSounds = ['sounds/start1.ogg', 'sounds/start2.ogg', 'sounds/start3.ogg'];
|
| 787 |
+
const randomStartSound = startSounds[Math.floor(Math.random() * startSounds.length)];
|
| 788 |
+
const startAudio = new Audio(randomStartSound);
|
| 789 |
+
startAudio.volume = 0.5;
|
| 790 |
+
startAudio.play();
|
| 791 |
// μκ° ν¨κ³Ό μ κ±°
|
| 792 |
this.scene.fog = null;
|
| 793 |
this.scene.background = new THREE.Color(0x87CEEB);
|
|
|
|
| 1197 |
if (!this.tank.isLoaded || this.isGameOver) return;
|
| 1198 |
|
| 1199 |
const direction = new THREE.Vector3();
|
| 1200 |
+
const isMoving = this.keys.forward || this.keys.backward;
|
| 1201 |
+
// μ΄λ μμν λ μ¬μ΄λ μ²λ¦¬
|
| 1202 |
+
if (isMoving && !this.isEngineRunning) {
|
| 1203 |
+
this.isEngineRunning = true;
|
| 1204 |
+
|
| 1205 |
+
// μ΄μ μ¬μ΄λ μ μ§
|
| 1206 |
+
if (this.engineStopSound) {
|
| 1207 |
+
this.engineStopSound.pause();
|
| 1208 |
+
}
|
| 1209 |
+
if (this.engineSound) {
|
| 1210 |
+
this.engineSound.pause();
|
| 1211 |
+
}
|
| 1212 |
+
|
| 1213 |
+
// μμ§ μ μ§ μ¬μ΄λ μ¬μ
|
| 1214 |
+
this.engineStopSound = new Audio('sounds/enginestop.ogg');
|
| 1215 |
+
this.engineStopSound.play();
|
| 1216 |
+
|
| 1217 |
+
// μμ§ μ μ§ μ¬μ΄λ μ’
λ£ ν μμ§ μ¬μ΄λ μμ
|
| 1218 |
+
this.engineStopSound.onended = () => {
|
| 1219 |
+
this.engineSound = new Audio('sounds/engine.ogg');
|
| 1220 |
+
this.engineSound.loop = true;
|
| 1221 |
+
this.engineSound.play();
|
| 1222 |
+
};
|
| 1223 |
+
}
|
| 1224 |
+
// μ΄λ λ©μΆ λ μ¬μ΄λ μ²λ¦¬
|
| 1225 |
+
else if (!isMoving && this.isEngineRunning) {
|
| 1226 |
+
this.isEngineRunning = false;
|
| 1227 |
+
if (this.engineSound) {
|
| 1228 |
+
this.engineSound.pause();
|
| 1229 |
+
this.engineSound = null;
|
| 1230 |
+
}
|
| 1231 |
+
if (this.engineStopSound) {
|
| 1232 |
+
this.engineStopSound.pause();
|
| 1233 |
+
this.engineStopSound = null;
|
| 1234 |
+
}
|
| 1235 |
+
const stopSound = new Audio('sounds/enginestop.ogg');
|
| 1236 |
+
stopSound.play();
|
| 1237 |
+
}
|
| 1238 |
+
|
| 1239 |
|
| 1240 |
// 차체 μ΄λκ³Ό νμ μ μ μ§
|
| 1241 |
if (this.keys.forward) direction.z += 1;
|
|
|
|
| 1464 |
checkCollisions() {
|
| 1465 |
if (this.isLoading || !this.tank.isLoaded) return;
|
| 1466 |
|
| 1467 |
+
// λͺ
μ€ μ¬μ΄λ λ°°μ΄ μ μ
|
| 1468 |
+
const hitSounds = [
|
| 1469 |
+
'sounds/hit1.ogg',
|
| 1470 |
+
'sounds/hit2.ogg',
|
| 1471 |
+
'sounds/hit3.ogg',
|
| 1472 |
+
'sounds/hit4.ogg',
|
| 1473 |
+
'sounds/hit5.ogg',
|
| 1474 |
+
'sounds/hit6.ogg',
|
| 1475 |
+
'sounds/hit7.ogg'
|
| 1476 |
+
];
|
| 1477 |
+
|
| 1478 |
const tankPosition = this.tank.getPosition();
|
| 1479 |
// μ μ΄μκ³Ό νλ μ΄μ΄ ν±ν¬ μΆ©λ 체ν¬
|
| 1480 |
this.enemies.forEach(enemy => {
|
|
|
|
| 1483 |
enemy.bullets.forEach(bullet => {
|
| 1484 |
const distance = bullet.position.distanceTo(tankPosition);
|
| 1485 |
if (distance < 1) {
|
| 1486 |
+
// λͺ
μ€ μ¬μ΄λ μ¬μ
|
| 1487 |
+
const randomHitSound = hitSounds[Math.floor(Math.random() * hitSounds.length)];
|
| 1488 |
+
const hitAudio = new Audio(randomHitSound);
|
| 1489 |
+
hitAudio.play();
|
| 1490 |
+
|
| 1491 |
if (this.tank.takeDamage(250)) { // λ°λ―Έμ§λ₯Ό 250μΌλ‘ μμ
|
| 1492 |
this.endGame();
|
| 1493 |
}
|
|
|
|
| 1508 |
|
| 1509 |
const distance = bullet.position.distanceTo(enemy.mesh.position);
|
| 1510 |
if (distance < 2) {
|
| 1511 |
+
// λͺ
μ€ μ¬μ΄λ μ¬μ
|
| 1512 |
+
const randomHitSound = hitSounds[Math.floor(Math.random() * hitSounds.length)];
|
| 1513 |
+
const hitAudio = new Audio(randomHitSound);
|
| 1514 |
+
hitAudio.play();
|
| 1515 |
+
|
| 1516 |
if (enemy.takeDamage(50)) {
|
| 1517 |
enemy.destroy();
|
| 1518 |
this.enemies.splice(enemyIndex, 1);
|