cutechicken commited on
Commit
5da2c82
โ€ข
1 Parent(s): 6aab0c5

Update game.js

Browse files
Files changed (1) hide show
  1. game.js +44 -19
game.js CHANGED
@@ -1133,9 +1133,10 @@ class Game {
1133
  if (!this.obstacles) {
1134
  this.obstacles = []; // ๋ฐฐ์—ด์ด ์—†์œผ๋ฉด ์ดˆ๊ธฐํ™”
1135
  }
 
 
1136
 
1137
- // ๋ฐ”์œ„ ์ƒ์„ฑ
1138
- // ๋ฐ”์œ„ ์ƒ์„ฑ
1139
  const rockGeometries = [
1140
  new THREE.DodecahedronGeometry(3),
1141
  new THREE.DodecahedronGeometry(2),
@@ -1148,23 +1149,37 @@ class Game {
1148
  metalness: 0.1
1149
  });
1150
 
1151
- // ๋ฐ”์œ„์šฉ ์ถฉ๋Œ ๋ฐ•์Šค๋ฅผ ์‹œ๊ฐํ™”ํ•˜๋Š” ์žฌ์งˆ (๋””๋ฒ„๊น…์šฉ)
1152
  const collisionBoxMaterial = new THREE.MeshBasicMaterial({
1153
  color: 0xff0000,
1154
  wireframe: true,
1155
  visible: false // ํ•„์š”์‹œ true๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ์ถฉ๋Œ ๋ฐ•์Šค ํ™•์ธ
1156
  });
1157
 
1158
- for (let i = 0; i < 100; i++) {
1159
  const rockGeometry = rockGeometries[Math.floor(Math.random() * rockGeometries.length)];
1160
  const rock = new THREE.Mesh(rockGeometry, rockMaterial);
1161
 
1162
- // ๋ฐ”์œ„ ์œ„์น˜ ์„ค์ •
1163
- rock.position.set(
1164
- (Math.random() - 0.5) * MAP_SIZE * 0.9,
1165
- Math.random() * 2,
1166
- (Math.random() - 0.5) * MAP_SIZE * 0.9
1167
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1168
 
1169
  rock.rotation.set(
1170
  Math.random() * Math.PI,
@@ -1172,11 +1187,9 @@ class Game {
1172
  Math.random() * Math.PI
1173
  );
1174
 
1175
- rock.scale.set(
1176
- 1 + Math.random() * 0.5,
1177
- 1 + Math.random() * 0.5,
1178
- 1 + Math.random() * 0.5
1179
- );
1180
 
1181
  // ์ถฉ๋Œ ๋ฐ•์Šค ์ƒ์„ฑ ๋ฐ ์„ค์ •
1182
  const boundingBox = new THREE.Box3().setFromObject(rock);
@@ -1187,7 +1200,7 @@ class Game {
1187
  collisionMesh.position.copy(rock.position);
1188
  collisionMesh.rotation.copy(rock.rotation);
1189
 
1190
- // ๋ฐ”์œ„์— ์ถฉ๋Œ ์†์„ฑ ์ถ”๊ฐ€
1191
  rock.userData.isCollidable = true;
1192
  rock.userData.type = 'rock';
1193
  rock.userData.collisionMesh = collisionMesh;
@@ -1195,9 +1208,21 @@ class Game {
1195
  rock.castShadow = true;
1196
  rock.receiveShadow = true;
1197
 
1198
- this.obstacles.push(rock);
1199
- this.scene.add(rock);
1200
- this.scene.add(collisionMesh); // ๋””๋ฒ„๊น…์šฉ ์ถฉ๋Œ ๋ฐ•์Šค
 
 
 
 
 
 
 
 
 
 
 
 
1201
  }
1202
 
1203
  // ์„ ์ธ์žฅ ์ถ”๊ฐ€
 
1133
  if (!this.obstacles) {
1134
  this.obstacles = []; // ๋ฐฐ์—ด์ด ์—†์œผ๋ฉด ์ดˆ๊ธฐํ™”
1135
  }
1136
+ // ๋ฐ”์œ„ ์ƒ์„ฑ ๊ฐœ์ˆ˜๋ฅผ 70๊ฐœ๋กœ ์ค„์ž„
1137
+ const ROCK_COUNT = 70;
1138
 
1139
+ // ๋ฐ”์œ„ ์ง€์˜ค๋ฉ”ํŠธ๋ฆฌ ์ •์˜
 
1140
  const rockGeometries = [
1141
  new THREE.DodecahedronGeometry(3),
1142
  new THREE.DodecahedronGeometry(2),
 
1149
  metalness: 0.1
1150
  });
1151
 
1152
+ // ์ถฉ๋Œ ๋ฐ•์Šค ์‹œ๊ฐํ™”์šฉ ์žฌ์งˆ (๋””๋ฒ„๊น…์šฉ)
1153
  const collisionBoxMaterial = new THREE.MeshBasicMaterial({
1154
  color: 0xff0000,
1155
  wireframe: true,
1156
  visible: false // ํ•„์š”์‹œ true๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ์ถฉ๋Œ ๋ฐ•์Šค ํ™•์ธ
1157
  });
1158
 
1159
+ for (let i = 0; i < ROCK_COUNT; i++) {
1160
  const rockGeometry = rockGeometries[Math.floor(Math.random() * rockGeometries.length)];
1161
  const rock = new THREE.Mesh(rockGeometry, rockMaterial);
1162
 
1163
+ // ๋ฐ”์œ„ ์œ„์น˜ ์„ค์ • - ๋งต ๊ฐ€์žฅ์ž๋ฆฌ์— ๋” ๋งŽ์ด ๋ฐฐ์น˜
1164
+ let x, z;
1165
+ const edgeSpawn = Math.random() < 0.7; // 70% ํ™•๋ฅ ๋กœ ๊ฐ€์žฅ์ž๋ฆฌ์— ์ƒ์„ฑ
1166
+
1167
+ if (edgeSpawn) {
1168
+ // ๋งต ๊ฐ€์žฅ์ž๋ฆฌ์— ์ƒ์„ฑ
1169
+ if (Math.random() < 0.5) {
1170
+ x = (Math.random() < 0.5 ? -1 : 1) * (MAP_SIZE * 0.4 + Math.random() * MAP_SIZE * 0.1);
1171
+ z = (Math.random() - 0.5) * MAP_SIZE * 0.9;
1172
+ } else {
1173
+ x = (Math.random() - 0.5) * MAP_SIZE * 0.9;
1174
+ z = (Math.random() < 0.5 ? -1 : 1) * (MAP_SIZE * 0.4 + Math.random() * MAP_SIZE * 0.1);
1175
+ }
1176
+ } else {
1177
+ // ๋งต ์ค‘์•™ ์˜์—ญ์— ์ƒ์„ฑ
1178
+ x = (Math.random() - 0.5) * MAP_SIZE * 0.6;
1179
+ z = (Math.random() - 0.5) * MAP_SIZE * 0.6;
1180
+ }
1181
+
1182
+ rock.position.set(x, Math.random() * 2, z);
1183
 
1184
  rock.rotation.set(
1185
  Math.random() * Math.PI,
 
1187
  Math.random() * Math.PI
1188
  );
1189
 
1190
+ // ๋ฐ”์œ„ ํฌ๊ธฐ๋ฅผ ์ข€ ๋” ๋‹ค์–‘ํ•˜๊ฒŒ ์„ค์ •
1191
+ const scale = 1 + Math.random() * 1.5; // 1.0 ~ 2.5 ์‚ฌ์ด์˜ ํฌ๊ธฐ
1192
+ rock.scale.set(scale, scale, scale);
 
 
1193
 
1194
  // ์ถฉ๋Œ ๋ฐ•์Šค ์ƒ์„ฑ ๋ฐ ์„ค์ •
1195
  const boundingBox = new THREE.Box3().setFromObject(rock);
 
1200
  collisionMesh.position.copy(rock.position);
1201
  collisionMesh.rotation.copy(rock.rotation);
1202
 
1203
+ // ๋ชจ๋“  ๋ฐ”์œ„๋ฅผ ์ถฉ๋Œ ๊ฐ€๋Šฅํ•˜๊ฒŒ ์„ค์ •
1204
  rock.userData.isCollidable = true;
1205
  rock.userData.type = 'rock';
1206
  rock.userData.collisionMesh = collisionMesh;
 
1208
  rock.castShadow = true;
1209
  rock.receiveShadow = true;
1210
 
1211
+ // ๋‹ค๋ฅธ ๋ฐ”์œ„๋“ค๊ณผ์˜ ๊ฑฐ๋ฆฌ ์ฒดํฌ
1212
+ let tooClose = false;
1213
+ for (const obstacle of this.obstacles) {
1214
+ const distance = rock.position.distanceTo(obstacle.position);
1215
+ if (distance < 15) { // ์ตœ์†Œ ๊ฑฐ๋ฆฌ ์„ค์ •
1216
+ tooClose = true;
1217
+ break;
1218
+ }
1219
+ }
1220
+
1221
+ if (!tooClose) {
1222
+ this.obstacles.push(rock);
1223
+ this.scene.add(rock);
1224
+ this.scene.add(collisionMesh);
1225
+ }
1226
  }
1227
 
1228
  // ์„ ์ธ์žฅ ์ถ”๊ฐ€