-
Notifications
You must be signed in to change notification settings - Fork 2
Random Maps
PH77SER edited this page May 7, 2024
·
2 revisions
the random map generation code is BASED on this https://github.com/GarnetKane99/RandomWalkerAlgo_YT
in essence, you have a data structure called Grid, which can be ONE_ONE, TWO_ONE, TWO_TWO, CONTROL_ROOM and EMPTY
- generate an empty MapWidth x MapHeight grid, datatype Grid. fill it with Grid.EMPTY
- spawn some "walkers" in the middle, and let them walk from the middle, and wherever they walk, they turn Grid.EMPTY into Grid.ONE_ONE. this represents a ROOM SPACE for now, not neccesarily a 1x1 room.
- randomly pick a point in this until you hit a Grid.ONE_ONE, and turn it into Grid.CONTROL_ROOM. cuz only one spawns
- run through every tile in the grid. if it's ONE_ONE check it's neighbors to see if you can spawn a 2x2 room. roll the chance to get a 2x2 room, and if successful, change the tiles to Grid.TWO_TWO and run DrawTwoByTwo().
- similar logic for 2x1 vertical, and 2x1 horizontal rooms, and DrawTwoByOneVertical()/Horizontal()
- run through the entire grid again. if we land on a ONE_ONE room, draw it. (note: drawing means spawning all the assets in it so they're in the actual unity scene). (note: in the running of the Draw commands, we also spawn navmeshes on the whole map corresponding to each room)
- bake the navmesh so we have one big area where AI can walk on
- run PostMapGenFunction. this will generate doors so they do not interfere with A.I. pathfinding and also run PostmapGenScript for anything else.