Update game.js
Browse files
game.js
CHANGED
|
@@ -208,6 +208,13 @@ class TankPlayer {
|
|
| 208 |
// μλ‘μ΄ μμΉ κ³μ°
|
| 209 |
const newPosition = this.body.position.clone().add(moveVector);
|
| 210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
// μλ‘μ΄ μμΉμ μ§ν λμ΄ κ°μ Έμ€κΈ°
|
| 212 |
const heightAtNewPos = window.gameInstance.getHeightAtPosition(newPosition.x, newPosition.z);
|
| 213 |
|
|
@@ -217,7 +224,7 @@ class TankPlayer {
|
|
| 217 |
// κ²½μ¬κ° λ무 κ°νλ₯Έμ§ 체ν¬
|
| 218 |
const currentHeight = this.body.position.y;
|
| 219 |
const heightDifference = Math.abs(newPosition.y - currentHeight);
|
| 220 |
-
const maxClimbAngle = 0.5;
|
| 221 |
|
| 222 |
if (heightDifference / this.moveSpeed < maxClimbAngle) {
|
| 223 |
this.body.position.copy(newPosition);
|
|
@@ -371,6 +378,12 @@ class Enemy {
|
|
| 371 |
const moveVector = direction.multiplyScalar(this.moveSpeed);
|
| 372 |
const newPosition = this.mesh.position.clone().add(moveVector);
|
| 373 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
// μλ‘μ΄ μμΉμ μ§ν λμ΄ κ°μ Έμ€κΈ°
|
| 375 |
const heightAtNewPos = window.gameInstance.getHeightAtPosition(newPosition.x, newPosition.z);
|
| 376 |
newPosition.y = heightAtNewPos + TANK_HEIGHT;
|
|
@@ -411,14 +424,15 @@ class Enemy {
|
|
| 411 |
}
|
| 412 |
}
|
| 413 |
|
| 414 |
-
|
| 415 |
// μ΄μ μ
λ°μ΄νΈ λΆλΆ
|
| 416 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
| 417 |
const bullet = this.bullets[i];
|
| 418 |
bullet.position.add(bullet.velocity);
|
| 419 |
|
| 420 |
-
|
| 421 |
-
|
|
|
|
|
|
|
| 422 |
this.scene.remove(bullet);
|
| 423 |
this.bullets.splice(i, 1);
|
| 424 |
}
|
|
@@ -566,64 +580,42 @@ class Game {
|
|
| 566 |
this.scene.add(directionalLight);
|
| 567 |
|
| 568 |
// μ§ν μμ± μμ
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
// μΈλ λμ΄ κ³μ°
|
| 607 |
-
height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
|
| 608 |
-
height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
|
| 609 |
-
height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
|
| 610 |
-
|
| 611 |
-
vertices[i + 2] = height * transitionFactor;
|
| 612 |
-
}
|
| 613 |
-
// μΈλ μμ
|
| 614 |
-
else {
|
| 615 |
-
let height = 0;
|
| 616 |
-
height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
|
| 617 |
-
height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
|
| 618 |
-
height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
|
| 619 |
-
vertices[i + 2] = height;
|
| 620 |
-
}
|
| 621 |
-
}
|
| 622 |
-
|
| 623 |
-
ground.geometry.attributes.position.needsUpdate = true;
|
| 624 |
-
ground.geometry.computeVertexNormals();
|
| 625 |
-
this.ground = ground;
|
| 626 |
-
this.scene.add(ground);
|
| 627 |
|
| 628 |
// λ±κ³ μ ν¨κ³Ό (μΈλ μμμλ§ μ μ©)
|
| 629 |
const contourMaterial = new THREE.LineBasicMaterial({
|
|
|
|
| 208 |
// μλ‘μ΄ μμΉ κ³μ°
|
| 209 |
const newPosition = this.body.position.clone().add(moveVector);
|
| 210 |
|
| 211 |
+
// λ§΅ κ²½κ³ μ²΄ν¬
|
| 212 |
+
const halfMap = MAP_SIZE / 2;
|
| 213 |
+
const margin = 10; // λ§΅ κ²½κ³μμμ μ¬μ 곡κ°
|
| 214 |
+
|
| 215 |
+
newPosition.x = Math.max(-halfMap + margin, Math.min(halfMap - margin, newPosition.x));
|
| 216 |
+
newPosition.z = Math.max(-halfMap + margin, Math.min(halfMap - margin, newPosition.z));
|
| 217 |
+
|
| 218 |
// μλ‘μ΄ μμΉμ μ§ν λμ΄ κ°μ Έμ€κΈ°
|
| 219 |
const heightAtNewPos = window.gameInstance.getHeightAtPosition(newPosition.x, newPosition.z);
|
| 220 |
|
|
|
|
| 224 |
// κ²½μ¬κ° λ무 κ°νλ₯Έμ§ 체ν¬
|
| 225 |
const currentHeight = this.body.position.y;
|
| 226 |
const heightDifference = Math.abs(newPosition.y - currentHeight);
|
| 227 |
+
const maxClimbAngle = 0.5;
|
| 228 |
|
| 229 |
if (heightDifference / this.moveSpeed < maxClimbAngle) {
|
| 230 |
this.body.position.copy(newPosition);
|
|
|
|
| 378 |
const moveVector = direction.multiplyScalar(this.moveSpeed);
|
| 379 |
const newPosition = this.mesh.position.clone().add(moveVector);
|
| 380 |
|
| 381 |
+
// λ§΅ κ²½κ³ μ²΄ν¬
|
| 382 |
+
const halfMap = MAP_SIZE / 2;
|
| 383 |
+
const margin = 10;
|
| 384 |
+
newPosition.x = Math.max(-halfMap + margin, Math.min(halfMap - margin, newPosition.x));
|
| 385 |
+
newPosition.z = Math.max(-halfMap + margin, Math.min(halfMap - margin, newPosition.z));
|
| 386 |
+
|
| 387 |
// μλ‘μ΄ μμΉμ μ§ν λμ΄ κ°μ Έμ€κΈ°
|
| 388 |
const heightAtNewPos = window.gameInstance.getHeightAtPosition(newPosition.x, newPosition.z);
|
| 389 |
newPosition.y = heightAtNewPos + TANK_HEIGHT;
|
|
|
|
| 424 |
}
|
| 425 |
}
|
| 426 |
|
|
|
|
| 427 |
// μ΄μ μ
λ°μ΄νΈ λΆλΆ
|
| 428 |
for (let i = this.bullets.length - 1; i >= 0; i--) {
|
| 429 |
const bullet = this.bullets[i];
|
| 430 |
bullet.position.add(bullet.velocity);
|
| 431 |
|
| 432 |
+
// μ΄μμ΄ λ§΅ κ²½κ³λ₯Ό λ²μ΄λλ©΄ μ κ±°
|
| 433 |
+
const halfMap = MAP_SIZE / 2;
|
| 434 |
+
if (Math.abs(bullet.position.x) > halfMap ||
|
| 435 |
+
Math.abs(bullet.position.z) > halfMap) {
|
| 436 |
this.scene.remove(bullet);
|
| 437 |
this.bullets.splice(i, 1);
|
| 438 |
}
|
|
|
|
| 580 |
this.scene.add(directionalLight);
|
| 581 |
|
| 582 |
// μ§ν μμ± μμ
|
| 583 |
+
const groundGeometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE, 100, 100);
|
| 584 |
+
const groundMaterial = new THREE.MeshStandardMaterial({
|
| 585 |
+
color: 0xD2B48C, // μ¬λ§μ
|
| 586 |
+
roughness: 0.8,
|
| 587 |
+
metalness: 0.2,
|
| 588 |
+
wireframe: false
|
| 589 |
+
});
|
| 590 |
+
|
| 591 |
+
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
| 592 |
+
ground.rotation.x = -Math.PI / 2;
|
| 593 |
+
ground.receiveShadow = true;
|
| 594 |
+
|
| 595 |
+
// μ§ν λμ΄ μ€μ - νμ§μ λͺ¨λμΈλλ§ μ‘΄μ¬νλλ‘ μμ
|
| 596 |
+
const vertices = ground.geometry.attributes.position.array;
|
| 597 |
+
const heightScale = 15;
|
| 598 |
+
|
| 599 |
+
for (let i = 0; i < vertices.length; i += 3) {
|
| 600 |
+
const x = vertices[i];
|
| 601 |
+
const z = vertices[i + 1];
|
| 602 |
+
|
| 603 |
+
// λ§΅μ 4λΆν νμ¬ μΌμͺ½ μλ νμ§, λλ¨Έμ§λ λͺ¨λμΈλμΌλ‘ μ€μ
|
| 604 |
+
if (x < 0 && z > 0) {
|
| 605 |
+
// νμ§ μμ
|
| 606 |
+
vertices[i + 2] = 0;
|
| 607 |
+
} else {
|
| 608 |
+
// λͺ¨λμΈλ μμ
|
| 609 |
+
const distance = Math.sqrt(x * x + z * z);
|
| 610 |
+
const height = Math.sin(distance * 0.02) * heightScale;
|
| 611 |
+
vertices[i + 2] = Math.max(0, height); // μμ λμ΄ λ°©μ§
|
| 612 |
+
}
|
| 613 |
+
}
|
| 614 |
+
|
| 615 |
+
ground.geometry.attributes.position.needsUpdate = true;
|
| 616 |
+
ground.geometry.computeVertexNormals();
|
| 617 |
+
this.ground = ground;
|
| 618 |
+
this.scene.add(ground);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 619 |
|
| 620 |
// λ±κ³ μ ν¨κ³Ό (μΈλ μμμλ§ μ μ©)
|
| 621 |
const contourMaterial = new THREE.LineBasicMaterial({
|