Spaces:
Running
Running
cutechicken
commited on
Commit
โข
8df69f6
1
Parent(s):
03060e2
Update game.js
Browse files
game.js
CHANGED
@@ -547,7 +547,7 @@ class Game {
|
|
547 |
this.initialize();
|
548 |
}
|
549 |
|
550 |
-
|
551 |
try {
|
552 |
// ์๊ฐ ํจ๊ณผ ์ ๊ฑฐ
|
553 |
this.scene.fog = null;
|
@@ -565,81 +565,60 @@ class Game {
|
|
565 |
directionalLight.shadow.mapSize.height = 1024;
|
566 |
this.scene.add(directionalLight);
|
567 |
|
568 |
-
//
|
569 |
-
const
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
575 |
});
|
576 |
-
|
577 |
-
|
|
|
|
|
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 |
-
const noise = (Math.random() - 0.5) * heightScale * 0.1;
|
625 |
-
height += noise;
|
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 |
this.scene.add(ground);
|
639 |
|
640 |
// ์ฌ๋ง ์ฅ์ ๏ฟฝ๏ฟฝ๊ฐ
|
641 |
await this.addDesertDecorations();
|
642 |
-
|
643 |
// ํฑํฌ ์ด๊ธฐํ
|
644 |
await this.tank.initialize(this.scene, this.loader);
|
645 |
if (!this.tank.isLoaded) {
|
@@ -654,22 +633,22 @@ 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();
|
665 |
this.startGameTimer();
|
666 |
-
|
667 |
} catch (error) {
|
668 |
console.error('Game initialization error:', error);
|
669 |
this.handleLoadingError();
|
670 |
}
|
671 |
}
|
672 |
|
|
|
673 |
// ๋ ์ด๋ ์
๋ฐ์ดํธ ๋ฉ์๋ ์ถ๊ฐ
|
674 |
updateRadar() {
|
675 |
const currentTime = Date.now();
|
|
|
547 |
this.initialize();
|
548 |
}
|
549 |
|
550 |
+
async initialize() {
|
551 |
try {
|
552 |
// ์๊ฐ ํจ๊ณผ ์ ๊ฑฐ
|
553 |
this.scene.fog = null;
|
|
|
565 |
directionalLight.shadow.mapSize.height = 1024;
|
566 |
this.scene.add(directionalLight);
|
567 |
|
568 |
+
// ShaderMaterial ์ ์
|
569 |
+
const terrainShader = new THREE.ShaderMaterial({
|
570 |
+
uniforms: {
|
571 |
+
uHeightScale: { value: 15 }, // ๋์ด ์ค์ผ์ผ
|
572 |
+
uColor: { value: new THREE.Color(0xD2B48C) }, // ๊ธฐ๋ณธ ์์
|
573 |
+
uLineColor: { value: new THREE.Color(0x000000) }, // ์ ์์
|
574 |
+
uLineFrequency: { value: 5.0 }, // ์ ๊ฐ๊ฒฉ
|
575 |
+
},
|
576 |
+
vertexShader: `
|
577 |
+
varying float vHeight;
|
578 |
+
void main() {
|
579 |
+
vHeight = position.z; // ๋์ด ๊ฐ ์ ๋ฌ
|
580 |
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
581 |
+
}
|
582 |
+
`,
|
583 |
+
fragmentShader: `
|
584 |
+
uniform float uHeightScale;
|
585 |
+
uniform vec3 uColor;
|
586 |
+
uniform vec3 uLineColor;
|
587 |
+
uniform float uLineFrequency;
|
588 |
+
varying float vHeight;
|
589 |
+
void main() {
|
590 |
+
// ๋ฑ๊ณ ์ ๊ณ์ฐ
|
591 |
+
float line = mod(vHeight * uLineFrequency / uHeightScale, 1.0);
|
592 |
+
vec3 color = mix(uLineColor, uColor, step(0.1, line)); // ์ ์์๊ณผ ๊ธฐ๋ณธ ์์ ํผํฉ
|
593 |
+
gl_FragColor = vec4(color, 1.0);
|
594 |
+
}
|
595 |
+
`,
|
596 |
});
|
597 |
+
|
598 |
+
// ์งํ ์์ฑ
|
599 |
+
const groundGeometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE, 100, 100);
|
600 |
+
const ground = new THREE.Mesh(groundGeometry, terrainShader);
|
601 |
ground.rotation.x = -Math.PI / 2;
|
602 |
ground.receiveShadow = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
603 |
|
604 |
+
// ์งํ ๋์ด ์ค์
|
605 |
const vertices = ground.geometry.attributes.position.array;
|
606 |
const heightScale = 15; // ๋์ด ์ค์ผ์ผ
|
607 |
const baseFrequency = 0.008; // ๊ธฐ๋ณธ ์ฃผํ์
|
|
|
608 |
for (let i = 0; i < vertices.length; i += 3) {
|
609 |
const x = vertices[i];
|
610 |
+
const z = vertices[i + 1];
|
611 |
+
const height = Math.sin(x * baseFrequency) * Math.cos(z * baseFrequency) * heightScale;
|
612 |
+
vertices[i + 2] = height;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
613 |
}
|
|
|
614 |
ground.geometry.attributes.position.needsUpdate = true;
|
615 |
ground.geometry.computeVertexNormals();
|
616 |
+
|
617 |
this.scene.add(ground);
|
618 |
|
619 |
// ์ฌ๋ง ์ฅ์ ๏ฟฝ๏ฟฝ๊ฐ
|
620 |
await this.addDesertDecorations();
|
621 |
+
|
622 |
// ํฑํฌ ์ด๊ธฐํ
|
623 |
await this.tank.initialize(this.scene, this.loader);
|
624 |
if (!this.tank.isLoaded) {
|
|
|
633 |
tankPosition.z - 30
|
634 |
);
|
635 |
this.camera.lookAt(tankPosition);
|
636 |
+
|
637 |
// ๋ก๋ฉ ์๋ฃ
|
638 |
this.isLoading = false;
|
639 |
document.getElementById('loading').style.display = 'none';
|
640 |
+
|
641 |
// ๊ฒ์ ์์
|
642 |
this.animate();
|
643 |
this.spawnEnemies();
|
644 |
this.startGameTimer();
|
|
|
645 |
} catch (error) {
|
646 |
console.error('Game initialization error:', error);
|
647 |
this.handleLoadingError();
|
648 |
}
|
649 |
}
|
650 |
|
651 |
+
|
652 |
// ๋ ์ด๋ ์
๋ฐ์ดํธ ๋ฉ์๋ ์ถ๊ฐ
|
653 |
updateRadar() {
|
654 |
const currentTime = Date.now();
|