Computer Games Design

Adventures in Procedural Content Generation - Adam Speers

Computer Games Design

Adventures in Procedural Content Generation - Adam Speers

Dungeon Generator: Part 6

More rubrics for cubes

Picking the correct tile type

Examining the sample tile-set from Dungeon Generator: Part 5, it is possible to visualise how the different tile elements fit together. Children learn mental spatial transformation skills through the playing of games, for example solving jigsaw puzzles or constructing things from Lego (Levine, et al., 2012). The dungeon generator needed a method that simulated those skills required to determine the correct tile and rotation for each position. This has been achieved by looking at the node information grid, navigating to each neighbour for a cell and recording if the neighbour is walkable or not (Figure 6.42). A cells tile type is determined by the pattern formed around the cell by its neighbours:

Look for neighbours:

Simple: North, East, South, West

Extended: North West, North, North East, East, South West, South, South East, West

The process for finding the correct tile type can be summarised as:

1. Read the walkable value for a cell's neighbours in each direction (Figure 6.1).

2. Lookup corresponding values in the tile match table (Figure 6.2).

3. Store the matching tile type and rotation (Figure 6.3).

Each tile Prefab is stored as a single object and has a default rotation. Patterns for matching tiles are repeated for each of the four cardinal directions. The lookup provides both the matching tile type and rotation. The rotation will replace the default and align the Prefab with the pattern found (Figure 6.4, 6.5, 6.6).

Figure 6.1: Find Neighbours: Read the grid for all surrounding tiles and store if walkable

Figure 6.2: Pick Tile - Read the scriptable object to find the tile type, save type and rotation to info map. Lookup prefab with type.

Figure 6.3: Spawn - Read the info map for this grid square and spawn the correct geometry with the stored rotation.

Figure 6.4: Tile_End rotation - 90

Figure 6.5: Tile_End rotation - 180

Figure 6.6: Tile_End rotation - 270

Navigating the grid

To assign a walkable value for each neighbour, the generator must navigate the grid. This is done by calculating the neighbours co-ordinates, using the target cells co-ordinates (x,y) with an offset for each direction.

NorthWestTile = new Vector2(x - 1, y + 1);

NorthTile = new Vector2(x + 0, y + 1);

NorthEastTile = new Vector2(x + 1, y + 1);

EastTile = new Vector2(x + 1, y + 0);

SouthWestTile = new Vector2(x - 1, y - 1);

SouthTile = new Vector2(x + 0, y - 1);

SouthEastTile = new Vector2(x + 1, y - 1);

WestTile = new Vector2(x - 1, y + 0);

Figure 6.42: Navigation offsets


Pattern matching by tile type

The following diagrams show the complete set of lookup rules for the extended tile matching process.

Figure 6.7: Tile_Corner_0

Figure 6.8: Check Neighbours and Store Rotation

Figure 6.9: Check Neighbours and Store Rotation

Figure 6.10: Tile_Corner_1

Figure 6.11: Check Neighbours and Store Rotation

Figure 6.12: Check Neighbours and Store Rotation

Figure 6.13: Tile_Crossroads_0

Figure 6.14: Check Neighbours and Store Rotation

Figure 6.15: Tile_Crossroads_1

Figure 6.16: Check Neighbours and Store Rotation

Figure 6.17: Tile_Crossroads_2a

Figure 6.18: Check Neighbours and Store Rotation

Figure 6.19: Tile_Crossroads_2b

Figure 6.20: Check Neighbours and Store Rotation

Figure 6.21: Tile_Crossroads_3

Figure 6.22: Check Neighbours and Store Rotation

Figure 6.23: Tile_Crossroads_4

Figure 6.24: Check Neighbours and Store Rotation

Figure 6.26: Tile_End

Figure 6.27: Check Neighbours and Store Rotation

Figure 6.28: Check Neighbours and Store Rotation

Figure 6.29: Check Neighbours and Store Rotation

Figure 6.30: Check Neighbours and Store Rotation

Figure 6.31: Tile_Straight

Figure 6.32: Check Neighbours and Store Rotation

Figure 6.33: Check Neighbours and Store Rotation

Figure 6.34: Tile_Tjunc_0

Figure 6.35: Check Neighbours and Store Rotation

Figure 6.36: Tile_Tjunc_1a

Figure 6.37: Check Neighbours and Store Rotation

Figure 6.38: Tile_Tjunc_1b

Figure 6.39: Check Neighbours and Store Rotation

Figure 6.40: Tile_Tjunc_2

Figure 6.41: Check Neighbours and Store Rotation

References

Levine, S., Ratliff, K., Huttenlocher, J. & Cannon, J. (2012). Early puzzle play: A predictor of preschoolers' spatial transformation skill. Developmental Psychology, 48(2), pp. 530-542.