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).
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);
Pattern matching by tile type
The following diagrams show the complete set of lookup rules for the extended tile matching process.
Next Post
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.