🏰
Dungeon Layout
gameType: "dungeon-layout"
BSP-based dungeon generation with room placement, corridor carving, doors, loot spawns, enemy spawns, and guaranteed entry→exit connectivity. Difficulty scales via room count, map size, enemy density, and corridor complexity. Every layout is validated for full room connectivity via BFS.
Interactive Example
🏰 Dungeon Layout
BSP dungeon generation — rooms, corridors, loot & enemies
difficulty: 0.45connected ✓
🚪
💎
🚧
🚧
👾
🏁
Wall Floor Corridor🚪 Entry🏁 Exit💎 Loot👾 Enemy
Rooms
2
Path Length
18
Loot
1
Enemies
1
Try it
await pf.generate({
gameType: "dungeon-layout",
params: { width: 30, height: 20, roomCount: 5, lootDensity: 0.3 },
count: 1,
difficulty: { target: 0.50 }
})API Parameters
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
width | number | Yes | 40 | Map width in cells. Range 20–80. |
height | number | Yes | 30 | Map height in cells. Range 20–60. |
roomCount | number | Yes | 6 | Target number of rooms. Range 3–20. |
roomSize.min | number | No | 4 | Minimum room dimension. |
roomSize.max | number | No | 8 | Maximum room dimension. |
corridorWidth | number | No | 1 | Corridor width (1–3 cells). |
lootDensity | number | No | 0.3 | Loot spawn density (0.0–1.0). |
enemyDensity | number | No | 0.3 | Enemy spawn density (0.0–1.0). |
Generation Details
The dungeon layout generator follows this process:
- Binary Space Partition the map into leaf regions
- Place one room per BSP leaf (with random placement fallback)
- Build a Minimum Spanning Tree (MST) across room centres for guaranteed connectivity
- Add extra corridors based on difficulty for maze complexity
- Carve L-shaped corridors between connected rooms
- Place doors at corridor→room transitions
- Select entry/exit at the two farthest-apart rooms
- Scatter loot and enemy spawns on floor cells based on density params
- Validate: all rooms connected via BFS, entry→exit path exists
Content Output
| Param | Type | Required | Default | Description |
|---|---|---|---|---|
grid | DungeonCell[][] | — | — | Cell types: "wall", "floor", "corridor", "door", "entry", "exit", "loot", "enemy". |
rooms | Room[] | — | — | Array of rooms with id, position, size, and centre coordinates. |
corridors | Corridor[] | — | — | Corridors connecting room pairs with cell positions. |
doors | [y,x][] | — | — | Door positions where corridors meet rooms. |
lootSpawns | [y,x][] | — | — | Loot spawn positions. |
enemySpawns | [y,x][] | — | — | Enemy spawn positions. |
entry | [y,x] | — | — | Entry position. |
exit | [y,x] | — | — | Exit position. |
Example Request
bash
curl -X POST https://api.gameplaygen.com/generate \
-H "Authorization: Bearer gg_live_abc123..." \
-H "Content-Type: application/json" \
-d '{
"gameType": "dungeon-layout",
"params": { "width": 40, "height": 30, "roomCount": 8, "lootDensity": 0.4 },
"count": 1,
"difficulty": { "target": 0.6 }
}'Tips for Game Integration
- ▸Fog of war: Use room boundaries to reveal areas only when the player enters.
- ▸Minimap: The
roomsarray provides room outlines for an overview map. - ▸Stacking floors: Generate multiple layouts and link exits→entries for multi-level dungeons.
- ▸Door mechanics: Use door cells to trigger locked-door or key-door puzzles.