/// <summary> /// Creates basic wall bounds from the given grid of walls. /// </summary> private CreateWalls MakeWalls(Vector2 offset, bool[,] map, bool wrapHorizontal, bool wrapVertical) { //First create the wall bounds. List <RecBounds> walls = new List <RecBounds>(); //Go through and add in all the walls from the map. for (int i = 0; i < map.GetLength(0); ++i) { for (int j = 0; j < map.GetLength(1); ++j) { if (map[i, j]) { walls.Add(new RecBounds(new Vector3(i + offset.x, j + offset.y, 0.0f), new Vector3(1.0f, 1.0f, 0.0f))); } } } CreateWalls cw = new CreateWalls(LevelGen.GenSettings.WrapX, LevelGen.GenSettings.WrapY); foreach (RecBounds b in walls) { cw.AddWall(b); } cw.FinalizeWalls(LevelGen.Map); return(cw); }
// laying down the tiles then creating walls // void layTilesDown() { laydownTiles = gameObject.GetComponent <LaydownTiles>(); bool returnValue = laydownTiles.loadInLocations(this.listOfPositions, floor); if (returnValue) { // pass off to creating the walls // createWalls = gameObject.GetComponent <CreateWalls>(); createWalls.startCreatingWalls(this.listOfPositions); } }
/// <summary> /// Generates the level's walls and collision lines. /// </summary> /// <param name="isPreview">If true, then collision will not be calculated.</param> public void Generate(Vector2 wallOffset, bool isPreview) { Vector2 worldSize = new Vector2(LevelGen.Map.GetLength(0), LevelGen.Map.GetLength(1)); WorldConstants.Size = worldSize; CreateWalls walls = MakeWalls(wallOffset, LevelGen.Map, LevelGen.GenSettings.WrapX, LevelGen.GenSettings.WrapY); //Get the wall container. GameObject wallsContainer = WorldConstants.WallContainer; wallsToAnimate = new List <WallSheetData>(); //Create the wall objects. Creator.ChooseWallStyle(); if (!isPreview) { foreach (GameObject tempG in Creator.CreateWalls(LevelGen)) { wallsToAnimate.Add(tempG.GetComponent <WallSheetData>()); } } //Create the wall minimaps and collision. foreach (RecBounds b in walls.WallBounds) { WorldConstants.ColTracker.AddWall(b); Creator.CreateMinimapWall(b); } //Set up the mirrored wall collision and (if necessary) collision lines. if (!isPreview) { foreach (RecBounds b in walls.MirroredWallBounds) { Tracker.AddWall(b); } Tracker.Lines = walls.Lines; } }
/** * <summary>Initalizes the game. Creates the maze and adds the obstacles.</summary> */ public void InitializeGame() { EnableUserInput = false; //Initializes the static variables of the game. CurrentState = 0; CurrentStepCount = 0; UpdateStepCounter(); AllNodes = new Dictionary <int, NodeController>(); AllEdges = new List <EdgeController>(); AllButtons = new List <ButtonController>(); PlayerPath = new List <NodeController>(); //Set all possible colors (at least as many as NumberOfObstacles) Colors = new List <Color> { new Color(0, 1, 0), new Color(0, 0, 1), new Color(1, 0, 0), new Color(1, 1, 0) }; //Initializes the number of states. NumberOfStates = (int)Math.Pow(2, NumberOfButtons); //Moves the player to the start point. GameObject.Find("Ruby").GetComponent <RubyController>().SetPositionAndScale(); //Generates the labyrinth GameObject gameObject = Instantiate(aldousBroderAlgorithmPrefab); AldousBroderAlgorithm a = gameObject.GetComponent <AldousBroderAlgorithm>(); a.Initialize((int)Math.Floor(1 / ScaleMazeSize * 18), (int)Math.Floor(1 / ScaleMazeSize * 10)); if (CurrentLevelCount != -1) { GarbageCollectorGameObjects.Add(gameObject); } if (!IsBattleGameMode) { //Generates all obstacles gameObject = Instantiate(obstacleGenerationPrefab); ObstacleGeneration obstacleGeneration = gameObject.GetComponent <ObstacleGeneration>(); obstacleGeneration.InsertObstacles(); if (CurrentLevelCount != -1) { GarbageCollectorGameObjects.Add(gameObject); } //Calculates the optimal path and distance. gameObject = Instantiate(modifiedDijkstraAlgorithmPrefab); ModifiedDijkstraAlgorithm dijkstra = gameObject.GetComponent <ModifiedDijkstraAlgorithm>(); if (ScaleMazeSize == 0.5f) { dijkstra.Initialize(AllNodes[0], AllNodes[719]); } else { dijkstra.Initialize(AllNodes[0], AllNodes[179]); } dijkstra.CalculateModifiedDijkstraAlgorithm(); GameObject stepCounterText = GameObject.Find("OptimalSteps"); stepCounterText.GetComponent <TextMeshProUGUI>().text = "Optimal: " + dijkstra.ShortestDistance; OptimalStepCount = dijkstra.ShortestDistance; ShortestPath = dijkstra.ShortestPath; if (CurrentLevelCount != -1) { GarbageCollectorGameObjects.Add(gameObject); } } //Creates all walls of the maze. GameObject createWallsObject = Instantiate(createWallsPrefab); CreateWalls createWallsScript = createWallsObject.GetComponent <CreateWalls>(); createWallsScript.CreateAllWalls(); if (CurrentLevelCount != -1) { GarbageCollectorGameObjects.Add(createWallsObject); } if (IsBattleGameMode) { GenerateFreezer(); GameObject.Find("Opponent").GetComponent <OpponentController>().InitializeOpponent(); } //Enables the user input. EnableUserInput = true; }