Spaces:
Running
Running
cutechicken
commited on
Commit
โข
2609750
1
Parent(s):
a7148ee
Update game.js
Browse files
game.js
CHANGED
@@ -798,6 +798,7 @@ class Game {
|
|
798 |
|
799 |
this.setupEventListeners();
|
800 |
this.initialize();
|
|
|
801 |
}
|
802 |
|
803 |
async initialize() {
|
@@ -809,55 +810,57 @@ class Game {
|
|
809 |
startAudio.volume = 0.5;
|
810 |
startAudio.play();
|
811 |
|
812 |
-
// ๋ ๋๋ฌ ์ค์
|
813 |
this.renderer.shadowMap.enabled = true;
|
814 |
this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
815 |
this.renderer.outputEncoding = THREE.sRGBEncoding;
|
816 |
|
|
|
|
|
|
|
817 |
// ์๊ฐ ํจ๊ณผ
|
818 |
this.scene.fog = new THREE.FogExp2(0x87CEEB, 0.0008);
|
819 |
this.scene.background = new THREE.Color(0x87CEEB);
|
820 |
|
821 |
-
//
|
|
|
822 |
const ambientLight = new THREE.AmbientLight(0xffffff, 0.4);
|
823 |
this.scene.add(ambientLight);
|
824 |
|
825 |
-
// ๋ฉ์ธ ํ์๊ด
|
826 |
const mainLight = new THREE.DirectionalLight(0xffffff, 1.0);
|
827 |
mainLight.position.set(MAP_SIZE/2, MAP_SIZE/2, MAP_SIZE/2);
|
828 |
mainLight.castShadow = true;
|
829 |
|
830 |
-
// ๊ทธ๋ฆผ์
|
831 |
-
mainLight.shadow.mapSize.width = 4096;
|
832 |
mainLight.shadow.mapSize.height = 4096;
|
833 |
mainLight.shadow.camera.near = 0.5;
|
834 |
-
mainLight.shadow.camera.far = MAP_SIZE * 2;
|
835 |
-
mainLight.shadow.camera.left = -MAP_SIZE;
|
836 |
mainLight.shadow.camera.right = MAP_SIZE;
|
837 |
mainLight.shadow.camera.top = MAP_SIZE;
|
838 |
mainLight.shadow.camera.bottom = -MAP_SIZE;
|
839 |
mainLight.shadow.bias = -0.001;
|
840 |
mainLight.shadow.radius = 2;
|
841 |
-
mainLight.shadow.normalBias = 0.02;
|
842 |
|
843 |
this.scene.add(mainLight);
|
844 |
|
845 |
-
// ๋ณด์กฐ ํ์๊ด
|
846 |
const secondaryLight = new THREE.DirectionalLight(0xffffff, 0.3);
|
847 |
secondaryLight.position.set(-50, 50, -50);
|
848 |
this.scene.add(secondaryLight);
|
849 |
|
850 |
-
// ํ๊ฒฝ๊ด
|
851 |
const hemisphereLight = new THREE.HemisphereLight(
|
852 |
-
0x87CEEB,
|
853 |
-
0xFFE87C,
|
854 |
0.3
|
855 |
);
|
856 |
this.scene.add(hemisphereLight);
|
857 |
-
|
858 |
-
|
859 |
-
// ์งํ ์์ฑ ์์
|
860 |
-
const groundGeometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE);
|
861 |
const groundMaterial = new THREE.MeshStandardMaterial({
|
862 |
color: 0xD2B48C,
|
863 |
roughness: 0.8,
|
@@ -869,79 +872,78 @@ const ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
|
869 |
ground.rotation.x = -Math.PI / 2;
|
870 |
ground.receiveShadow = true;
|
871 |
|
872 |
-
//
|
873 |
const vertices = ground.geometry.attributes.position.array;
|
874 |
for (let i = 0; i < vertices.length; i += 3) {
|
875 |
-
vertices[i + 2] = 0;
|
876 |
}
|
877 |
|
878 |
ground.geometry.attributes.position.needsUpdate = true;
|
879 |
ground.geometry.computeVertexNormals();
|
880 |
this.ground = ground;
|
881 |
this.scene.add(ground);
|
882 |
-
const flatlandRadius = MAP_SIZE / 2;
|
883 |
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
// ํฑํฌ ์ด๊ธฐํ
|
895 |
-
await this.tank.initialize(this.scene, this.loader);
|
896 |
-
if (!this.tank.isLoaded) {
|
897 |
-
throw new Error('Tank loading failed');
|
898 |
-
}
|
899 |
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
{ x: spawnPos.x - 2, z: spawnPos.z },
|
906 |
-
{ x: spawnPos.x, z: spawnPos.z + 2 },
|
907 |
-
{ x: spawnPos.x, z: spawnPos.z - 2 }
|
908 |
-
];
|
909 |
-
|
910 |
-
const slopes = slopeCheckPoints.map(point => {
|
911 |
-
const pointHeight = this.getHeightAtPosition(point.x, point.z);
|
912 |
-
return Math.abs(pointHeight - heightAtSpawn) / 2;
|
913 |
-
});
|
914 |
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
920 |
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
tankPosition.z - 30
|
927 |
-
);
|
928 |
-
this.camera.lookAt(tankPosition);
|
929 |
-
|
930 |
-
// ๋ก๋ฉ ์๋ฃ
|
931 |
-
this.isLoading = false;
|
932 |
-
document.getElementById('loading').style.display = 'none';
|
933 |
-
|
934 |
-
// ๊ฒ์ ์์
|
935 |
-
this.animate();
|
936 |
-
this.spawnEnemies();
|
937 |
-
this.startGameTimer();
|
938 |
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
943 |
}
|
944 |
|
|
|
945 |
// ๋ ์ด๋ ์
๋ฐ์ดํธ ๋ฉ์๋ ์ถ๊ฐ
|
946 |
updateRadar() {
|
947 |
const currentTime = Date.now();
|
|
|
798 |
|
799 |
this.setupEventListeners();
|
800 |
this.initialize();
|
801 |
+
this.obstacles = []; // obstacles ๋ฐฐ์ด ์ถ๊ฐ
|
802 |
}
|
803 |
|
804 |
async initialize() {
|
|
|
810 |
startAudio.volume = 0.5;
|
811 |
startAudio.play();
|
812 |
|
813 |
+
// ๋ ๋๋ฌ ์ค์
|
814 |
this.renderer.shadowMap.enabled = true;
|
815 |
this.renderer.shadowMap.type = THREE.PCFSoftShadowMap;
|
816 |
this.renderer.outputEncoding = THREE.sRGBEncoding;
|
817 |
|
818 |
+
// ๊ธฐ๋ณธ ์ฌ ์ค์
|
819 |
+
this.setupScene();
|
820 |
+
|
821 |
// ์๊ฐ ํจ๊ณผ
|
822 |
this.scene.fog = new THREE.FogExp2(0x87CEEB, 0.0008);
|
823 |
this.scene.background = new THREE.Color(0x87CEEB);
|
824 |
|
825 |
+
// ์กฐ๋ช
์ค์
|
826 |
+
// ์ฃผ๋ณ๊ด
|
827 |
const ambientLight = new THREE.AmbientLight(0xffffff, 0.4);
|
828 |
this.scene.add(ambientLight);
|
829 |
|
830 |
+
// ๋ฉ์ธ ํ์๊ด
|
831 |
const mainLight = new THREE.DirectionalLight(0xffffff, 1.0);
|
832 |
mainLight.position.set(MAP_SIZE/2, MAP_SIZE/2, MAP_SIZE/2);
|
833 |
mainLight.castShadow = true;
|
834 |
|
835 |
+
// ๊ทธ๋ฆผ์ ์ค์
|
836 |
+
mainLight.shadow.mapSize.width = 4096;
|
837 |
mainLight.shadow.mapSize.height = 4096;
|
838 |
mainLight.shadow.camera.near = 0.5;
|
839 |
+
mainLight.shadow.camera.far = MAP_SIZE * 2;
|
840 |
+
mainLight.shadow.camera.left = -MAP_SIZE;
|
841 |
mainLight.shadow.camera.right = MAP_SIZE;
|
842 |
mainLight.shadow.camera.top = MAP_SIZE;
|
843 |
mainLight.shadow.camera.bottom = -MAP_SIZE;
|
844 |
mainLight.shadow.bias = -0.001;
|
845 |
mainLight.shadow.radius = 2;
|
846 |
+
mainLight.shadow.normalBias = 0.02;
|
847 |
|
848 |
this.scene.add(mainLight);
|
849 |
|
850 |
+
// ๋ณด์กฐ ํ์๊ด
|
851 |
const secondaryLight = new THREE.DirectionalLight(0xffffff, 0.3);
|
852 |
secondaryLight.position.set(-50, 50, -50);
|
853 |
this.scene.add(secondaryLight);
|
854 |
|
855 |
+
// ํ๊ฒฝ๊ด
|
856 |
const hemisphereLight = new THREE.HemisphereLight(
|
857 |
+
0x87CEEB,
|
858 |
+
0xFFE87C,
|
859 |
0.3
|
860 |
);
|
861 |
this.scene.add(hemisphereLight);
|
862 |
+
// ์งํ ์์ฑ
|
863 |
+
const groundGeometry = new THREE.PlaneGeometry(MAP_SIZE, MAP_SIZE, 100, 100);
|
|
|
|
|
864 |
const groundMaterial = new THREE.MeshStandardMaterial({
|
865 |
color: 0xD2B48C,
|
866 |
roughness: 0.8,
|
|
|
872 |
ground.rotation.x = -Math.PI / 2;
|
873 |
ground.receiveShadow = true;
|
874 |
|
875 |
+
// ์งํ ๋์ด ์ค์
|
876 |
const vertices = ground.geometry.attributes.position.array;
|
877 |
for (let i = 0; i < vertices.length; i += 3) {
|
878 |
+
vertices[i + 2] = 0; // ๋ชจ๋ ๋์ด๋ฅผ 0์ผ๋ก ์ค์
|
879 |
}
|
880 |
|
881 |
ground.geometry.attributes.position.needsUpdate = true;
|
882 |
ground.geometry.computeVertexNormals();
|
883 |
this.ground = ground;
|
884 |
this.scene.add(ground);
|
|
|
885 |
|
886 |
+
// ๊ฒฉ์ ํจ๊ณผ ์ถ๊ฐ
|
887 |
+
const gridHelper = new THREE.GridHelper(MAP_SIZE, 50, 0x000000, 0x000000);
|
888 |
+
gridHelper.material.opacity = 0.1;
|
889 |
+
gridHelper.material.transparent = true;
|
890 |
+
gridHelper.position.y = 0.1;
|
891 |
+
this.scene.add(gridHelper);
|
892 |
|
893 |
+
// ์ฌ๋ง ์ฅ์ ์ถ๊ฐ
|
894 |
+
await this.addDesertDecorations();
|
|
|
|
|
|
|
|
|
|
|
|
|
895 |
|
896 |
+
// ํฑํฌ ์ด๊ธฐํ
|
897 |
+
await this.tank.initialize(this.scene, this.loader);
|
898 |
+
if (!this.tank.isLoaded) {
|
899 |
+
throw new Error('Tank loading failed');
|
900 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
901 |
|
902 |
+
// ์คํฐ ์์น ๊ฒ์ฆ
|
903 |
+
const spawnPos = this.findValidSpawnPosition();
|
904 |
+
const heightAtSpawn = this.getHeightAtPosition(spawnPos.x, spawnPos.z);
|
905 |
+
const slopeCheckPoints = [
|
906 |
+
{ x: spawnPos.x + 2, z: spawnPos.z },
|
907 |
+
{ x: spawnPos.x - 2, z: spawnPos.z },
|
908 |
+
{ x: spawnPos.x, z: spawnPos.z + 2 },
|
909 |
+
{ x: spawnPos.x, z: spawnPos.z - 2 }
|
910 |
+
];
|
911 |
+
|
912 |
+
const slopes = slopeCheckPoints.map(point => {
|
913 |
+
const pointHeight = this.getHeightAtPosition(point.x, point.z);
|
914 |
+
return Math.abs(pointHeight - heightAtSpawn) / 2;
|
915 |
+
});
|
916 |
|
917 |
+
const maxSlope = Math.max(...slopes);
|
918 |
+
if (maxSlope > 0.3) {
|
919 |
+
location.reload();
|
920 |
+
return;
|
921 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
922 |
|
923 |
+
// ์นด๋ฉ๋ผ ์ด๊ธฐ ์ค์
|
924 |
+
const tankPosition = this.tank.getPosition();
|
925 |
+
this.camera.position.set(
|
926 |
+
tankPosition.x,
|
927 |
+
tankPosition.y + 15,
|
928 |
+
tankPosition.z - 30
|
929 |
+
);
|
930 |
+
this.camera.lookAt(tankPosition);
|
931 |
+
|
932 |
+
// ๋ก๋ฉ ์๋ฃ ์ฒ๋ฆฌ
|
933 |
+
this.isLoading = false;
|
934 |
+
document.getElementById('loading').style.display = 'none';
|
935 |
+
|
936 |
+
// ๊ฒ์ ์์
|
937 |
+
this.animate();
|
938 |
+
this.spawnEnemies();
|
939 |
+
this.startGameTimer();
|
940 |
+
|
941 |
+
} catch (error) {
|
942 |
+
console.error('Game initialization error:', error);
|
943 |
+
this.handleLoadingError();
|
944 |
}
|
945 |
|
946 |
+
|
947 |
// ๋ ์ด๋ ์
๋ฐ์ดํธ ๋ฉ์๋ ์ถ๊ฐ
|
948 |
updateRadar() {
|
949 |
const currentTime = Date.now();
|