cutechicken commited on
Commit
2609750
โ€ข
1 Parent(s): a7148ee

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +75 -73
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
- // ๋ชจ๋“  ์ •์ ์˜ ๋†’์ด๋ฅผ 0์œผ๋กœ ์„ค์ •
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
- const gridHelper = new THREE.GridHelper(flatlandRadius * 2, 50, 0x000000, 0x000000);
886
- gridHelper.material.opacity = 0.1;
887
- gridHelper.material.transparent = true;
888
- gridHelper.position.y = 0.1;
889
- this.scene.add(gridHelper);
890
 
891
- // ์‚ฌ๋ง‰ ์žฅ์‹ ์ถ”๊ฐ€
892
- await this.addDesertDecorations();
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
- const spawnPos = this.findValidSpawnPosition();
902
- const heightAtSpawn = this.getHeightAtPosition(spawnPos.x, spawnPos.z);
903
- const slopeCheckPoints = [
904
- { x: spawnPos.x + 2, z: spawnPos.z },
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
- const maxSlope = Math.max(...slopes);
916
- if (maxSlope > 0.3) {
917
- location.reload();
918
- return;
919
- }
 
 
 
 
 
 
 
 
 
920
 
921
- // ์นด๋ฉ”๋ผ ์ดˆ๊ธฐ ์œ„์น˜ ์„ค์ •
922
- const tankPosition = this.tank.getPosition();
923
- this.camera.position.set(
924
- tankPosition.x,
925
- tankPosition.y + 15,
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
- } catch (error) {
940
- console.error('Game initialization error:', error);
941
- this.handleLoadingError();
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();