Another update for you. I’ve got the majority of my old Unity function finished. (CreateLevel & ProcessTiles) Now I just need to create the BuildWalls function to actually spawn the meshes. As you can see, it’s a bit more organized now. Can’t trace anything because I’m not seeing ANY execution paths firing at the moment, but I’m not even going to worry about that until I’m done implementing the BuildWalls function.
I really appreciate your help on this one. I’m kinda scared about the whole execution path thing, but we’ll deal with that when the development of this version is completed. And if I need to send another file, at least I know how to cut it WAY down in size. I didn’t know what I could get rid of and what I needed to include.
This is the code I wrote that I’m porting to BP:
#pragma strict
var mazeMaxSize : int = 20;
class mazeBlock {
var hasBeenProcessed : boolean;
var canGoNorth : boolean;
var canGoSouth : boolean;
var canGoEast : boolean;
var canGoWest : boolean;
function Reset () {
hasBeenProcessed = false;
canGoNorth = false;
canGoSouth = false;
canGoEast = false;
canGoWest = false;
}
};
// Global Variables
var newObject : Transform;
var mazeGrid : mazeBlock,];
var levelSizeX : int;
var levelSizeY : int;
function Start () {
Debug.Log("Creating Maze");
CreateMaze (5, 5);
Debug.Log("Finished Creating");
BuildMaze();
}
function Update () {
}
function CreateMaze(x : int, y : int) {
Debug.Log ("Starting CreateMaze");
// set our level size
levelSizeX = x;
levelSizeY = y;
mazeGrid = new mazeBlock[mazeMaxSize, mazeMaxSize];
Debug.Log ("Initializing Maze Squares");
//reset all grid squares to init values.
for (var i : int = 0; i<mazeMaxSize; i++)
{
for (var j : int = 0; j<mazeMaxSize; j++)
{
mazeGrid[i,j] = new mazeBlock();
mazeGrid[i,j].Reset();
}
}
Debug.Log ("About to process squares");
// start our maze generation by processing the first square
ProcessSquare (Random.Range(0, levelSizeX+1),Random.Range(0, levelSizeY+1));
Debug.Log ("Finished!");
}
function ProcessSquare (x: int, y: int) {
// mark this grid point as processed
mazeGrid[x,y].hasBeenProcessed=true;
Debug.Log("Processing Square:");
// start our function loop
do {
// pick a random direction
var nextDirection = Random.Range(1, 5);
// process the square in the next direction
switch (nextDirection)
{
case 1: //try to go north
if (y == levelSizeY || mazeGrid[x, y+1].hasBeenProcessed) break; //we can't go north
mazeGrid [x, y].canGoNorth=true;
mazeGrid [x, y+1].canGoSouth=true;
ProcessSquare (x, y+1);
break;
case 2: //try to go east
if (x == levelSizeX || mazeGrid[x+1,y].hasBeenProcessed) break; //we can't go right
mazeGrid [x, y].canGoEast=true;
mazeGrid [x+1,y].canGoWest=true;
ProcessSquare (x+1, y);
break;
case 3: //try to go south
if (y==0 || mazeGrid[x, y-1].hasBeenProcessed) break; // we can't go down
mazeGrid[x,y].canGoSouth=true;
mazeGrid[x,y-1].canGoNorth=true;
ProcessSquare (x, y-1);
break;
case 4: //try to go west
if (x==0 || mazeGrid[x-1,y].hasBeenProcessed) break; //we can't go left
mazeGrid[x,y].canGoWest=true;
mazeGrid[x-1,y].canGoEast=true;
ProcessSquare (x-1, y);
break;
default:
break;
}
//check to see if all surrounding squares have been processed
var processedCount=0;
if (y==levelSizeY || mazeGrid[x, y+1].hasBeenProcessed) processedCount++;
if (x==levelSizeX || mazeGrid[x+1, y].hasBeenProcessed) processedCount++;
if (y==0 || mazeGrid[x, y-1].hasBeenProcessed) processedCount++;
if (x==0 || mazeGrid[x-1, y].hasBeenProcessed) processedCount++;
// if so, exit our loop, and our function
} while (processedCount < 4);
}
function BuildMaze() {
for (var i : int = 0; i<=levelSizeX; i++)
for (var j : int = 0; j <=levelSizeY; j++) {
var newPosition : Vector3;
newPosition.Set (4*i, 4*j, 0);
Instantiate (newObject, newPosition, newObject.rotation);
if (mazeGrid[i,j].canGoNorth) {
newPosition.Set ((4*i), (4*j)+2, 0);
Instantiate(newObject, newPosition, newObject.rotation);
}
if (mazeGrid[i,j].canGoEast) {
newPosition.Set ((4*i)+2, (4*j), 0);
Instantiate(newObject, newPosition, newObject.rotation);
}
}
}
Really the only major difference here is in the code I could do a “Do While” loop, where in BP it looks like I only have the option of a normal “While” loop. But I think I’m okay in translating the difference.