Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MazeConstructor : MonoBehaviour
- {
- public bool showDebug;
- public GameObject Wall;
- public GameObject Enemy;
- public int SpawnAmount;
- public GameObject Torch, Shovel, Avalanche;
- private MazeDataGenerator dataGenerator;
- public GameObject Player;
- public int[,] data
- {
- get; private set;
- }
- private void Awake()
- {
- dataGenerator = new MazeDataGenerator();
- data = new int[,]
- {
- {1,1,1},
- {1,0,1},
- {1,1,1}
- };
- }
- //Generates the Maze;
- public void GenerateNewMaze(int sizeRows, int sizeCols)
- {
- if (sizeRows % 2 == 0 && sizeCols % 2 == 0)
- {
- Debug.LogError("Odd numbers work better for dungeon size.");
- }
- data = dataGenerator.FromDimensions(sizeRows, sizeCols);
- PlaceExit();
- PlacePlayer();
- PlaceShovel();
- PlaceTorch();
- PlaceBlocks();
- }
- //Places Traps
- void PlaceTraps()
- {
- int spawned;
- int[,] maze = data;
- int rMax = maze.GetUpperBound(0);
- int cMax = maze.GetUpperBound(1);
- for (spawned = 0; spawned < SpawnAmount; spawned++)
- {
- A:
- int x = Random.Range(0, GameController.srows);
- int y = Random.Range(0, GameController.scols);
- Transform ParentTransform = gameObject.transform;
- Debug.Log(x + "+" + y);
- if (maze[x, y] == 0)
- {
- //Debug.Log(maze[x, y]);
- Instantiate(Enemy, ParentTransform);
- Enemy.transform.position = new Vector3(x, 1.083f, y);
- }
- else if (maze[x, y] == 1)
- {
- spawned--;
- }
- }
- }
- //Placing the Walls
- void PlaceBlocks()
- {
- int[,] maze = data;
- int rMax = maze.GetUpperBound(0);
- int cMax = maze.GetUpperBound(1);
- for (int x = 0; x <= rMax; x++)
- {
- for (int z = 0; z <= cMax; z++)
- {
- if (maze[x, z] == 1)
- {
- Transform ParentTransform = gameObject.transform;
- Instantiate(Wall, ParentTransform);
- Wall.transform.position = new Vector3(x, 0, z);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement