Advertisement
Guest User

Untitled

a guest
May 16th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MazeConstructor : MonoBehaviour
  6. {
  7.  
  8.     public bool showDebug;
  9.     public GameObject Wall;
  10.     public GameObject Enemy;
  11.     public int SpawnAmount;
  12.     public GameObject Torch, Shovel, Avalanche;
  13.     private MazeDataGenerator dataGenerator;
  14.     public GameObject Player;
  15.  
  16.     public int[,] data
  17.     {
  18.         get; private set;
  19.     }
  20.  
  21.     private void Awake()
  22.     {
  23.         dataGenerator = new MazeDataGenerator();
  24.         data = new int[,]
  25.         {
  26.             {1,1,1},
  27.             {1,0,1},
  28.             {1,1,1}
  29.            
  30.         };
  31.     }
  32.  
  33.  
  34.     //Generates the Maze;
  35.     public void GenerateNewMaze(int sizeRows, int sizeCols)
  36.     {
  37.         if (sizeRows % 2 == 0 && sizeCols % 2 == 0)
  38.         {
  39.             Debug.LogError("Odd numbers work better for dungeon size.");
  40.  
  41.         }
  42.         data = dataGenerator.FromDimensions(sizeRows, sizeCols);
  43.  
  44.         PlaceExit();
  45.         PlacePlayer();
  46.         PlaceShovel();
  47.         PlaceTorch();
  48.         PlaceBlocks();
  49.     }
  50.  
  51.     //Places Traps
  52.     void PlaceTraps()
  53.     {
  54.         int spawned;
  55.         int[,] maze = data;
  56.  
  57.         int rMax = maze.GetUpperBound(0);
  58.         int cMax = maze.GetUpperBound(1);
  59.  
  60.         for (spawned = 0; spawned < SpawnAmount; spawned++)
  61.         {
  62.         A:
  63.             int x = Random.Range(0, GameController.srows);
  64.             int y = Random.Range(0, GameController.scols);
  65.             Transform ParentTransform = gameObject.transform;
  66.             Debug.Log(x + "+" + y);
  67.  
  68.             if (maze[x, y] == 0)
  69.             {
  70.                 //Debug.Log(maze[x, y]);
  71.                 Instantiate(Enemy, ParentTransform);
  72.                 Enemy.transform.position = new Vector3(x, 1.083f, y);
  73.  
  74.             }
  75.             else if (maze[x, y] == 1)
  76.             {
  77.                 spawned--;
  78.  
  79.             }
  80.  
  81.         }
  82.     }
  83.  
  84.     //Placing the Walls
  85.  
  86.     void PlaceBlocks()
  87.     {
  88.         int[,] maze = data;
  89.         int rMax = maze.GetUpperBound(0);
  90.         int cMax = maze.GetUpperBound(1);
  91.         for (int x = 0; x <= rMax; x++)
  92.         {
  93.             for (int z = 0; z <= cMax; z++)
  94.             {
  95.                 if (maze[x, z] == 1)
  96.                 {
  97.                     Transform ParentTransform = gameObject.transform;
  98.                     Instantiate(Wall, ParentTransform);
  99.                     Wall.transform.position = new Vector3(x, 0, z);
  100.                    
  101.                    
  102.                 }
  103.  
  104.             }
  105.         }
  106.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement