Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
|
@@ -74,6 +74,48 @@ class TankPlayer {
|
|
| 74 |
this.body.position.copy(this.position);
|
| 75 |
}
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
scene.add(this.body);
|
| 78 |
this.isLoaded = true;
|
| 79 |
this.updateAmmoDisplay();
|
|
@@ -125,25 +167,36 @@ class TankPlayer {
|
|
| 125 |
}
|
| 126 |
|
| 127 |
update(mouseX, mouseY, scene) {
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
}
|
| 146 |
}
|
|
|
|
| 147 |
|
| 148 |
move(direction) {
|
| 149 |
if (!this.body) return;
|
|
@@ -517,11 +570,34 @@ class Game {
|
|
| 517 |
const groundMaterial = new THREE.MeshStandardMaterial({
|
| 518 |
color: 0xD2B48C,
|
| 519 |
roughness: 0.8,
|
| 520 |
-
metalness: 0.2
|
|
|
|
| 521 |
});
|
|
|
|
| 522 |
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
| 523 |
ground.rotation.x = -Math.PI / 2;
|
| 524 |
ground.receiveShadow = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
|
| 526 |
// ๋ ๋ค์ํ ์งํ ์์ฑ
|
| 527 |
const vertices = ground.geometry.attributes.position.array;
|
|
@@ -1051,14 +1127,24 @@ class Game {
|
|
| 1051 |
return null;
|
| 1052 |
}
|
| 1053 |
updateParticles() {
|
| 1054 |
-
|
| 1055 |
-
|
| 1056 |
-
|
| 1057 |
-
|
| 1058 |
-
|
| 1059 |
-
|
| 1060 |
-
|
| 1061 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1062 |
|
| 1063 |
createExplosion(position) {
|
| 1064 |
for (let i = 0; i < PARTICLE_COUNT; i++) {
|
|
|
|
| 74 |
this.body.position.copy(this.position);
|
| 75 |
}
|
| 76 |
|
| 77 |
+
// ํญ๋ฐ ์ดํํธ ๋ฉ์๋ ์ถ๊ฐ
|
| 78 |
+
this.createExplosionEffect = (scene, position) => {
|
| 79 |
+
// ํญ๋ฐ ํํฐํด
|
| 80 |
+
for (let i = 0; i < 15; i++) {
|
| 81 |
+
const size = Math.random() * 0.2 + 0.1;
|
| 82 |
+
const geometry = new THREE.SphereGeometry(size);
|
| 83 |
+
const material = new THREE.MeshBasicMaterial({
|
| 84 |
+
color: Math.random() < 0.5 ? 0xff4500 : 0xff8c00
|
| 85 |
+
});
|
| 86 |
+
const particle = new THREE.Mesh(geometry, material);
|
| 87 |
+
particle.position.copy(position);
|
| 88 |
+
|
| 89 |
+
const speed = Math.random() * 0.3 + 0.2;
|
| 90 |
+
const angle = Math.random() * Math.PI * 2;
|
| 91 |
+
const elevation = Math.random() * Math.PI - Math.PI / 2;
|
| 92 |
+
|
| 93 |
+
particle.velocity = new THREE.Vector3(
|
| 94 |
+
Math.cos(angle) * Math.cos(elevation) * speed,
|
| 95 |
+
Math.sin(elevation) * speed,
|
| 96 |
+
Math.sin(angle) * Math.cos(elevation) * speed
|
| 97 |
+
);
|
| 98 |
+
|
| 99 |
+
particle.gravity = -0.01;
|
| 100 |
+
particle.life = Math.random() * 20 + 20;
|
| 101 |
+
particle.fadeRate = 1 / particle.life;
|
| 102 |
+
|
| 103 |
+
scene.add(particle);
|
| 104 |
+
window.gameInstance.particles.push({
|
| 105 |
+
mesh: particle,
|
| 106 |
+
velocity: particle.velocity,
|
| 107 |
+
gravity: particle.gravity,
|
| 108 |
+
life: particle.life,
|
| 109 |
+
fadeRate: particle.fadeRate
|
| 110 |
+
});
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// ์ถฉ๋ ์ฌ์ด๋ ์ฌ์
|
| 114 |
+
const explosionSound = new Audio('sounds/explosion.ogg');
|
| 115 |
+
explosionSound.volume = 0.3;
|
| 116 |
+
explosionSound.play();
|
| 117 |
+
};
|
| 118 |
+
|
| 119 |
scene.add(this.body);
|
| 120 |
this.isLoaded = true;
|
| 121 |
this.updateAmmoDisplay();
|
|
|
|
| 167 |
}
|
| 168 |
|
| 169 |
update(mouseX, mouseY, scene) {
|
| 170 |
+
if (!this.body || !this.turretGroup) return;
|
| 171 |
+
|
| 172 |
+
const absoluteTurretRotation = mouseX;
|
| 173 |
+
this.turretGroup.rotation.y = absoluteTurretRotation - this.body.rotation.y;
|
| 174 |
+
this.turretRotation = absoluteTurretRotation;
|
| 175 |
+
|
| 176 |
+
// ์ด์ ์
๋ฐ์ดํธ ๋ฐ ์ถฉ๋ ์ฒดํฌ
|
| 177 |
+
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
| 178 |
+
const bullet = this.bullets[i];
|
| 179 |
+
const oldPosition = bullet.position.clone();
|
| 180 |
+
bullet.position.add(bullet.velocity);
|
| 181 |
+
|
| 182 |
+
// ์งํ ๋์ด ์ฒดํฌ
|
| 183 |
+
const terrainHeight = window.gameInstance.getHeightAtPosition(
|
| 184 |
+
bullet.position.x,
|
| 185 |
+
bullet.position.z
|
| 186 |
+
);
|
| 187 |
+
|
| 188 |
+
if (bullet.position.y < terrainHeight ||
|
| 189 |
+
Math.abs(bullet.position.x) > MAP_SIZE / 2 ||
|
| 190 |
+
Math.abs(bullet.position.z) > MAP_SIZE / 2) {
|
| 191 |
+
|
| 192 |
+
// ํญ๋ฐ ์ดํํธ ์์ฑ
|
| 193 |
+
this.createExplosionEffect(scene, bullet.position);
|
| 194 |
+
|
| 195 |
+
scene.remove(bullet);
|
| 196 |
+
this.bullets.splice(i, 1);
|
| 197 |
}
|
| 198 |
}
|
| 199 |
+
}
|
| 200 |
|
| 201 |
move(direction) {
|
| 202 |
if (!this.body) return;
|
|
|
|
| 570 |
const groundMaterial = new THREE.MeshStandardMaterial({
|
| 571 |
color: 0xD2B48C,
|
| 572 |
roughness: 0.8,
|
| 573 |
+
metalness: 0.2,
|
| 574 |
+
wireframe: false
|
| 575 |
});
|
| 576 |
+
|
| 577 |
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
| 578 |
ground.rotation.x = -Math.PI / 2;
|
| 579 |
ground.receiveShadow = true;
|
| 580 |
+
|
| 581 |
+
// ๊ฒฉ์ ํจ๊ณผ๋ฅผ ์ํ ๋ผ์ธ ์ถ๊ฐ
|
| 582 |
+
const gridSize = 50; // ๊ฒฉ์ ํฌ๊ธฐ
|
| 583 |
+
const gridHelper = new THREE.GridHelper(MAP_SIZE, gridSize, 0x000000, 0x000000);
|
| 584 |
+
gridHelper.material.opacity = 0.1;
|
| 585 |
+
gridHelper.material.transparent = true;
|
| 586 |
+
gridHelper.position.y = 0.1; // ์ง๋ฉด๋ณด๋ค ์ฝ๊ฐ ์์ ๋ฐฐ์น
|
| 587 |
+
this.scene.add(gridHelper);
|
| 588 |
+
|
| 589 |
+
// ๋ฑ๊ณ ์ ํจ๊ณผ๋ฅผ ์ํ ์งํ ์ปจํฌ์ด
|
| 590 |
+
const contourLines = new THREE.LineSegments(
|
| 591 |
+
new THREE.EdgesGeometry(groundGeometry),
|
| 592 |
+
new THREE.LineBasicMaterial({
|
| 593 |
+
color: 0x000000,
|
| 594 |
+
opacity: 0.15,
|
| 595 |
+
transparent: true
|
| 596 |
+
})
|
| 597 |
+
);
|
| 598 |
+
contourLines.rotation.x = -Math.PI / 2;
|
| 599 |
+
contourLines.position.y = 0.1;
|
| 600 |
+
this.scene.add(contourLines);
|
| 601 |
|
| 602 |
// ๋ ๋ค์ํ ์งํ ์์ฑ
|
| 603 |
const vertices = ground.geometry.attributes.position.array;
|
|
|
|
| 1127 |
return null;
|
| 1128 |
}
|
| 1129 |
updateParticles() {
|
| 1130 |
+
for (let i = this.particles.length - 1; i >= 0; i--) {
|
| 1131 |
+
const particle = this.particles[i];
|
| 1132 |
+
|
| 1133 |
+
// ์ค๋ ฅ ์ ์ฉ
|
| 1134 |
+
particle.velocity.y += particle.gravity;
|
| 1135 |
+
particle.mesh.position.add(particle.velocity);
|
| 1136 |
+
|
| 1137 |
+
// ํฌ๋ช
๋ ๊ฐ์
|
| 1138 |
+
particle.mesh.material.opacity -= particle.fadeRate;
|
| 1139 |
+
particle.life--;
|
| 1140 |
+
|
| 1141 |
+
// ํํฐํด ์ ๊ฑฐ
|
| 1142 |
+
if (particle.life <= 0 || particle.mesh.material.opacity <= 0) {
|
| 1143 |
+
this.scene.remove(particle.mesh);
|
| 1144 |
+
this.particles.splice(i, 1);
|
| 1145 |
+
}
|
| 1146 |
+
}
|
| 1147 |
+
}
|
| 1148 |
|
| 1149 |
createExplosion(position) {
|
| 1150 |
for (let i = 0; i < PARTICLE_COUNT; i++) {
|