cutechicken commited on
Commit
4fa4927
โ€ข
1 Parent(s): e40e2dd

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +26 -1
game.js CHANGED
@@ -325,7 +325,7 @@ class Game {
325
  this.setupEventListeners();
326
  this.initialize();
327
  }
328
-
329
  async initialize() {
330
  try {
331
  // ์•ˆ๊ฐœ ํšจ๊ณผ ์ œ๊ฑฐ
@@ -397,6 +397,31 @@ class Game {
397
  }
398
  }
399
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
  // ์‚ฌ๋ง‰ ์žฅ์‹๋ฌผ ์ถ”๊ฐ€ ๋ฉ”์†Œ๋“œ
401
  async addDesertDecorations() {
402
  // ๋ฐ”์œ„ ์ƒ์„ฑ
 
325
  this.setupEventListeners();
326
  this.initialize();
327
  }
328
+
329
  async initialize() {
330
  try {
331
  // ์•ˆ๊ฐœ ํšจ๊ณผ ์ œ๊ฑฐ
 
397
  }
398
  }
399
 
400
+ getTerrainHeightAt(x, z) {
401
+ const groundSize = MAP_SIZE;
402
+ const halfSize = groundSize / 2;
403
+
404
+ // ์ขŒํ‘œ๊ฐ€ ์ง€ํ˜• ๊ฒฝ๊ณ„๋ฅผ ๋„˜์–ด๊ฐ€๋ฉด ๊ธฐ๋ณธ ๋†’์ด ๋ฐ˜ํ™˜
405
+ if (x < -halfSize || x > halfSize || z < -halfSize || z > halfSize) {
406
+ return 0;
407
+ }
408
+
409
+ // ์ง€ํ˜• ๋†’์ด ๋ฐ์ดํ„ฐ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์„ ํ˜• ๋ณด๊ฐ„๋ฒ•์„ ์‚ฌ์šฉํ•ด ๋†’์ด ๊ณ„์‚ฐ
410
+ let closestPoint = { distance: Infinity, height: 0 };
411
+ this.terrainHeightData.forEach(point => {
412
+ const dx = x - point.x;
413
+ const dz = z - point.z;
414
+ const distance = Math.sqrt(dx * dx + dz * dz);
415
+
416
+ if (distance < closestPoint.distance) {
417
+ closestPoint = { distance, height: point.y };
418
+ }
419
+ });
420
+
421
+ return closestPoint.height;
422
+ }
423
+
424
+
425
  // ์‚ฌ๋ง‰ ์žฅ์‹๋ฌผ ์ถ”๊ฐ€ ๋ฉ”์†Œ๋“œ
426
  async addDesertDecorations() {
427
  // ๋ฐ”์œ„ ์ƒ์„ฑ