Week 8 - Level Blocking


Working with the Random Level Generator.

Level Generator

I originally wanted to run the Random Level Generator using the TileMap from the tutorials and the Random Tile Generator (which was used for vases or something). However, after spending some time (probably too much) I found that this wasn't quite going the way I wanted it to. So what does one do when they can't figure out what to do? The Internet!
It was there I found the walker idea (thanks to Mehails Tumkins for the original code). The basic idea was to create a grid(x, y) and then create a number of "walkers" that will walk around the grid recording the squares they walk on whilst staying away from the edge of the grid.
These squares become the floor of the level. 


From there the LevelGenerator script will then go through each square of the grid and check if one of its neighbour squares is a floor square, and if it is, will assign a particular number to that square. (Was a good idea Lindsay!) I.e. If a square only has 1 neighbour floor tile that was X+1, Y+1, it will be assigned 00100000. 


In addition to this, if a square has multiple floor neighbours, then these numbers can be added together. Once all the squares have been assigned then the script will add the appropriate wall tile prefabs to their assigned squares. 
Each of these wall tile prefabs come with a box collider to create the effect of actual walls.



One small issue that I'm still working my way through is the wrong tiles being generated, however, this issue is becoming less and less because when I find one, I am able to add the exception to the (somewhat large) if statement in the LevelGenerator script. In the example below you can see the island square (which is the default for empty squares that don't have a tile). This is fixed by adding 00001010 to the if statement.

After the walls have all been created, the game will then add in the exit square, usually as far from the player as possible while still being inside the map, because we don't want to make it too easy. This particular tile prefab also comes with an exit script attached to it, which will, when touched by the player, regenerate and restart the whole level. This gives the effect of entering into another level, or proceeding further down into the Dungeons of Dread! My intention is, in this script to add a counter which will be attached to the enemies, making them harder/faster on each level down you go. In addition to this, the counter will also be the high score for the player, the more levels down you go, the higher the score. 



Enemies

As you can see in the gif's, there are spawners happening for enemies. Currently they are just circles (with an added shader), but they are also generated randomly with the level at random locations.

References
M. Tumkins, https://medium.com/@mihailstumkins/how-to-create-random-levels-with-unity-3d-221..., viewed 3 Sept 2020.

Files

10 Sept.zip Play in browser
Sep 10, 2020

Leave a comment

Log in with itch.io to leave a comment.