Spaces:
Running
Running
cutechicken
commited on
Commit
β’
7fea2cd
1
Parent(s):
36d3f59
Update game.js
Browse files
game.js
CHANGED
@@ -208,13 +208,6 @@ class TankPlayer {
|
|
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,7 +217,7 @@ class TankPlayer {
|
|
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,12 +371,6 @@ class Enemy {
|
|
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,15 +411,14 @@ class Enemy {
|
|
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 |
-
|
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,42 +566,64 @@ class Game {
|
|
580 |
this.scene.add(directionalLight);
|
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 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
619 |
|
620 |
// λ±κ³ μ ν¨κ³Ό (μΈλ μμμλ§ μ μ©)
|
621 |
const contourMaterial = new THREE.LineBasicMaterial({
|
|
|
208 |
// μλ‘μ΄ μμΉ κ³μ°
|
209 |
const newPosition = this.body.position.clone().add(moveVector);
|
210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
// μλ‘μ΄ μμΉμ μ§ν λμ΄ κ°μ Έμ€κΈ°
|
212 |
const heightAtNewPos = window.gameInstance.getHeightAtPosition(newPosition.x, newPosition.z);
|
213 |
|
|
|
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 |
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 |
}
|
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 |
+
if (Math.abs(bullet.position.x) > MAP_SIZE ||
|
421 |
+
Math.abs(bullet.position.z) > MAP_SIZE) {
|
|
|
|
|
422 |
this.scene.remove(bullet);
|
423 |
this.bullets.splice(i, 1);
|
424 |
}
|
|
|
566 |
this.scene.add(directionalLight);
|
567 |
|
568 |
// μ§ν μμ± μμ
|
569 |
+
const groundGeometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE, 100, 100);
|
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 vertices = ground.geometry.attributes.position.array;
|
583 |
+
const heightScale = 15;
|
584 |
+
const baseFrequency = 0.008;
|
585 |
+
|
586 |
+
// νμ§ μμ μ μ
|
587 |
+
const flatlandRadius = MAP_SIZE * 0.3; // νμ§ μμμ λ°κ²½
|
588 |
+
const transitionZone = MAP_SIZE * 0.1; // νμ§μ μΈλ μ¬μ΄μ μ ν ꡬμ
|
589 |
+
|
590 |
+
for (let i = 0; i < vertices.length; i += 3) {
|
591 |
+
const x = vertices[i];
|
592 |
+
const y = vertices[i + 1];
|
593 |
+
|
594 |
+
// μ€μ¬μ μΌλ‘λΆν°μ 거리 κ³μ°
|
595 |
+
const distanceFromCenter = Math.sqrt(x * x + y * y);
|
596 |
+
|
597 |
+
// νμ§ μμμ΄λ©΄ λμ΄λ₯Ό 0μΌλ‘ μ€μ
|
598 |
+
if (distanceFromCenter < flatlandRadius) {
|
599 |
+
vertices[i + 2] = 0;
|
600 |
+
}
|
601 |
+
// μ ν ꡬμμ΄λ©΄ λΆλλ½κ² λμ΄ μ¦κ°
|
602 |
+
else if (distanceFromCenter < flatlandRadius + transitionZone) {
|
603 |
+
const transitionFactor = (distanceFromCenter - flatlandRadius) / transitionZone;
|
604 |
+
let height = 0;
|
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({
|