Path Generation Module
This module demonstrates several advanced game development concepts:
1. Procedural Content Generation (PCG)
2. Pathfinding algorithms
3. Constraint-based generation
Methods
(inner) generatePath(grid) → {Promise.<Array.<{x: number, y: number}>>}
Generates a valid path through the game grid using a modified depth-first search.
This algorithm ensures:
- Path always moves from left to right
- No diagonal movements
- No path segments touch each other (except at turns)
- Path is always completable
Parameters:
Name | Type | Description |
---|---|---|
grid |
Array.<Array.<string>> | 2D array representing the game grid |
Returns:
Promise resolving to array of path coordinates
Implementation uses:
- Backtracking algorithm pattern
- Constraint satisfaction
- Random selection for variety
- Type
- Promise.<Array.<{x: number, y: number}>>
(inner) getPathPosition(progress, path) → {Object}
Calculates a position along the path based on a progress value
Implements smooth entity movement along path segments
Parameters:
Name | Type | Description |
---|---|---|
progress |
number | Progress along path (0-1) |
path |
Array.<{x: number, y: number}> | Array of path coordinates |
Returns:
Interpolated position along path
Uses:
- Linear interpolation (lerp)
- Path segment traversal
- Normalized progress tracking
- Type
- Object