cutechicken commited on
Commit
2ce947b
โ€ข
1 Parent(s): 8df69f6

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +58 -37
game.js CHANGED
@@ -565,43 +565,18 @@ class Game {
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; // ๊ธฐ๋ณธ ์ฃผํŒŒ์ˆ˜
@@ -613,12 +588,57 @@ class Game {
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,15 +653,16 @@ class Game {
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();
 
565
  directionalLight.shadow.mapSize.height = 1024;
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
+ });
575
+ const ground = new THREE.Mesh(groundGeometry, groundMaterial);
576
  ground.rotation.x = -Math.PI / 2;
577
  ground.receiveShadow = true;
578
+
579
+ // ์ง€ํ˜• ๋†’์ด ์„ค์ • (๊ธฐ์กด ์ง€ํ˜• ์ˆ˜์ • ์ฝ”๋“œ ํฌํ•จ)
580
  const vertices = ground.geometry.attributes.position.array;
581
  const heightScale = 15; // ๋†’์ด ์Šค์ผ€์ผ
582
  const baseFrequency = 0.008; // ๊ธฐ๋ณธ ์ฃผํŒŒ์ˆ˜
 
588
  }
589
  ground.geometry.attributes.position.needsUpdate = true;
590
  ground.geometry.computeVertexNormals();
591
+
592
+ // EdgesGeometry๋กœ ์„  ์ถ”๊ฐ€
593
+ const edgesGeometry = new THREE.EdgesGeometry(ground.geometry);
594
+ const lineMaterial = new THREE.LineBasicMaterial({ color: 0x000000, linewidth: 1 });
595
+ const contourLines = new THREE.LineSegments(edgesGeometry, lineMaterial);
596
+
597
+ // ์ง€ํ˜• ๋ฐ ์„  ์ถ”๊ฐ€
598
+ this.scene.add(ground);
599
+ this.scene.add(contourLines);
600
+
601
+ // ๋” ๋‹ค์–‘ํ•œ ์ง€ํ˜• ์ƒ์„ฑ
602
+ const vertices = ground.geometry.attributes.position.array;
603
+ const heightScale = 15; // ๋†’์ด ์Šค์ผ€์ผ
604
+ const baseFrequency = 0.008; // ๊ธฐ๋ณธ ์ฃผํŒŒ์ˆ˜
605
+
606
+ for (let i = 0; i < vertices.length; i += 3) {
607
+ const x = vertices[i];
608
+ const y = vertices[i + 1];
609
+
610
+ // ์—ฌ๋Ÿฌ ์ฃผํŒŒ์ˆ˜๋ฅผ ์กฐํ•ฉํ•œ ์ง€ํ˜• ์ƒ์„ฑ
611
+ let height = 0;
612
+
613
+ // ํฐ ์–ธ๋• (๊ธฐ๋ณธ ์ง€ํ˜•)
614
+ height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
615
+
616
+ // ์ค‘๊ฐ„ ํฌ๊ธฐ ์ง€ํ˜•
617
+ height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
618
+
619
+ // ์ž‘์€ ๊ตด๊ณก
620
+ height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
621
 
622
+ // ๋žœ๋ค ๋…ธ์ด์ฆˆ ์ถ”๊ฐ€ (์•„์ฃผ ์ž‘์€ ๊ตด๊ณก)
623
+ const noise = (Math.random() - 0.5) * heightScale * 0.1;
624
+ height += noise;
625
+
626
+ // ๋งต ๊ฐ€์žฅ์ž๋ฆฌ๋กœ ๊ฐˆ์ˆ˜๋ก ๋†’์ด๋ฅผ ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ๊ฐ์†Œ
627
+ const distanceFromCenter = Math.sqrt(x * x + y * y) / (MAP_SIZE * 0.5);
628
+ const edgeFactor = Math.pow(Math.max(0, 1 - distanceFromCenter), 2); // ๋ถ€๋“œ๋Ÿฌ์šด ๊ฐ์‡ 
629
+
630
+ // ์ตœ์ข… ๋†’์ด ์„ค์ •
631
+ vertices[i + 2] = height * edgeFactor;
632
+ }
633
+
634
+ ground.geometry.attributes.position.needsUpdate = true;
635
+ ground.geometry.computeVertexNormals();
636
+ this.ground = ground;
637
  this.scene.add(ground);
638
 
639
  // ์‚ฌ๋ง‰ ์žฅ์‹ ์ถ”๊ฐ€
640
  await this.addDesertDecorations();
641
+
642
  // ํƒฑํฌ ์ดˆ๊ธฐํ™”
643
  await this.tank.initialize(this.scene, this.loader);
644
  if (!this.tank.isLoaded) {
 
653
  tankPosition.z - 30
654
  );
655
  this.camera.lookAt(tankPosition);
656
+
657
  // ๋กœ๋”ฉ ์™„๋ฃŒ
658
  this.isLoading = false;
659
  document.getElementById('loading').style.display = 'none';
660
+
661
  // ๊ฒŒ์ž„ ์‹œ์ž‘
662
  this.animate();
663
  this.spawnEnemies();
664
  this.startGameTimer();
665
+
666
  } catch (error) {
667
  console.error('Game initialization error:', error);
668
  this.handleLoadingError();