From 5ab233b00c2af529847d5ffe07134c788bbac0dd Mon Sep 17 00:00:00 2001 From: Stefan Willoughby Date: Mon, 16 Mar 2026 16:46:21 +1100 Subject: [PATCH] fix: Improve corridor generation logic to ensure minimum segment length --- README.md | 33 +++++++++++++++++++++++++++++++++ map/map_generator.gd | 33 +++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e69de29..11d3bff 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/map/map_generator.gd b/map/map_generator.gd index 4765cee..7db06d4 100644 --- a/map/map_generator.gd +++ b/map/map_generator.gd @@ -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.