Spaces:
Running
Running
cutechicken
commited on
Commit
โข
4fa4927
1
Parent(s):
e40e2dd
Update game.js
Browse files
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 |
// ๋ฐ์ ์์ฑ
|