🏰

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

ParamTypeRequiredDefaultDescription
widthnumberYes40Map width in cells. Range 20–80.
heightnumberYes30Map height in cells. Range 20–60.
roomCountnumberYes6Target number of rooms. Range 3–20.
roomSize.minnumberNo4Minimum room dimension.
roomSize.maxnumberNo8Maximum room dimension.
corridorWidthnumberNo1Corridor width (1–3 cells).
lootDensitynumberNo0.3Loot spawn density (0.0–1.0).
enemyDensitynumberNo0.3Enemy spawn density (0.0–1.0).

Generation Details

The dungeon layout generator follows this process:

  1. Binary Space Partition the map into leaf regions
  2. Place one room per BSP leaf (with random placement fallback)
  3. Build a Minimum Spanning Tree (MST) across room centres for guaranteed connectivity
  4. Add extra corridors based on difficulty for maze complexity
  5. Carve L-shaped corridors between connected rooms
  6. Place doors at corridor→room transitions
  7. Select entry/exit at the two farthest-apart rooms
  8. Scatter loot and enemy spawns on floor cells based on density params
  9. Validate: all rooms connected via BFS, entry→exit path exists

Content Output

ParamTypeRequiredDefaultDescription
gridDungeonCell[][]Cell types: "wall", "floor", "corridor", "door", "entry", "exit", "loot", "enemy".
roomsRoom[]Array of rooms with id, position, size, and centre coordinates.
corridorsCorridor[]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 rooms array 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.