So, I have an enum for walls, simply called WallState, with the 4 cardinal direction as bitmasks. I also have a struct called Chunk, which simply has a Position (x and y struct) and a WallState[,]. I have Chunks handle a 5, 5 tiling of WallState’s and the map is simply a 3x3 of chunks that generates as the player moves. When you go to the chunk to the right of the center, that chunk on the right becomes the center, all the chunks on the left get removed, and new chunks get generated on the right. It’s meant to be an infinite maze that has no ending, but for some reason, whenever I move out of the original 3x3 of chunks that generate on startup, I have a chance that when moving to the left or the right (not up and down confusingly) I have a chance to bump into an invisible wall…

Above, I cannot move right, even though a wall doesn’t exist there, it does somewhere in the code…
public static Chunk[,] ShiftMaze(Chunk[,] maze, WallState direction, int width, int height) {
Chunk[] generatedChunks = new Chunk[3];
Chunk[,] tempNewMaze = new Chunk[5,5];
Chunk[,] newMaze = new Chunk[3,3];
if (direction.HasFlag(WallState.LEFT)) {
Chunk[,] newChunkTemp = GenerateMaze(15,5,Time.time.ToString());
for (int i = 0; i < 3; i ++) { generatedChunks[i] = newChunkTemp[i,0]; }
for (int x = 0; x < 4; x ++) {
for (int y = 0; y < 3; y ++) {
if (x == 0) {
tempNewMaze[x,y+1] = generatedChunks[y];
} else {
tempNewMaze[x,y+1] = maze[x-1,y];
}
}
}
for (int x = 0; x < 3; x ++) {
for (int y = 0; y < 3; y ++) {
newMaze[x,y] = tempNewMaze[x,y+1];
}
}
}
if (direction.HasFlag(WallState.RIGHT)) {
Chunk[,] newChunkTemp = GenerateMaze(15,5,Time.time.ToString());
for (int i = 0; i < 3; i ++) { generatedChunks[i] = newChunkTemp[i,0]; }
for (int x = 0; x < 4; x ++) {
for (int y = 0; y < 3; y ++) {
if (x == 3) {
tempNewMaze[x+1,y+1] = generatedChunks[y];
} else {
tempNewMaze[x+1,y+1] = maze[x,y];
}
}
}
for (int x = 0; x < 3; x ++) {
for (int y = 0; y < 3; y ++) {
newMaze[x,y] = tempNewMaze[x+2,y+1];
}
}
}
if (direction.HasFlag(WallState.UP)) {
Chunk[,] newChunkTemp = GenerateMaze(5,15,Time.time.ToString());
for (int i = 0; i < 3; i ++) { generatedChunks[i] = newChunkTemp[0,i]; }
for (int x = 1; x < 4; x ++) {
for (int y = 1; y < 4; y ++) {
tempNewMaze[x,y] = maze[x-1,y-1];
}
}
for (int i = 0; i < 3; i ++) { tempNewMaze[i+1,4] = generatedChunks[i]; }
for (int x = 0; x < 3; x ++) {
for (int y = 0; y < 3; y ++) {
newMaze[x,y] = tempNewMaze[x+1,y+2];
}
}
}
if (direction.HasFlag(WallState.DOWN)) {
Chunk[,] newChunkTemp = GenerateMaze(5,15,Time.time.ToString());
for (int i = 0; i < 3; i ++) { generatedChunks[i] = newChunkTemp[0,i]; }
for (int x = 1; x < 4; x ++) {
for (int y = 1; y < 4; y ++) {
tempNewMaze[x,y] = maze[x-1,y-1];
}
}
for (int i = 0; i < 3; i ++) { tempNewMaze[i+1,0] = generatedChunks[i]; }
for (int x = 0; x < 3; x ++) {
for (int y = 0; y < 3; y ++) {
newMaze[x,y] = tempNewMaze[x+1,y];
}
}
}
for (int j = 0; j < 4; j ++) {
for (int i = 0; i < 5; i ++) {
if (j == 0) {
if (maze[1,1].Walls[0,i].HasFlag(WallState.LEFT)) { maze[0,1].Walls[4,i] |= WallState.RIGHT; }
else { maze[0,1].Walls[4,i] &= ~WallState.RIGHT; }
}
if (j == 1) {
if (maze[1,1].Walls[i,4].HasFlag(WallState.UP)) { maze[1,2].Walls[i,0] |= WallState.DOWN; }
else { maze[1,2].Walls[i,0] &= ~WallState.DOWN; }
}
if (j == 2) {
if (maze[1,1].Walls[4,i].HasFlag(WallState.RIGHT)) { maze[2,1].Walls[0,i] |= WallState.LEFT; }
else { maze[2,1].Walls[0,i] &= ~WallState.RIGHT; }
}
if (j == 3) {
if (maze[1,1].Walls[i,0].HasFlag(WallState.DOWN)) { maze[1,0].Walls[i,4] |= WallState.UP; }
else { maze[1,0].Walls[i,4] &= ~WallState.RIGHT; }
}
}
}
return newMaze;
}
All that GenerateMaze() does is takes in a size (x, y) and a seed, and then uses a recursive backtracker on the generated maze to add some paths.
ShiftMaze() is only called whenever the player moves into a new chunk, and chunk[1,1] is the center.
I added the last double for loop to try and check if the Chunk WallStates just aren’t rendering correctly.


