Spaces:
Running
Running
cutechicken
commited on
Commit
โข
27f0f2f
1
Parent(s):
6a99267
Update game.js
Browse files
game.js
CHANGED
@@ -549,97 +549,69 @@ class Game {
|
|
549 |
|
550 |
async initialize() {
|
551 |
try {
|
552 |
-
// ์๊ฐ
|
553 |
this.scene.fog = null;
|
554 |
this.scene.background = new THREE.Color(0x87CEEB);
|
555 |
|
556 |
-
// ์ฃผ๋ณ๊ด
|
557 |
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
|
558 |
this.scene.add(ambientLight);
|
559 |
|
560 |
-
// ํ์๊ด ์ค์
|
561 |
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
|
562 |
directionalLight.position.set(100, 100, 50);
|
563 |
-
directionalLight.castShadow = true;
|
564 |
-
directionalLight.shadow.mapSize.width =
|
565 |
-
directionalLight.shadow.mapSize.height =
|
|
|
|
|
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 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;
|
604 |
const heightScale = 15; // ๋์ด ์ค์ผ์ผ
|
605 |
const baseFrequency = 0.008; // ๊ธฐ๋ณธ ์ฃผํ์
|
606 |
-
|
607 |
for (let i = 0; i < vertices.length; i += 3) {
|
608 |
const x = vertices[i];
|
609 |
-
const
|
610 |
-
|
611 |
-
// ์ฌ๋ฌ ์ฃผํ์๋ฅผ ์กฐํฉํ ์งํ ์์ฑ
|
612 |
-
let height = 0;
|
613 |
-
|
614 |
-
// ํฐ ์ธ๋ (๊ธฐ๋ณธ ์งํ)
|
615 |
-
height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
|
616 |
-
|
617 |
-
// ์ค๊ฐ ํฌ๊ธฐ ์งํ
|
618 |
-
height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
|
619 |
-
|
620 |
-
// ์์ ๊ตด๊ณก
|
621 |
-
height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
|
622 |
|
623 |
-
//
|
624 |
-
|
625 |
-
height +=
|
626 |
-
|
627 |
-
// ๋งต ๊ฐ์ฅ์๋ฆฌ๋ก ๊ฐ์๋ก ๋์ด๋ฅผ ๋ถ๋๋ฝ๊ฒ ๊ฐ์
|
628 |
-
const distanceFromCenter = Math.sqrt(x * x + y * y) / (MAP_SIZE * 0.5);
|
629 |
-
const edgeFactor = Math.pow(Math.max(0, 1 - distanceFromCenter), 2); // ๋ถ๋๋ฌ์ด ๊ฐ์
|
630 |
-
|
631 |
-
// ์ต์ข
๋์ด ์ค์
|
632 |
-
vertices[i + 2] = height * edgeFactor;
|
633 |
-
}
|
634 |
|
|
|
|
|
635 |
ground.geometry.attributes.position.needsUpdate = true;
|
636 |
ground.geometry.computeVertexNormals();
|
637 |
-
|
638 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
639 |
|
640 |
// ์ฌ๋ง ์ฅ์ ์ถ๊ฐ
|
641 |
await this.addDesertDecorations();
|
642 |
-
|
643 |
// ํฑํฌ ์ด๊ธฐํ
|
644 |
await this.tank.initialize(this.scene, this.loader);
|
645 |
if (!this.tank.isLoaded) {
|
@@ -654,11 +626,11 @@ class Game {
|
|
654 |
tankPosition.z - 30
|
655 |
);
|
656 |
this.camera.lookAt(tankPosition);
|
657 |
-
|
658 |
// ๋ก๋ฉ ์๋ฃ
|
659 |
this.isLoading = false;
|
660 |
document.getElementById('loading').style.display = 'none';
|
661 |
-
|
662 |
// ๊ฒ์ ์์
|
663 |
this.animate();
|
664 |
this.spawnEnemies();
|
|
|
549 |
|
550 |
async initialize() {
|
551 |
try {
|
552 |
+
// ๋ฐฐ๊ฒฝ ๋ฐ ์๊ฐ ์ค์
|
553 |
this.scene.fog = null;
|
554 |
this.scene.background = new THREE.Color(0x87CEEB);
|
555 |
|
556 |
+
// ์ฃผ๋ณ๊ด ์ถ๊ฐ
|
557 |
const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
|
558 |
this.scene.add(ambientLight);
|
559 |
|
560 |
+
// ํ์๊ด(์ง์ฌ๊ด) ์ถ๊ฐ ๋ฐ ๊ทธ๋ฆผ์ ์ค์
|
561 |
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
|
562 |
directionalLight.position.set(100, 100, 50);
|
563 |
+
directionalLight.castShadow = true; // ๊ทธ๋ฆผ์ ํ์ฑํ
|
564 |
+
directionalLight.shadow.mapSize.width = 2048; // ๊ทธ๋ฆผ์ ํด์๋ ์ฆ๊ฐ
|
565 |
+
directionalLight.shadow.mapSize.height = 2048;
|
566 |
+
directionalLight.shadow.camera.near = 0.5;
|
567 |
+
directionalLight.shadow.camera.far = 500;
|
568 |
this.scene.add(directionalLight);
|
569 |
|
570 |
+
// ์งํ ์์ฑ
|
571 |
const groundGeometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE, 100, 100);
|
572 |
const groundMaterial = new THREE.MeshStandardMaterial({
|
573 |
color: 0xD2B48C,
|
574 |
roughness: 0.8,
|
575 |
metalness: 0.2,
|
|
|
576 |
});
|
|
|
577 |
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
578 |
ground.rotation.x = -Math.PI / 2;
|
579 |
+
ground.receiveShadow = true; // ์งํ์ด ๊ทธ๋ฆผ์๋ฅผ ๋ฐ๋๋ก ์ค์
|
580 |
+
this.scene.add(ground);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
581 |
|
582 |
+
// ์งํ์ ๋์ด ์์ (๋
ธ์ด์ฆ ์ถ๊ฐ)
|
583 |
const vertices = ground.geometry.attributes.position.array;
|
584 |
const heightScale = 15; // ๋์ด ์ค์ผ์ผ
|
585 |
const baseFrequency = 0.008; // ๊ธฐ๋ณธ ์ฃผํ์
|
|
|
586 |
for (let i = 0; i < vertices.length; i += 3) {
|
587 |
const x = vertices[i];
|
588 |
+
const z = vertices[i + 1];
|
589 |
+
let height = Math.sin(x * baseFrequency) * Math.cos(z * baseFrequency) * heightScale;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
590 |
|
591 |
+
// ์ถ๊ฐ์ ์ธ ๊ตด๊ณก ๋ฐ ๋
ธ์ด์ฆ
|
592 |
+
height += Math.sin(x * baseFrequency * 2) * Math.cos(z * baseFrequency * 2) * (heightScale * 0.5);
|
593 |
+
height += Math.random() * heightScale * 0.1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
594 |
|
595 |
+
vertices[i + 2] = height;
|
596 |
+
}
|
597 |
ground.geometry.attributes.position.needsUpdate = true;
|
598 |
ground.geometry.computeVertexNormals();
|
599 |
+
|
600 |
+
// ์งํ ์ปจํฌ์ด ๋ผ์ธ ์์ฑ
|
601 |
+
const edgesGeometry = new THREE.EdgesGeometry(ground.geometry);
|
602 |
+
const lineMaterial = new THREE.LineBasicMaterial({
|
603 |
+
color: 0x000000,
|
604 |
+
linewidth: 1,
|
605 |
+
transparent: true,
|
606 |
+
opacity: 0.5,
|
607 |
+
});
|
608 |
+
const contourLines = new THREE.LineSegments(edgesGeometry, lineMaterial);
|
609 |
+
contourLines.rotation.x = -Math.PI / 2;
|
610 |
+
this.scene.add(contourLines);
|
611 |
|
612 |
// ์ฌ๋ง ์ฅ์ ์ถ๊ฐ
|
613 |
await this.addDesertDecorations();
|
614 |
+
|
615 |
// ํฑํฌ ์ด๊ธฐํ
|
616 |
await this.tank.initialize(this.scene, this.loader);
|
617 |
if (!this.tank.isLoaded) {
|
|
|
626 |
tankPosition.z - 30
|
627 |
);
|
628 |
this.camera.lookAt(tankPosition);
|
629 |
+
|
630 |
// ๋ก๋ฉ ์๋ฃ
|
631 |
this.isLoading = false;
|
632 |
document.getElementById('loading').style.display = 'none';
|
633 |
+
|
634 |
// ๊ฒ์ ์์
|
635 |
this.animate();
|
636 |
this.spawnEnemies();
|