cutechicken commited on
Commit
3e7d780
ยท
verified ยท
1 Parent(s): d3db2f9

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +55 -45
game.js CHANGED
@@ -577,59 +577,47 @@ class Game {
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 y = vertices[i + 1];
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;
@@ -637,6 +625,28 @@ class Game {
637
  this.ground = ground;
638
  this.scene.add(ground);
639
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
640
  // ์‚ฌ๋ง‰ ์žฅ์‹ ์ถ”๊ฐ€
641
  await this.addDesertDecorations();
642
 
 
577
  const ground = new THREE.Mesh(groundGeometry, groundMaterial);
578
  ground.rotation.x = -Math.PI / 2;
579
  ground.receiveShadow = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
580
 
581
+ // ์ง€ํ˜• ๋†’์ด ์„ค์ •
582
  const vertices = ground.geometry.attributes.position.array;
583
+ const heightScale = 15;
584
+ const baseFrequency = 0.008;
585
 
586
+ // ํ‰์ง€ ์˜์—ญ ์ •์˜
587
+ const flatlandRadius = MAP_SIZE * 0.3; // ํ‰์ง€ ์˜์—ญ์˜ ๋ฐ˜๊ฒฝ
588
+ const transitionZone = MAP_SIZE * 0.1; // ํ‰์ง€์™€ ์–ธ๋• ์‚ฌ์ด์˜ ์ „ํ™˜ ๊ตฌ์—ญ
589
+
590
  for (let i = 0; i < vertices.length; i += 3) {
591
  const x = vertices[i];
592
  const y = vertices[i + 1];
593
 
594
+ // ์ค‘์‹ฌ์ ์œผ๋กœ๋ถ€ํ„ฐ์˜ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ
595
+ const distanceFromCenter = Math.sqrt(x * x + y * y);
 
 
 
 
 
 
596
 
597
+ // ํ‰์ง€ ์˜์—ญ์ด๋ฉด ๋†’์ด๋ฅผ 0์œผ๋กœ ์„ค์ •
598
+ if (distanceFromCenter < flatlandRadius) {
599
+ vertices[i + 2] = 0;
600
+ }
601
+ // ์ „ํ™˜ ๊ตฌ์—ญ์ด๋ฉด ๋ถ€๋“œ๋Ÿฝ๊ฒŒ ๋†’์ด ์ฆ๊ฐ€
602
+ else if (distanceFromCenter < flatlandRadius + transitionZone) {
603
+ const transitionFactor = (distanceFromCenter - flatlandRadius) / transitionZone;
604
+ let height = 0;
605
+
606
+ // ์–ธ๋• ๋†’์ด ๊ณ„์‚ฐ
607
+ height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
608
+ height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
609
+ height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
610
+
611
+ vertices[i + 2] = height * transitionFactor;
612
+ }
613
+ // ์–ธ๋• ์˜์—ญ
614
+ else {
615
+ let height = 0;
616
+ height += Math.sin(x * baseFrequency) * Math.cos(y * baseFrequency) * heightScale;
617
+ height += Math.sin(x * baseFrequency * 2) * Math.cos(y * baseFrequency * 2) * (heightScale * 0.5);
618
+ height += Math.sin(x * baseFrequency * 4) * Math.cos(y * baseFrequency * 4) * (heightScale * 0.25);
619
+ vertices[i + 2] = height;
620
+ }
621
  }
622
 
623
  ground.geometry.attributes.position.needsUpdate = true;
 
625
  this.ground = ground;
626
  this.scene.add(ground);
627
 
628
+ // ๋“ฑ๊ณ ์„  ํšจ๊ณผ (์–ธ๋• ์˜์—ญ์—๋งŒ ์ ์šฉ)
629
+ const contourMaterial = new THREE.LineBasicMaterial({
630
+ color: 0x000000,
631
+ opacity: 0.15,
632
+ transparent: true
633
+ });
634
+
635
+ const contourLines = new THREE.LineSegments(
636
+ new THREE.EdgesGeometry(groundGeometry),
637
+ contourMaterial
638
+ );
639
+ contourLines.rotation.x = -Math.PI / 2;
640
+ contourLines.position.y = 0.1;
641
+ this.scene.add(contourLines);
642
+
643
+ // ๊ฒฉ์ž ํšจ๊ณผ (ํ‰์ง€ ์˜์—ญ์—๋งŒ ์ ๏ฟฝ๏ฟฝ)
644
+ const gridHelper = new THREE.GridHelper(flatlandRadius * 2, 50, 0x000000, 0x000000);
645
+ gridHelper.material.opacity = 0.1;
646
+ gridHelper.material.transparent = true;
647
+ gridHelper.position.y = 0.1;
648
+ this.scene.add(gridHelper);
649
+
650
  // ์‚ฌ๋ง‰ ์žฅ์‹ ์ถ”๊ฐ€
651
  await this.addDesertDecorations();
652