Spaces:
Running
Running
ok
Browse files- src/config/gameConfig.js +14 -7
- src/scene/PathBuilder.js +32 -0
src/config/gameConfig.js
CHANGED
|
@@ -155,20 +155,27 @@ export function getWaveParams(n) {
|
|
| 155 |
return { count, hp, speed, reward, spawnInterval };
|
| 156 |
}
|
| 157 |
|
| 158 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
export const PATH_POINTS = [
|
| 160 |
-
|
|
|
|
|
|
|
| 161 |
new THREE.Vector3(-24, 0, 0),
|
|
|
|
| 162 |
new THREE.Vector3(0, 0, 0),
|
|
|
|
| 163 |
new THREE.Vector3(0, 0, 16),
|
|
|
|
| 164 |
new THREE.Vector3(20, 0, 16),
|
| 165 |
-
|
|
|
|
| 166 |
];
|
| 167 |
|
| 168 |
-
// Grid settings
|
| 169 |
-
export const GROUND_SIZE = 60;
|
| 170 |
-
export const GRID_CELL_SIZE = 2;
|
| 171 |
-
|
| 172 |
// Visual settings
|
| 173 |
export const SCENE_BACKGROUND = 0x202432;
|
| 174 |
|
|
|
|
| 155 |
return { count, hp, speed, reward, spawnInterval };
|
| 156 |
}
|
| 157 |
|
| 158 |
+
// Grid settings
|
| 159 |
+
export const GROUND_SIZE = 60;
|
| 160 |
+
export const GRID_CELL_SIZE = 2;
|
| 161 |
+
|
| 162 |
+
// Path waypoints (edge-to-edge, axis-aligned for clean corners)
|
| 163 |
+
// Starts at bottom edge (z = -GROUND_SIZE/2), ends at right edge (x = GROUND_SIZE/2)
|
| 164 |
export const PATH_POINTS = [
|
| 165 |
+
// Start on bottom edge
|
| 166 |
+
new THREE.Vector3(-24, 0, -GROUND_SIZE / 2),
|
| 167 |
+
// Up to center-left
|
| 168 |
new THREE.Vector3(-24, 0, 0),
|
| 169 |
+
// Across the middle
|
| 170 |
new THREE.Vector3(0, 0, 0),
|
| 171 |
+
// Up to mid-upper lane
|
| 172 |
new THREE.Vector3(0, 0, 16),
|
| 173 |
+
// Right towards exit lane
|
| 174 |
new THREE.Vector3(20, 0, 16),
|
| 175 |
+
// End on right edge
|
| 176 |
+
new THREE.Vector3(GROUND_SIZE / 2, 0, 16),
|
| 177 |
];
|
| 178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
// Visual settings
|
| 180 |
export const SCENE_BACKGROUND = 0x202432;
|
| 181 |
|
src/scene/PathBuilder.js
CHANGED
|
@@ -35,6 +35,27 @@ export class PathBuilder {
|
|
| 35 |
for (let i = 0; i < this.pathPoints.length - 1; i++) {
|
| 36 |
this.addSegment(this.pathPoints[i], this.pathPoints[i + 1]);
|
| 37 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
}
|
| 39 |
|
| 40 |
createPathLine() {
|
|
@@ -64,4 +85,15 @@ export class PathBuilder {
|
|
| 64 |
this.scene.add(road);
|
| 65 |
this.roadMeshes.push(road);
|
| 66 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
}
|
|
|
|
| 35 |
for (let i = 0; i < this.pathPoints.length - 1; i++) {
|
| 36 |
this.addSegment(this.pathPoints[i], this.pathPoints[i + 1]);
|
| 37 |
}
|
| 38 |
+
|
| 39 |
+
// Add square fill tiles at right-angle corners for perfect joins
|
| 40 |
+
for (let i = 1; i < this.pathPoints.length - 1; i++) {
|
| 41 |
+
const prev = this.pathPoints[i - 1];
|
| 42 |
+
const cur = this.pathPoints[i];
|
| 43 |
+
const next = this.pathPoints[i + 1];
|
| 44 |
+
|
| 45 |
+
const v1 = new THREE.Vector3().subVectors(cur, prev);
|
| 46 |
+
const v2 = new THREE.Vector3().subVectors(next, cur);
|
| 47 |
+
// Consider only x/z for pathing (top-down)
|
| 48 |
+
v1.y = 0;
|
| 49 |
+
v2.y = 0;
|
| 50 |
+
|
| 51 |
+
// Normalize direction to axis-aligned unit vectors when possible
|
| 52 |
+
const isV1H = Math.abs(v1.x) > Math.abs(v1.z);
|
| 53 |
+
const isV2H = Math.abs(v2.x) > Math.abs(v2.z);
|
| 54 |
+
const isTurn = (isV1H && !isV2H) || (!isV1H && isV2H);
|
| 55 |
+
if (isTurn) {
|
| 56 |
+
this.addCornerTile(cur);
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
}
|
| 60 |
|
| 61 |
createPathLine() {
|
|
|
|
| 85 |
this.scene.add(road);
|
| 86 |
this.roadMeshes.push(road);
|
| 87 |
}
|
| 88 |
+
|
| 89 |
+
addCornerTile(center) {
|
| 90 |
+
const size = ROAD_HALF_WIDTH * 2;
|
| 91 |
+
const geo = new THREE.BoxGeometry(size, 0.101, size);
|
| 92 |
+
const tile = new THREE.Mesh(geo, this.roadMat);
|
| 93 |
+
tile.castShadow = false;
|
| 94 |
+
tile.receiveShadow = true;
|
| 95 |
+
tile.position.set(center.x, 0.0505, center.z);
|
| 96 |
+
this.scene.add(tile);
|
| 97 |
+
this.roadMeshes.push(tile);
|
| 98 |
+
}
|
| 99 |
}
|