fix: Improve corridor generation logic to ensure minimum segment length

This commit is contained in:
2026-03-16 16:46:21 +11:00
parent bb1c9f9284
commit 5ab233b00c
2 changed files with 62 additions and 4 deletions
+33
View File
@@ -0,0 +1,33 @@
# Shadow Pixel Run
Shadow Pixel Run is a 2D pixel art game built with Godot 4.6.
## Features
- Procedural dungeon generation with rooms and corridors
- Retro pixel art visuals (640×360 viewport, 4× window scale)
- Player movement and tile-based world
- Seamless auto-connected walls and floor tiles
## Project Structure
- **Main scene:** `scenes/world.tscn` (Node2D with `FloorLayer`, `MapLayer`,)
- **Player:** `CharacterBody2D` at `scenes/world.tscn > Player`, script: `scripts/actors/player.gd`
- **Scripts:** All under `scripts/` (organized by category)
- **Assets:** All under `assets/sprites/` (Godot auto-generates `.import` files; do not edit these manually)
- **Tilemaps:**
- `FloorLayer`: `office_floor.png` (single-tile floor atlas)
- `WallLayer`: `office_walls.png` (auto-connected terrain tileset)
## Controls
Left mouse button
## Art & Assets
- All sprites and tilesets are in `assets/sprites/` and `assets/tilesets/`
- Pixel art style, 32×32 tile atlases
## License
See LICENSE and THIRDPARTY.md for asset and code licensing details.
+29 -4
View File
@@ -115,17 +115,42 @@ func _get_manhattan_points(start: Vector2i, end: Vector2i, v_first: bool) -> Arr
var pts: Array[Vector2i] = []
var x_step: int = sign(end.x - start.x) if end.x != start.x else 1
var y_step: int = sign(end.y - start.y) if end.y != start.y else 1
var min_len: int = 2 # Minimum segment length before changing direction
if v_first:
for y in range(start.y, end.y + y_step, y_step):
var y_len: int = abs(end.y - start.y)
var y_end: int = start.y
if y_len < min_len:
y_end = start.y + y_step * min_len
# Clamp to end.y if overshoot
if (y_step > 0 and y_end > end.y) or (y_step < 0 and y_end < end.y):
y_end = end.y
else:
y_end = end.y
for y in range(start.y, y_end + y_step, y_step):
pts.append(Vector2i(start.x, y))
for x in range(start.x + x_step, end.x + x_step, x_step):
pts.append(Vector2i(x, end.y))
pts.append(Vector2i(x, y_end))
# If y_end != end.y, finish remaining y segment
if y_end != end.y:
for y in range(y_end + y_step, end.y + y_step, y_step):
pts.append(Vector2i(end.x, y))
else:
for x in range(start.x, end.x + x_step, x_step):
var x_len: int = abs(end.x - start.x)
var x_end: int = start.x
if x_len < min_len:
x_end = start.x + x_step * min_len
if (x_step > 0 and x_end > end.x) or (x_step < 0 and x_end < end.x):
x_end = end.x
else:
x_end = end.x
for x in range(start.x, x_end + x_step, x_step):
pts.append(Vector2i(x, start.y))
for y in range(start.y + y_step, end.y + y_step, y_step):
pts.append(Vector2i(end.x, y))
pts.append(Vector2i(x_end, y))
if x_end != end.x:
for x in range(x_end + x_step, end.x + x_step, x_step):
pts.append(Vector2i(x, end.y))
return pts
# Returns true if the corridor path does not violate the 2-tile gap rule between rooms.