So within my project, I am basically trying to make a randomly generated maze with random entrances and exits. I have three classes (a Maze class, a GameScene class, and a Grid Class) within so far I have successfully been able to code a randomly generated maze.
However my problem is that the Maze class (which is where the random generation code takes place) purely contains the data for the maze, but no current connection to the graphics. So when I run my app, a blank screen shows up.
What I am trying (but am unsure how) to do is basically place a line (aka a black color sprite shaped in a line) in the location where the maze wall is.
So, the way my maze works is that it is a grid (array) in which each array cell's "walls" (up, down, left, or right) are defined as either true or false. If the cell wall is false, then there is no maze wall there; but if it is true, then there is a maze wall there. The state of each wall being randomly generated is what creates the maze.
I was able to connect the code to the color sprite named "mazeWall" within the GameScene class (using this code:)
var mazeWall: SKNode!
[...]
mazeWall = self.childNode(withName: "mazeWall")
Also, I was able to access the Maze class's data within GameScene class using this code to create an object of the Maze class type:
var maze = Maze()
However I am now unsure how to call the color sprite to the position of the true walls on the grid.
This is the code I attempted to have within the GameScene Class to access Maze class' data and to loop through the maze's cells and check which walls are true:
class GameScene: SKScene {
var mazeWall: SKNode!
var maze = Maze()
var backgroundColorCustom = UIColor(red: 255, green: 244, blue: 231,
alpha: 4.0)
override func didMove(to view: SKView) {
/* Set reference to obstacle layer node */
mazeWall = self.childNode(withName: "mazeWall")
//going through each cell and checking if it is true in order to place a wall
for x in 0..<self.maze.gridSize{
for y in 0..<self.maze.gridSize{
if (self.maze.down[x,y]) == true {
//code
}
if (self.maze.up[x,y]) == true {
//code
}
if (self.maze.left[x,y]) == true{
//code
}
if (self.maze.right[x,y]) == true {
//code
}
}//end of y forloop
}//end of x for loop
}//end of func didMove
}//end of GameScene class
Please let me know how I can call the mazeWall color sprite to the position of the "true" maze walls within the maze. Also let me know if you need me to include more of my code (my maze class, the grid class, maze generation, etc)...
Thanks in advance!