At the moment all 3 tile corner cases that are being matched by the algorithm are going to spawn a wall corner tile. For dead ends such as the image below, this does not look great. In this section, you will add a new function to find those dead ends and rotate the tile correctly.
Update MapBuilder API Script
You will need to add a few changes to the MapBuilder script. Some of the code is going to be refactored to make it easier to spawn extra tiles later on.
Update CheckForWallCorner Function
The CheckForWallCorner function will need a few changes. A new variable called extraTile will be created, and if there is a match, and that tileRow is not nil then the extraTile for this function will be a floor tile.
functionMapBuilder.CheckForWallCorner(map, neighbors, row, col)local tileRow = nillocal extraTile = nillocal rotation = Rotation.New()
if neighbors.WEST == MapBuilder.Type.Wall and neighbors.NORTH == MapBuilder.Type.Wall and map[row][col] ~= MapBuilder.Type.Wall and neighbors.EAST ~= niland neighbors.SOUTH ~= nilthen tileRow = TILES[MapBuilder.Type.WallCorner]
rotation.z = 0elseif neighbors.NORTH == MapBuilder.Type.Wall and neighbors.EAST == MapBuilder.Type.Wall and map[row][col] ~= MapBuilder.Type.Wall and neighbors.WEST ~= niland neighbors.SOUTH ~= nilthen tileRow = TILES[MapBuilder.Type.WallCorner]
rotation.z = 90elseif neighbors.EAST == MapBuilder.Type.Wall and neighbors.SOUTH == MapBuilder.Type.Wall and map[row][col] ~= MapBuilder.Type.Wall and neighbors.NORTH ~= niland neighbors.WEST ~= nilthen tileRow = TILES[MapBuilder.Type.WallCorner]
rotation.z = 180elseif neighbors.SOUTH == MapBuilder.Type.Wall and neighbors.WEST == MapBuilder.Type.Wall and map[row][col] ~= MapBuilder.Type.Wall and neighbors.EAST ~= niland neighbors.NORTH ~= nilthen tileRow = TILES[MapBuilder.Type.WallCorner]
rotation.z = 270endif tileRow ~= nilthen extraTile = TILES[MapBuilder.Type.Floor]
endreturn tileRow, rotation, extraTile
endCode language:Lua(lua)
Create CheckForDeadEnd Function
Create a new function called CheckForDeadEnd that will work very similar to the CheckForWallCorner function, the main only difference is the rotation of the tile will be 45 degree increments for the cardinal directions.
Tile Rotation
If the children of your tile have been rotated, then the rotation for the Z axis will be different for you. Change the rotation Z value until you find which values work for your tile.
functionMapBuilder.CheckForDeadEnd(map, neighbors, row, col)local tileRow = nillocal extraTile = nillocal rotation = Rotation.New()
if(neighbors.WEST == MapBuilder.Type.Wall and neighbors.NORTH == MapBuilder.Type.Wall and neighbors.EAST == MapBuilder.Type.Wall and neighbors.SOUTH ~= MapBuilder.Type.Wall and map[row][col] ~= MapBuilder.Type.Wall) then tileRow = TILES[MapBuilder.Type.WallCorner]
rotation.z = 45elseif(neighbors.NORTH == MapBuilder.Type.Wall and neighbors.EAST == MapBuilder.Type.Wall and neighbors.SOUTH == MapBuilder.Type.Wall and neighbors.WEST ~= MapBuilder.Type.Wall and map[row][col] ~= MapBuilder.Type.Wall) then tileRow = TILES[MapBuilder.Type.WallCorner]
rotation.z = 135elseif(neighbors.EAST == MapBuilder.Type.Wall and neighbors.SOUTH == MapBuilder.Type.Wall and neighbors.WEST == MapBuilder.Type.Wall and neighbors.NORTH ~= MapBuilder.Type.Wall and map[row][col] ~= MapBuilder.Type.Wall) then tileRow = TILES[MapBuilder.Type.WallCorner]
rotation.z = -135elseif(neighbors.SOUTH == MapBuilder.Type.Wall and neighbors.WEST == MapBuilder.Type.Wall and neighbors.NORTH == MapBuilder.Type.Wall and neighbors.EAST ~= MapBuilder.Type.Wall and map[row][col] ~= MapBuilder.Type.Wall) then tileRow = TILES[MapBuilder.Type.WallCorner]
rotation.z = -45endif tileRow ~= nilthen extraTile = TILES[MapBuilder.Type.Floor]
endreturn tileRow, rotation, extraTile
endCode language:Lua(lua)
Update SpawnExtraTile Function
The SpawnExtraTile function will now take in the tile that will be spawned, and also do a check to see what type of tile it is. If it is the floor tile, then the rotation is reset and the scale is set to 1.
The Spawn function also needs updating so it can call the CheckForDeadEnd function. The order the checks are done is important, meaning that the dead end check should be done first, then the wall corner check, then finally the actual tile that matches the value from the map table.
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.
3rd Party Cookies
This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.
Keeping this cookie enabled helps us to improve our website.
Please enable Strictly Necessary Cookies first so that we can save your preferences!