So here’s what I already have: https://pastebin.com/BpUshpKY (this is the relevant function)
The maze is divided into invidiual blocks, the maze this code will generate is 9x9 “blocks”.
My maze is defined using an X and Y system, and each X and Y also having 4 values for left, up, right, down.
These extra values define whether or not there is a wall in this place.
I then have the draw() function read the gameGrid[][][] array, and draw out the lines in each block, so for example:
gameGrid[0][0][0] = 0;
gameGrid[0][0][1] = 0;
gameGrid[0][0][2] = 0;
gameGrid[0][0][3] = 1;
will be the top-left-most block, and it will have a wall on the left side, the up side, the right side, and it will have no wall on the bottom side.
the actual random generation is probably very needlessly complicated and even though I made it, I don’t fully comprehend how it works… because it doesn’t fully work as intended. the aim of that part of the function is to make sure that there are always enough “openings” or “sides with no walls”, so that the whole thing is connected…
it kind of works. but it’s very, very slightly inconsistent. like 1 out of 100 attempts will block off one part of the maze.
the reason i went through all this trouble instead of looking for a random maze generation algorithm is because I need to know the location of every wall.
This is because I aim to put tanks inside this maze, and their projectiles will bounce off the walls, so i can create a tank vs tank game, in 2d top-down view, and the main focus of the game is going to be the fact that you can shoot someone from behind a wall if you can aim your projectiles to bounce off the walls in the right way.
tl;dr: somewhat working random maze generator that allows me to keep track of where every wall is, and isnt, to create a random map for a tank game.
so the actual problem i have is: does anyone know of a simpler method to achieve this?
more specifically, I want to achieve random maze generation, but one where I can keep track of the walls so I can create collisions between them and the tanks/tank projectiles.
edit: here is my entire code, which is compilable, and should sort of showcase what I want, minus the tanks: https://pastebin.com/bKcDhPeP