コード例 #1
0
	protected void SetMazeCell(int row, int column, MazeCell cell){
		if (row >= 0 && column >= 0 && row < mMazeRows && column < mMazeColumns) {
			mMaze[row,column] = cell;
		}else{
			throw new System.ArgumentOutOfRangeException();
		}
	}
コード例 #2
0
ファイル: MazeDoor.cs プロジェクト: designerzim/unity-Maze
    public override void Initialize (MazeCell primary, MazeCell other, MazeDirection direction)
    {
        float localX = hinge.localScale.x;
        float localY = hinge.localScale.y;
        float localZ = hinge.localScale.z;

        base.Initialize(primary, other, direction);
        if (OtherSideOfDoor != null)
        {
            isMirrored = true;
            hinge.localScale = new Vector3(-localX, localY, localZ);
            Vector3 p = hinge.localPosition;
            p.x *= -1;
            hinge.localPosition = p;
        }

        for (int i = 0; i < transform.childCount; i++)
        {
            Transform child = transform.GetChild(i);
            if (child != hinge)
            {
                child.GetComponent<Renderer>().material = cell.room.settings.wallMaterial;
            }
        }
    }
コード例 #3
0
	public virtual void Initialize (MazeCell cell, MazeDirection direction = MazeDirection.North) {
		this.cell = cell;
		this.direction = direction;
		transform.parent = cell.transform;
		transform.localPosition = Vector3.zero;
		transform.localRotation = direction.ToRotation();
	}
コード例 #4
0
	public void Initialize (MazeCell cell) {
		base.Initialize (cell);
		Vector3 temp = new Vector3(0,6f,0);
		this.transform.position += temp;
		var killTimer = Random.Range (3, 5);
		this.killTime = System.DateTime.Now.AddSeconds (killTimer);
	}
コード例 #5
0
 public int FindAdjacentCellWall(MazeCell mazeCell)
 {
     if( mazeCell.row == this.row )
     {
         if( mazeCell.column < this.column)
         {
             return 0;
         }
         else
         {
             return 2;
         }
     }
     else
     {
         if( mazeCell.row < this.row )
         {
             return 1;
         }
         else
         {
             return 3;
         }
     }
 }
コード例 #6
0
ファイル: Maze.cs プロジェクト: RireMakar/Unity-Backtracking
 // creates a passage between the specified cells
 private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction)
 {
     MazePassage passage = Instantiate(passagePrefab) as MazePassage;
     passage.Initialize(cell, otherCell, direction);
     passage = Instantiate(passagePrefab) as MazePassage;
     passage.Initialize(otherCell, cell, direction.GetOpposite());
 }
コード例 #7
0
ファイル: Player.cs プロジェクト: thmundal/Blendertest
    void OnControllerColliderHit(ControllerColliderHit hit)
    {
        Rigidbody body = hit.collider.attachedRigidbody;

        MazeCell cell = hit.gameObject.GetComponentInParent<MazeCell>();
        if (cell == null)
            return;

        if(cell != currentCell)
        {
            if(currentCell != null)
                currentCell.OnPlayerExit();

            cell.OnPlayerEnter();
        }

        currentCell = cell;
        Vector3 transformDirection = new Vector3(Mathf.Round(transform.forward.x), 0f, Mathf.Round(transform.forward.z));
        IntVector2 direction = new IntVector2((int) transformDirection.x, (int) transformDirection.z);

        if(direction.x != 0 && direction.z != 0)
        {
            if (Random.Range(0, 1) == 1)
                direction.x = 0;
            else
                direction.z = 0;
        }

        MazeDirection mazeDirection = MazeDirections.FromIntVector2(direction);
        faceDirection = mazeDirection;
    }
コード例 #8
0
ファイル: Maze.cs プロジェクト: kleptodorf/CS3013
	private void CreateWall(MazeCell cell, MazeCell otherCell, MazeDirection direction){
		MazeWall wall = Instantiate (wallFab) as MazeWall;
		wall.Initialize (cell, otherCell, direction);
		if(otherCell != null){
			wall = Instantiate (wallFab) as MazeWall;
			wall.Initialize (otherCell, cell, direction.GetOpposite ());
		}
	}
コード例 #9
0
ファイル: Player.cs プロジェクト: gulfaraz/GGJ2016
	public void SetLocation (MazeCell cell) {
		if (currentCell != null) {
			currentCell.OnPlayerExited();
		}
		currentCell = cell;
		transform.localPosition = cell.transform.localPosition;
		currentCell.OnPlayerEntered();
	}
コード例 #10
0
    public void CreateDoor(MazeCell mazeCell)
    {
        int sideToCreateDoorOn = FindAdjacentCellWall(mazeCell);
        doors[sideToCreateDoorOn] = true;

        int oppositeDoorSide = (sideToCreateDoorOn + 2) % 4;
        mazeCell.doors[oppositeDoorSide] = true;
    }
	private MazePassage GetMazePassageBasedOnMaxDoorNumber (MazeCell cell) {
		if (cell.room != null && cell.room.Size > maze.cells.Length/(maze.MaxDoorNumber+2)  && doorNumber < maze.MaxDoorNumber) {
			doorNumber++;
			return maze.doorPrefab;
		}
		else
			return maze.passagePrefab;
	}
コード例 #12
0
	private List<MazeDoor> GetDoorsContainedAtCell(MazeCell cell) {
		var doors = new List<MazeDoor> ();
		foreach (var edge in cell.edges) {
			if (edge is MazeDoor)
				doors.Add ((MazeDoor)edge);
		}
		return doors;
	}
コード例 #13
0
ファイル: MazeCellEdge.cs プロジェクト: Zoltaris/MinotaurMaze
	public void Initialize (MazeCell cell, MazeCell otherCell, MazeDirection direction) {
		this.cell = cell;
		this.otherCell = otherCell;
		this.direction = direction;
		cell.SetEdge(direction, this);
		transform.parent = cell.transform;
		transform.localPosition = Vector3.zero;
		transform.localRotation = direction.ToRotation();
	}
コード例 #14
0
ファイル: Maze.cs プロジェクト: thmundal/Blendertest
 public void CreateWall(MazeCell cell, MazeCell otherCell, MazeDirection direction)
 {
     MazeWall wall = Instantiate(wallprefabs[Random.Range(0, wallprefabs.Length)]) as MazeWall;
     wall.Initialize(cell, otherCell, direction);
     if(otherCell != null)
     {
         wall = Instantiate(wallprefabs[Random.Range(0, wallprefabs.Length)]) as MazeWall;
         wall.Initialize(otherCell, cell, direction.GetOpposite());
     }
 }
コード例 #15
0
	public static List<MazeCell> GetSurroundingCellsInSameRoom(MazeCell cell, MazeCell otherCell, MazeRoom room) {
		var selectedCell = cell.room.RoomId == room.RoomId ? cell : otherCell;

		List<MazeCell> cells = new List<MazeCell>();
		foreach (IntVector2 vectors in MazeDirections.vectorsAllDirections) {
			IntVector2 coordinates = selectedCell.coordinates + vectors;
			var celly = selectedCell.room.cells.Find (x => x.coordinates == coordinates);
			if (celly != null)
				cells.Add (celly);
		}
		return cells;
	}
コード例 #16
0
	private int GetCellComplexity(MazeCell cell) {
		int complexity = 0;
		int counter = 0;
		bool edgeReached = false;

		while (!edgeReached) {
			var neighborhoodCells = MazeCell.GetAllNeighborhoodCellsInSameRoom (cell, counter++);
			complexity += neighborhoodCells.Count;
			if (neighborhoodCells.Count < 8) 
				edgeReached = true;	
		}
		return complexity;
	}
コード例 #17
0
	public static List<MazeCell> GetAllNeighborhoodCellsInSameRoom(MazeCell cell, int factor) {
		List<MazeCell> cells = new List<MazeCell>();
		foreach (IntVector2 vectors in MazeDirections.vectorsAllDirections) {
			IntVector2 tempVector = new IntVector2(0,0);
			for (int k = 0; k < factor+1; ++k)
				tempVector += vectors ;
			IntVector2 coordinates = cell.coordinates + tempVector;
			var celly = cell.room.cells.Find (x => x.coordinates == coordinates);
			if (celly != null)
				cells.Add (celly);
		}
		return cells;
	}
コード例 #18
0
ファイル: Maze.cs プロジェクト: sabrinagreenlee/JaneBound
 private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction)
 {
     MazePassage prefab = Random.value < doorProbability ? doorPrefab : passagePrefab;
     MazePassage passage = Instantiate(prefab) as MazePassage;
     passage.Initialize(cell, otherCell, direction);
     passage = Instantiate(prefab) as MazePassage;
     if (passage is MazeDoor) {
         otherCell.Initialize(CreateRoom(cell.room.settingsIndex));
     }
     else {
         otherCell.Initialize(cell.room);
     }
     passage.Initialize(otherCell, cell, direction.GetOpposite());
 }
コード例 #19
0
	public BasicMazeGenerator(int rows, int columns){
		mMazeRows = Mathf.Abs(rows);
		mMazeColumns = Mathf.Abs(columns);
		if (mMazeRows == 0) {
			mMazeRows = 1;
		}
		if (mMazeColumns == 0) {
			mMazeColumns = 1;
		}
		mMaze = new MazeCell[rows,columns];
		for (int row = 0; row < rows; row++) {
			for(int column = 0; column < columns; column++){
				mMaze[row,column] = new MazeCell();
			}
		}
	}
コード例 #20
0
ファイル: Maze.cs プロジェクト: julianstengaard/TwinSpirits
    public Maze(int width, int height)
    {
        this.width = width;
        this.height = height;

        cells = new MazeCell[width, height];

        //Fill the cells-array
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                cells[x,y] = new MazeCell(x, y);
            }
        }
    }
コード例 #21
0
 public IntVector2 GetLocation(MazeCell[,] cells)
 {
     MazeCell tMin=null;
     float minDist = Mathf.Infinity;
     Vector3 currentPos = transform.position;
     foreach(MazeCell c in cells)
     {
         float dist = Vector3.Distance(c.gameObject.transform.position, currentPos);
         if(dist<minDist)
         {
             tMin = c;
             minDist = dist;
         }
     }
     return tMin.coordinates;
 }
コード例 #22
0
    public override void Initialize(MazeCell primary, MazeCell other, MazeDirection direction)
    {
        base.Initialize(primary, other, direction);
        if (OtherSideOfDoor != null) {
            hinge.localScale = new Vector3(-1f, 1f, 1f);
            Vector3 p = hinge.localPosition;
            p.x = -p.x;
            hinge.localPosition = p;
        }

        for (int i = 0; i < transform.childCount; i++) {
            Transform child = transform.GetChild(i);
            if (child != hinge) {
                child.GetComponent<Renderer>().material = cell.room.settings.wallMaterial;
            }
        }
    }
コード例 #23
0
	private void Move1(MazeDirection direction,bool playsound)
    {        
          MazeCell nextcell =  Maze.instance.getLongNextMazeCell(currentCell, direction);
          directionKeyWating = MazeDirection.None;// khong 
          setRotation(direction);
          currentDirection = direction;
          if (nextcell != null)
          {              
              SetLocation(nextcell);
              targetCell = nextcell;
          }
        if(playsound)
        {
            SoundEngine.playLoop(SoundEngine.instance.move);
        }
          
    }
コード例 #24
0
    public GameObject realBoby;//using when
	public void SetLocation (MazeCell cell) {		
	
       // anim.Play("WALK");//.SetBool("ISWALK", true);
       // isCanmove = false;
       // int step =Mathf.Abs( cell.coordinates.x - currentCell.coordinates.x + cell.coordinates.z - currentCell.coordinates.z);
       // Debug.Log(step);
        //iTween.MoveTo(gameObject, iTween.Hash("position", cell.transform.localPosition, "easetype", iTween.EaseType.linear, "time", step*0.6f + 0.2f,"onComplete", "walkCompleted"));

		


        anim.Play("WALK");//.SetBool("ISWALK", true);
        isCanmove = false;
        float distance = Vector3.Distance(transform.position, cell.transform.position); ;// Mathf.Abs(cell.coordinates.x - currentCell.coordinates.x + cell.coordinates.z - currentCell.coordinates.z);
      //  Debug.Log(distance);
        iTween.MoveTo(gameObject, iTween.Hash("position", cell.transform.localPosition, "easetype", iTween.EaseType.linear, "time", distance * 0.4f , "onComplete", "walkCompleted"));
        
		
	}
コード例 #25
0
        private void Visit(MazeCell cell, bool[,] visited) {
            visited[cell.X, cell.Y] = true;

            while (true) {
                List<MazeLink> potentials = new List<MazeLink>(
                     from dir in Direction.Values
                     where cell[dir].OtherSide != null && !visited[cell[dir].OtherSide.X, cell[dir].OtherSide.Y]
                     orderby Guid.NewGuid()
                     select cell[dir]
                );

                if (potentials.Count == 0)
                    return;

                MazeLink link = potentials[0];
                link.Wall = false;
                Visit(link.OtherSide, visited);                
            }
        }
コード例 #26
0
	private List<MazeDoor> ExtractDoors (MazeCell[,] cells) {
		var allDoors = new List<MazeDoor>(); 
		foreach (var cell in cells) {
			
			var doors = GetDoorsContainedAtCell (cell);
			if (doors.Count () == 0 ) continue;
			foreach (var door in doors) {
				if (door.DoorDescription == Helpers.kDeletedDoorDescription) 
					continue;
				if (string.IsNullOrEmpty (door.DoorDescription))
					door.DoorDescription = CreateRoomName (door.cell.room.RoomId, door.otherCell.room.RoomId);
				door.cell.room.DoorsList.Add (door);
				door.Rooms = new MazeRoom[] {
					door.cell.room,
					door.otherCell.room 
				};
				allDoors.Add (door);
			}
		}
		return allDoors;
	}
コード例 #27
0
 private void moveContinue(MazeDirection _direction)// khi dang di chuyen ma co nut nhan
 {
     if((currentDirection == MazeDirection.North && _direction == MazeDirection.South ) ||
         (currentDirection == MazeDirection.South && _direction == MazeDirection.North ) ||
         (currentDirection == MazeDirection.East && _direction == MazeDirection.West ) ||
         (currentDirection == MazeDirection.West && _direction == MazeDirection.East ) )
     {
         
         MazeCell tempCurrentcell = Maze.instance.findCell(transform.position);
         MazeCell nextcell = currentCell;//.instance.getLongNextMazeCell(currentCell, _direction);
         // directionKeyWating = MazeDirection.None;// khong 
         setRotation(_direction);
         if (nextcell != null)
         {
             currentCell = tempCurrentcell;
             SetLocation(nextcell);
             targetCell = nextcell;               
         }
         // dung la
     }
     
    
 }
コード例 #28
0
    public static void GenMaze(int width, int height, string filePath, string pathFilePath)
    {
        Maze maze = new Maze();

        MazeCell[][] cellMatrix = maze.GenerateByPrim(height, width);
        //List<string> mazeData = new List<string>();
        for (int i = 0; i < height; i++)
        {
            string oneline = "";
            for (int j = 0; j < width; ++j)
            {
                MazeCell iter = cellMatrix[i][j];
                oneline += (iter.m_leftCanThrought == 1).ToString() + (iter.m_upCanThrought == 1) + (iter.m_rightCanThrought == 1) + (iter.m_downCanThrought == 1) + "\t";
            }
            //mazeData.Add(oneline);
            Debug.Log(oneline);
        }

        //File.WriteAllLines(fileName, mazeData.ToArray());

        Bitmap bitmap = Draw(cellMatrix, height, width);

        bitmap.Save(filePath);
        List <MazeCell> path = maze.GothroughMazeByBacktracing(cellMatrix, height, width);

        foreach (var iter in path)
        {
            Debug.Log("pathPoint " + iter.m_r + " " + iter.m_c);
        }
        Bitmap pathMap = DrawPath(cellMatrix, height, width, bitmap, path);

        pathMap.Save(pathFilePath);

        Debug.Log("Maze end " + filePath);
        Debug.Log("Maze end2 " + pathFilePath);
    }
コード例 #29
0
    private void InitializeMaze()
    {
        mazeCells = new MazeCell[mazeRows, mazeCols];

        for (int r = 0; r < mazeRows; r++)
        {
            for (int c = 0; c < mazeCols; c++)
            {
                mazeCells[r, c] = new MazeCell();

                mazeCells[r, c].floor      = Instantiate(wall, new Vector3(r * size, -(size / 2f), c * size), Quaternion.identity) as GameObject;
                mazeCells[r, c].floor.name = "Floor " + r + "," + c;
                mazeCells[r, c].floor.transform.Rotate(Vector3.right, 90f);

                if (c == 0)
                {
                    mazeCells[r, c].westWall      = Instantiate(wall, new Vector3(r * size, 0, c * size - size / 2f), Quaternion.identity) as GameObject;
                    mazeCells[r, c].westWall.name = "West Wall " + r + "," + c;
                }

                mazeCells[r, c].eastWall      = Instantiate(wall, new Vector3(r * size, 0, (c * size) + (size / 2f)), Quaternion.identity) as GameObject;
                mazeCells[r, c].eastWall.name = "East Wall " + r + "," + c;

                if (r == 0)
                {
                    mazeCells[r, c].northWall      = Instantiate(wall, new Vector3((r * size) - (size / 2f), 0, c * size), Quaternion.identity) as GameObject;
                    mazeCells[r, c].northWall.name = "North Wall " + r + "," + c;
                    mazeCells[r, c].northWall.transform.Rotate(Vector3.up * 90f);
                }

                mazeCells[r, c].southWall      = Instantiate(wall, new Vector3((r * size) + (size / 2f), 0, c * size), Quaternion.identity) as GameObject;
                mazeCells[r, c].southWall.name = "South Wall " + r + "," + c;
                mazeCells[r, c].southWall.transform.Rotate(Vector3.up * 90f);
            }
        }
    }
コード例 #30
0
    // gets a list of all valid neighbors for currentCell in the grid
    List <MazeCell> GetNeighbors(MazeCell currentCell, MazeCell[,] grid)
    {
        int             r         = currentCell.row;
        int             c         = currentCell.col;
        List <MazeCell> neighbors = new List <MazeCell>();

        if (isValidCell(r + 1, c, grid))
        {
            neighbors.Add(grid[r + 1, c]);
        }
        if (isValidCell(r - 1, c, grid))
        {
            neighbors.Add(grid[r - 1, c]);
        }
        if (isValidCell(r, c + 1, grid))
        {
            neighbors.Add(grid[r, c + 1]);
        }
        if (isValidCell(r, c - 1, grid))
        {
            neighbors.Add(grid[r, c - 1]);
        }
        return(neighbors);
    }
コード例 #31
0
    private void DoNextGenerationStep(List <MazeCell> activeCells)
    {
        int      currentIndex = activeCells.Count - 1;
        MazeCell currentCell  = activeCells[currentIndex];

        if (currentCell.IsFullyInitialized)
        {
            activeCells.RemoveAt(currentIndex);
            return;
        }
        MazeDirection direction   = currentCell.RandomUninitializedDirection;
        IntVector2    coordinates = currentCell.coordinates + direction.ToIntVector2();

        if (ContainsCoordinates(coordinates))
        {
            MazeCell neighbor = GetCell(coordinates);
            if (neighbor == null)
            {
                neighbor = CreateCell(coordinates);
                CreatePassage(currentCell, neighbor, direction);
                activeCells.Add(neighbor);
            }
            else if (currentCell.room.settingsIndex == neighbor.room.settingsIndex)
            {
                CreatePassageInSameRoom(currentCell, neighbor, direction);
            }
            else
            {
                CreateWall(currentCell, neighbor, direction);
            }
        }
        else
        {
            CreateWall(currentCell, null, direction);
        }
    }
コード例 #32
0
 public BasicMazeGenerator(int rows, int columns)
 {
     mMazeRows    = Mathf.Abs(rows);
     mMazeColumns = Mathf.Abs(columns);
     if (mMazeRows == 0)
     {
         mMazeRows = 1;
     }
     if (mMazeColumns == 0)
     {
         mMazeColumns = 1;
     }
     mMaze = new MazeCell[rows, columns];
     for (int row = 0; row < rows; row++)
     {
         for (int column = 0; column < columns; column++)
         {
             var mazeCell = new MazeCell();
             mazeCell.rowPos    = row;
             mazeCell.colPos    = column;
             mMaze[row, column] = mazeCell;
         }
     }
 }
コード例 #33
0
    private void CreatePassage(MazeCell cell, MazeCell otherCell, MazeDirection direction)
    {
        MazeDoor passage = Instantiate(doorPrefab) as MazeDoor;

        passage.Initialize(cell, otherCell, direction);
    }
コード例 #34
0
    private void DestroyMazeCellEdge(MazeCell cell, MazeDirection dir)
    {
        MazeCellEdge edge = cell.GetEdge(dir);

        Destroy(edge.gameObject);
    }
コード例 #35
0
 private void DestroyMazeCell(MazeCell cell)
 {
     Destroy(cell.gameObject);
 }
コード例 #36
0
ファイル: Traps.cs プロジェクト: PavanJakhu/Mouse-Maze
 public void SetLocation(MazeCell cell)
 {
     transform.position  = cell.transform.localPosition;
     transform.position += new Vector3(0.0f, 0.1f, 0.0f);
 }
コード例 #37
0
 public override void Initialize(MazeCell cell, MazeCell otherCell, MazeDirection direction)
 {
     base.Initialize(cell, otherCell, direction);
     wall.GetComponent <Renderer>().material = cell.room.settings.wallMaterial;
 }
コード例 #38
0
 public override void Initialize(MazeCell parentCell, MazeCell neighbourCell, MazeDirection direction)
 {
     base.Initialize(parentCell, neighbourCell, direction);
     wall.GetComponent <Renderer>().material = parentCell.room.settings.wallMaterial;
 }
コード例 #39
0
ファイル: MazeLoader.cs プロジェクト: jackt0310/Maze-Explorer
    //this creates a grid of walls, every cell will have a north, south, east, west wall
    private void InitializeMaze()
    {
        Color replace;

        switch (InventoryManagement.CurrentLevel)
        {
        case 1:
            replace = Color.white;
            break;

        case 2:
            replace = Color.red;
            break;

        case 3:
            replace = Color.blue;
            break;

        case 4:
            // Orange
            replace = new Color(255f / 255f, 69f / 255f, 0f / 255f);
            break;

        default:
            replace = Color.white;
            break;
        }

        // create 2d array to hold each maze cell
        mazeCells = new MazeCell[mazeRows, mazeColumns];
        // go through each cell and create the grid of walls
        for (int r = 0; r < mazeRows; r++)
        {
            for (int c = 0; c < mazeColumns; c++)
            {
                // create maze cell
                mazeCells [r, c] = new MazeCell();
                // change this depending on the size you want the hallway
                // make sure floors are big enough for this var
                size = 22f;

                // create floor for each cell
                mazeCells [r, c].floor      = Instantiate(floors, new Vector3(r * size, 0, c * size), Quaternion.identity) as GameObject;
                mazeCells [r, c].floor.name = "Floor " + r + "," + c;
                mazeCells [r, c].floor.transform.Rotate(Vector3.right, 90f);


                if (!arenaMode)
                {
                    // if first column create a west wall
                    if (c == 0)
                    {
                        mazeCells[r, c].westWall      = Instantiate(wall, new Vector3(r * size, 5, (c * size) - (size / 2f)), Quaternion.identity) as GameObject;
                        mazeCells[r, c].westWall.name = "West Wall " + r + "," + c;
                        mazeCells[r, c].westWall.GetComponent <Renderer>().material.SetColor("_Color", replace);
                    }

                    // create east wall for every cell, not west otherwise we would have overlaps
                    mazeCells[r, c].eastWall      = Instantiate(wall, new Vector3(r * size, 5, (c * size) + (size / 2f)), Quaternion.identity) as GameObject;
                    mazeCells[r, c].eastWall.name = "East Wall " + r + "," + c;
                    mazeCells[r, c].eastWall.GetComponent <Renderer>().material.SetColor("_Color", replace);

                    // if first row create a north wall
                    if (r == 0)
                    {
                        mazeCells[r, c].northWall      = Instantiate(wall, new Vector3((r * size) - (size / 2f), 5, c * size), Quaternion.identity) as GameObject;
                        mazeCells[r, c].northWall.name = "North Wall " + r + "," + c;
                        mazeCells[r, c].northWall.transform.Rotate(Vector3.up * 90f);
                        mazeCells[r, c].northWall.GetComponent <Renderer>().material.SetColor("_Color", replace);
                    }

                    // create a south wall for every cell, not north otherwise we would have overlaps
                    mazeCells[r, c].southWall      = Instantiate(wall, new Vector3((r * size) + (size / 2f), 5, c * size), Quaternion.identity) as GameObject;
                    mazeCells[r, c].southWall.name = "South Wall " + r + "," + c;
                    mazeCells[r, c].southWall.transform.Rotate(Vector3.up * 90f);
                    mazeCells[r, c].southWall.GetComponent <Renderer>().material.SetColor("_Color", replace);

                    //make door opening for end of maze, always in the same spot bottom right
                    if (r == mazeRows - 1 && c == mazeColumns - 1)
                    {
                        Destroy(mazeCells[r, c].southWall);
                    }
                }
                else
                {
                    // if first column create a west wall
                    if (c == 0)
                    {
                        mazeCells[r, c].westWall      = Instantiate(wall, new Vector3(r * size, 5, (c * size) - (size / 2f)), Quaternion.identity) as GameObject;
                        mazeCells[r, c].westWall.name = "West Wall " + r + "," + c;
                        mazeCells[r, c].westWall.GetComponent <Renderer>().material.SetColor("_Color", replace);
                    }

                    // if last column create an east wall
                    if (c == mazeColumns - 1)
                    {
                        mazeCells[r, c].eastWall      = Instantiate(wall, new Vector3(r * size, 5, (c * size) + (size / 2f)), Quaternion.identity) as GameObject;
                        mazeCells[r, c].eastWall.name = "East Wall " + r + "," + c;
                        mazeCells[r, c].eastWall.GetComponent <Renderer>().material.SetColor("_Color", replace);
                    }


                    // if first row create a north wall
                    if (r == 0)
                    {
                        mazeCells[r, c].northWall      = Instantiate(wall, new Vector3((r * size) - (size / 2f), 5, c * size), Quaternion.identity) as GameObject;
                        mazeCells[r, c].northWall.name = "North Wall " + r + "," + c;
                        mazeCells[r, c].northWall.transform.Rotate(Vector3.up * 90f);
                        mazeCells[r, c].northWall.GetComponent <Renderer>().material.SetColor("_Color", replace);
                    }

                    // if last row create a south wall
                    if (r == mazeRows - 1)
                    {
                        mazeCells[r, c].southWall      = Instantiate(wall, new Vector3((r * size) + (size / 2f), 5, c * size), Quaternion.identity) as GameObject;
                        mazeCells[r, c].southWall.name = "South Wall " + r + "," + c;
                        mazeCells[r, c].southWall.transform.Rotate(Vector3.up * 90f);
                        mazeCells[r, c].southWall.GetComponent <Renderer>().material.SetColor("_Color", replace);
                    }
                }
            }
        }
    }
コード例 #40
0
    private List <MazeCell> unvisitedNeighbors(MazeCell cell)
    {
        List <MazeCell> ret = new List <MazeCell>();
        MazeCell        tmp;

        if (cell.Row < ROWS - 1)
        {
            tmp = _maze.CellAt(cell.Row + 1, cell.Column, cell.Layer);
            if (!tmp.Visited)
            {
                ret.Add(tmp);
            }
        }

        if (cell.Row > 0)
        {
            tmp = _maze.CellAt(cell.Row - 1, cell.Column, cell.Layer);
            if (!tmp.Visited)
            {
                ret.Add(tmp);
            }
        }

        if (cell.Column < COLS - 1)
        {
            tmp = _maze.CellAt(cell.Row, cell.Column + 1, cell.Layer);
            if (!tmp.Visited)
            {
                ret.Add(tmp);
            }
        }

        if (cell.Column > 0)
        {
            tmp = _maze.CellAt(cell.Row, cell.Column - 1, cell.Layer);
            if (!tmp.Visited)
            {
                ret.Add(tmp);
            }
        }

        if (cell.Layer < LAYS - 1)
        {
            tmp = _maze.CellAt(cell.Row, cell.Column, cell.Layer + 1);
            if (!tmp.Visited)
            {
                ret.Add(tmp);
            }
        }

        if (cell.Layer > 0)
        {
            tmp = _maze.CellAt(cell.Row, cell.Column, cell.Layer - 1);
            if (!tmp.Visited)
            {
                ret.Add(tmp);
            }
        }

        return(ret);
    }
コード例 #41
0
    public List <SpawnGroup> GenerateMaze()
    {
        createLogicalMaze();
        GameObject mazeGO = (GameObject)GameObject.Instantiate(_data.mazePrefab, Vector3.zero, Quaternion.identity);

        Dictionary <int, List <Transform> > cellByWalls = new Dictionary <int, List <Transform> >();

        for (int i = 1; i < 6; ++i)
        {
            cellByWalls.Add(i, (new List <Transform>()));
        }

        //This uses Find heavily, so as a result it only makes sense to generate
        //the maze when loading.  It might not even make sense to do it this way
        //regardless
        for (int l = 0; l < LAYS; ++l)
        {
            for (int r = 0; r < ROWS; ++r)
            {
                for (int c = 0; c < COLS; ++c)
                {
                    MazeCell   cell         = _maze.CellAt(r, c, l);
                    GameObject cellGO       = mazeGO.transform.FindChild(string.Format(FIND_CELL_STR, l, r, c)).gameObject;
                    int        n            = 0;
                    bool       needElevator = false;
                    bool       useScoreMat  = false;

                    GameObject tmpGO = cellGO.transform.FindChild("Back").gameObject;
                    tmpGO.SetActive(cell.IsWallEnabled(MazeCell.WallSides.Back));
                    if (tmpGO.activeSelf)
                    {
                        ++n;
                        tmpGO.GetComponent <MeshRenderer>().material = _mcData.defaultMaterial;
                    }

                    tmpGO = cellGO.transform.FindChild("Front").gameObject;
                    tmpGO.SetActive(cell.IsWallEnabled(MazeCell.WallSides.Front));
                    if (tmpGO.activeSelf)
                    {
                        ++n;
                        tmpGO.GetComponent <MeshRenderer>().material = _mcData.defaultMaterial;
                    }

                    tmpGO = cellGO.transform.FindChild("Right").gameObject;
                    tmpGO.SetActive(cell.IsWallEnabled(MazeCell.WallSides.Right));
                    if (tmpGO.activeSelf)
                    {
                        ++n;
                        tmpGO.GetComponent <MeshRenderer>().material = _mcData.defaultMaterial;

                        useScoreMat = (Random.Range(0, 100) > 89);
                        if (useScoreMat)
                        {
                            GameObject scoreGO = GameObject.CreatePrimitive(PrimitiveType.Quad);
                            scoreGO.GetComponent <Collider>().enabled = false;
                            scoreGO.transform.parent        = tmpGO.transform;
                            scoreGO.transform.localRotation = Quaternion.Euler(90 * Vector3.up);
                            scoreGO.transform.localScale    = Vector3.one;
                            scoreGO.transform.localPosition = -0.71f * Vector3.right;
                            scoreGO.GetComponent <MeshRenderer>().material       = _mcData.scoreMaterial;
                            scoreGO.GetComponent <MeshRenderer>().receiveShadows = false;
                        }
                    }

                    tmpGO = cellGO.transform.FindChild("Left").gameObject;
                    tmpGO.SetActive(cell.IsWallEnabled(MazeCell.WallSides.Left));
                    if (tmpGO.activeSelf)
                    {
                        ++n;
                        tmpGO.GetComponent <MeshRenderer>().material = _mcData.defaultMaterial;
                        if (useScoreMat)
                        {
                            GameObject scoreGO = GameObject.CreatePrimitive(PrimitiveType.Quad);
                            scoreGO.GetComponent <Collider>().enabled = false;
                            scoreGO.transform.parent        = tmpGO.transform;
                            scoreGO.transform.localRotation = Quaternion.Euler(270 * Vector3.up);
                            scoreGO.transform.localScale    = Vector3.one;
                            scoreGO.transform.localPosition = 0.71f * Vector3.right;
                            scoreGO.GetComponent <MeshRenderer>().material       = _mcData.scoreMaterial;
                            scoreGO.GetComponent <MeshRenderer>().receiveShadows = false;
                        }
                    }

                    tmpGO = cellGO.transform.FindChild("Top").gameObject;
                    tmpGO.SetActive(cell.IsWallEnabled(MazeCell.WallSides.Top));
                    if (tmpGO.activeSelf)
                    {
                        ++n;
                        tmpGO.GetComponent <MeshRenderer>().material = _mcData.defaultMaterial;
                    }
                    else
                    {
                        needElevator = true;
                    }

                    tmpGO = cellGO.transform.FindChild("Bottom").gameObject;
                    tmpGO.SetActive(cell.IsWallEnabled(MazeCell.WallSides.Bottom));
                    if (tmpGO.activeSelf)
                    {
                        ++n;
                        tmpGO.GetComponent <MeshRenderer>().material = _mcData.defaultMaterial;
                        if (needElevator)
                        {
                            Transform  btm   = tmpGO.transform;
                            GameObject eleGO = (GameObject)GameObject.Instantiate(_data.elevatorTriggerPrefab, btm.position, Quaternion.identity);
                            eleGO.name = "Elevator" + btm.position.ToString();
                        }
                    }

                    if (cell == _endCell)
                    {
                        AudioSource src = cellGO.AddComponent <AudioSource>();
                        src.clip        = _data.endCellSound;
                        src.spread      = 0.0f;
                        src.rolloffMode = AudioRolloffMode.Linear;
                        src.maxDistance = 32.0f;
                        src.loop        = true;
                        src.volume      = 0.4f;
                        src.Play();
                    }
                    cellByWalls[n].Add(cellGO.transform);
                }
            }
        }

        disableDuplicateWalls(mazeGO);

        return(createSpawnGroups(cellByWalls));
    }
コード例 #42
0
ファイル: Maze.cs プロジェクト: gulfaraz/GGJ2016
	private void CreatePassageInSameRoom (MazeCell cell, MazeCell otherCell, MazeDirection direction) {
		MazePassage passage = Instantiate(passagePrefab) as MazePassage;
		passage.Initialize(cell, otherCell, direction);
		passage = Instantiate(passagePrefab) as MazePassage;
		passage.Initialize(otherCell, cell, direction.GetOpposite());
		if (cell.room != otherCell.room) {
			MazeRoom roomToAssimilate = otherCell.room;
			cell.room.Assimilate(roomToAssimilate);
			rooms.Remove(roomToAssimilate);
			Destroy(roomToAssimilate);
		}
	}
コード例 #43
0
ファイル: MazeRoom.cs プロジェクト: sabrinagreenlee/JaneBound
 public void Add(MazeCell cell)
 {
     cell.room = this;
     cells.Add(cell);
 }
コード例 #44
0
 public void Generate(MazeCell current, Transform transform)
 {
     this.transform.parent        = transform;
     this.transform.localPosition = new Vector3(current.coordX, 0.5f, current.coordY);
 }
コード例 #45
0
ファイル: MazeMap.cs プロジェクト: helluvamatt/MazeGame
        public void Generate()
        {
            var rng = new Random();

            // Randomized iterative depth-first traversal used to create labyrinths
            var cells = new MazeCell[_VPathCount, _HPathCount];

            for (int y = 0; y < _VPathCount; y++)
            {
                for (int x = 0; x < _HPathCount; x++)
                {
                    cells[y, x] = new MazeCell(x, y);
                }
            }
            var stack = new Stack <MazeCell>();

            stack.Push(cells[0, 0]);

            while (stack.Any())
            {
                var pathstart = stack.Pop();
                var pathstack = new Stack <MazeCell>();
                pathstack.Push(pathstart);

                while (pathstack.Any())
                {
                    var cell = pathstack.Pop();
                    cell.Visited = true;

                    var neighbors = new List <MazeCell>();
                    if (cell.X > 0 && !cells[cell.Y, cell.X - 1].Visited)
                    {
                        neighbors.Add(cells[cell.Y, cell.X - 1]);
                    }
                    if (cell.Y > 0 && !cells[cell.Y - 1, cell.X].Visited)
                    {
                        neighbors.Add(cells[cell.Y - 1, cell.X]);
                    }
                    if (cell.X < _HPathCount - 1 && !cells[cell.Y, cell.X + 1].Visited)
                    {
                        neighbors.Add(cells[cell.Y, cell.X + 1]);
                    }
                    if (cell.Y < _VPathCount - 1 && !cells[cell.Y + 1, cell.X].Visited)
                    {
                        neighbors.Add(cells[cell.Y + 1, cell.X]);
                    }

                    if (neighbors.Any())
                    {
                        var neighbor = neighbors[rng.Next(neighbors.Count)];
                        if (neighbor.X == cell.X && neighbor.Y == cell.Y - 1)
                        {
                            neighbor.South = false; cell.North = false;
                        }
                        else if (neighbor.X == cell.X && neighbor.Y == cell.Y + 1)
                        {
                            neighbor.North = false; cell.South = false;
                        }
                        else if (neighbor.X == cell.X - 1 && neighbor.Y == cell.Y)
                        {
                            neighbor.East = false; cell.West = false;
                        }
                        else if (neighbor.X == cell.X + 1 && neighbor.Y == cell.Y)
                        {
                            neighbor.West = false; cell.East = false;
                        }

                        stack.Push(neighbor);
                        pathstack.Push(neighbor);
                    }
                }
            }

            Layout(rng, cells);
        }
コード例 #46
0
ファイル: AStar.cs プロジェクト: nbathras/Maze
    public static List <MazeCell> RunAStar(MazeCell start, MazeCell end)
    {
        Node startNode = new Node(null, start);

        startNode.g = startNode.h = startNode.f = 0;
        Node endNode = new Node(null, end);

        endNode.g = endNode.h = endNode.f = 0;

        List <Node> openList   = new List <Node>();
        List <Node> closedList = new List <Node>();

        openList.Add(startNode);

        while (openList.Count > 0)
        {
            // Get the current node
            Node currentNode  = openList[0];
            int  currentIndex = 0;
            for (int i = 0; i < openList.Count; i++)
            {
                if (openList[i].f < currentNode.f)
                {
                    currentNode  = openList[i];
                    currentIndex = i;
                }
            }

            closedList.Add(openList[currentIndex]);
            openList.RemoveAt(currentIndex);

            if (currentNode.Equals(endNode))
            {
                List <MazeCell> path    = new List <MazeCell>();
                Node            current = currentNode;
                while (current != null)
                {
                    path.Add(current.position);
                    current = current.parent;
                }
                path.Reverse();
                return(path);
            }

            List <MazeCell> childrenMazeCell = currentNode.position.getConnections();
            List <Node>     children         = new List <Node>();

            foreach (MazeCell mazeCell in childrenMazeCell)
            {
                children.Add(new Node(currentNode, mazeCell));
            }

            foreach (Node child in children)
            {
                if (closedList.Contains(child))
                {
                    continue;
                }

                child.g = currentNode.g + 1;
                child.h = Mathf.Pow((child.position.GetX() - endNode.position.GetX()), 2) + Mathf.Pow((child.position.GetY() - endNode.position.GetY()), 2);
                child.f = child.g + child.h;

                bool shouldAddChild = true;
                foreach (Node openNode in openList)
                {
                    if (child.Equals(openNode) && child.g > openNode.g)
                    {
                        shouldAddChild = false;
                        break;
                    }
                }

                if (shouldAddChild)
                {
                    openList.Add(child);
                }
            }
        }

        return(null);
    }
コード例 #47
0
    private void CreateWall(MazeCell cell, MazeCell otherCell, MazeDirection direction)
    {
        MazeWall wall = Instantiate(wallPrefab) as MazeWall;

        wall.Initialize(cell, otherCell, direction);
    }
コード例 #48
0
ファイル: MazeSpawner.cs プロジェクト: paxer/unity_radom_maze
    void Start()
    {
        RandomSeed = Random.Range(Int32.MinValue, Int32.MaxValue);

        if (!FullRandom)
        {
            Random.seed = RandomSeed;
        }
        switch (Algorithm)
        {
        case MazeGenerationAlgorithm.PureRecursive:
            mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns);
            break;

        case MazeGenerationAlgorithm.RecursiveTree:
            mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns);
            break;

        case MazeGenerationAlgorithm.RandomTree:
            mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns);
            break;

        case MazeGenerationAlgorithm.OldestTree:
            mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns);
            break;

        case MazeGenerationAlgorithm.RecursiveDivision:
            mMazeGenerator = new DivisionMazeGenerator(Rows, Columns);
            break;
        }
        mMazeGenerator.GenerateMaze();

        bool isGoalGenerated = false;

        for (int row = 0; row < Rows; row++)
        {
            for (int column = 0; column < Columns; column++)
            {
                float      x    = column * (CellWidth + (AddGaps?.2f : 0));
                float      z    = row * (CellHeight + (AddGaps?.2f : 0));
                MazeCell   cell = mMazeGenerator.GetMazeCell(row, column);
                GameObject tmp;
                tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject;
                tmp.transform.parent = transform;
                if (cell.WallRight)
                {
                    tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject;        // right
                    tmp.transform.parent = transform;
                }
                if (cell.WallFront)
                {
                    tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;        // front
                    tmp.transform.parent = transform;
                }
                if (cell.WallLeft)
                {
                    tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject;        // left
                    tmp.transform.parent = transform;
                }
                if (cell.WallBack)
                {
                    tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject;        // back
                    tmp.transform.parent = transform;
                }
                if (cell.IsGoal && GoalPrefab != null && !isGoalGenerated)
                {
                    isGoalGenerated      = true;
                    tmp                  = Instantiate(GoalPrefab, new Vector3(x, 1, z), Quaternion.Euler(0, 0, 0)) as GameObject;
                    tmp.transform.parent = transform;
                }
            }
        }
        if (Pillar != null)
        {
            for (int row = 0; row < Rows + 1; row++)
            {
                for (int column = 0; column < Columns + 1; column++)
                {
                    float      x   = column * (CellWidth + (AddGaps?.2f : 0));
                    float      z   = row * (CellHeight + (AddGaps?.2f : 0));
                    GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject;
                    tmp.transform.parent = transform;
                }
            }
        }
    }
コード例 #49
0
 public void Activate(MazeCell cell)
 {
     SetLocation(cell);
     origin = cell;
 }
コード例 #50
0
    private IEnumerator BeginGame()
    {
        //Instantiate Maze
        TogglePause(false);
        Camera.main.clearFlags = CameraClearFlags.Skybox;
        Camera.main.rect       = new Rect(0f, 0f, 1f, 1f);
        mazeInstance           = Instantiate(mazePrefab) as Maze;
        yield return(StartCoroutine(mazeInstance.Generate()));

        //Instantiate Player
        playerInstance = Instantiate(playerPrefab) as Player;
        IntVector2 coord       = new IntVector2(0, 0);
        MazeCell   currentCell = mazeInstance.GetCell(coord);
        MazeCell   safeCell    = mazeInstance.GetSafeCell();
        MazeCell   playerCell  = currentCell;
        int        maxDistance = 0;
        int        sizeX       = mazeInstance.size.x;
        int        sizeZ       = mazeInstance.size.z;

        for (int i = 0; i < sizeX; ++i)
        {
            coord.x = i;
            for (int j = 0; j < sizeZ; ++j)
            {
                coord.z     = j;
                currentCell = mazeInstance.GetCell(coord);
                int distance = GetManhattanDistance(currentCell, safeCell);
                if (distance > maxDistance)
                {
                    maxDistance = distance;
                    playerCell  = currentCell;
                }
            }
        }
        playerInstance.Activate(playerCell);
        playerCell.SetMaterialColor(Color.blue);
        playerInstance.treasureText = treasureText;

        //Instantiate Enemy
        enemyInstance = Instantiate(enemyPrefab) as Enemy;
        List <MazeCell> doors = mazeInstance.GetDoorCells();

        coord       = new IntVector2(0, 0);
        currentCell = mazeInstance.GetCell(coord);
        MazeCell enemyCell = currentCell;

        maxDistance = 0;
        sizeX       = mazeInstance.size.x;
        sizeZ       = mazeInstance.size.z;
        for (int i = 0; i < sizeX; ++i)
        {
            coord.x = i;
            for (int j = 0; j < sizeZ; ++j)
            {
                coord.z     = j;
                currentCell = mazeInstance.GetCell(coord);
                int distance = GetManhattanDistance(currentCell, playerCell);
                if (distance > maxDistance)
                {
                    maxDistance = distance;
                    enemyCell   = currentCell;
                }
            }
        }
        enemyInstance.Activate(enemyCell, doors);

        rockText.text = "Rocks: " + rockCount.ToString();

        gameStarted = true;
    }
コード例 #51
0
ファイル: MazeWall.cs プロジェクト: Ariapaws/CS4350-Wormhole
 public override void Initialize(MazeCell cell, MazeCell otherCell, MazeDirection direction)
 {
     base.Initialize(cell, otherCell, direction);
     //wall.GetComponent<MeshRenderer>().material.mainTexture = cell.room.settings.wallMaterial.mainTexture;
 }
コード例 #52
0
 public int GetManhattanDistance(MazeCell a, MazeCell b)
 {
     return(Mathf.Abs(a.coordinates.x - b.coordinates.x) + Mathf.Abs(a.coordinates.z - b.coordinates.z));
 }
コード例 #53
0
ファイル: MazeWall.cs プロジェクト: Confirm4Crit/Maze
 public override void Initialize(MazeCell cell, MazeCell otherCell, MazeDirection direction)
 {
     base.Initialize(cell, otherCell, direction);
     wall.GetComponent<Renderer>().material = cell.room.settings.wallMaterial;
 }
コード例 #54
0
    private void InitializeMaze()
    {
        mazeCells = new MazeCell[mazeRows, mazeColumns];

        for (int r = 0; r < mazeRows; r++)
        {
            for (int c = 0; c < mazeColumns; c++)
            {
                mazeCells [r, c] = new MazeCell();

                // For now, use the same wall object for the floor!
                //		mazeCells [r, c] .floor = Instantiate (wall, new Vector3 (r*size, -(size/2f), c*size), Quaternion.identity) as GameObject;
                //		mazeCells [r, c] .floor.name = "Floor " + r + "," + c;
                //		mazeCells [r, c] .floor.transform.Rotate (Vector3.right, 90f);

                if (c == 0)
                {
                    mazeCells[r, c].westWall       = Instantiate(wall, new Vector3(r * size, 0, (c * size) - (size / 2f)), Quaternion.identity) as GameObject;
                    mazeCells [r, c].westWall.name = "West Wall " + r + "," + c;

                    //mazeCells [r, c].isWallWest = true;
                }

                mazeCells [r, c].eastWall      = Instantiate(wall, new Vector3(r * size, 0, (c * size) + (size / 2f)), Quaternion.identity) as GameObject;
                mazeCells [r, c].eastWall.name = "East Wall " + r + "," + c;

                //mazeCells [r, c].isWallEast = true;

//				if (c > 0) {
//					if (mazeCells [r, c - 1].isWallEast) {
//						mazeCells [r, c].isWallWest = true;
//					}
//				}

                if (r == 0)
                {
                    mazeCells [r, c].northWall      = Instantiate(wall, new Vector3((r * size) - (size / 2f), 0, c * size), Quaternion.identity) as GameObject;
                    mazeCells [r, c].northWall.name = "North Wall " + r + "," + c;
                    mazeCells [r, c].northWall.transform.Rotate(Vector3.up * 90f);

                    //mazeCells [r, c].isWallNorth = true;
                }

                mazeCells [r, c].southWall      = Instantiate(wall, new Vector3((r * size) + (size / 2f), 0, c * size), Quaternion.identity) as GameObject;
                mazeCells [r, c].southWall.name = "South Wall " + r + "," + c;
                mazeCells [r, c].southWall.transform.Rotate(Vector3.up * 90f);

                //mazeCells [r, c].isWallSouth = true;

//				if (r > 0) {
//					if (mazeCells [r - 1, c].isWallSouth) {
//						mazeCells [r, c].isWallNorth = true;
//					}
//				}
            }
        }



        //ShowMazeCellWallBoolData ("initialize");
        //ShowMazeCellWallData ("initialize");
    }
コード例 #55
0
ファイル: Maze.cs プロジェクト: DaneLinsky/ZombieMaze
    private void DoFirstGenerationStep(List <MazeCell> activeCells)
    {
        MazeCell newCell = CreateCell(RandomCoordinates);

        activeCells.Add(newCell);
    }
コード例 #56
0
ファイル: MazeManager.cs プロジェクト: GustavoPChaves/Pacman
    private static void SetupRightAndLeftNeighborOfMazeCell(List <MazeCell> mazeCells, string line, int i, MazeCell newMazeCell)
    {
        // check for left-right neighbor
        if (HasLeftNeighborOnPosition(line, i))
        {
            // assign each MazeCell to the corresponding side of other MazeCell
            newMazeCell.left = mazeCells[mazeCells.Count - 1];
            mazeCells[mazeCells.Count - 1].right = newMazeCell;

            // adjust adjcent MazeCell counts of each MazeCell
            newMazeCell.AdjacentCount++;
            mazeCells[mazeCells.Count - 1].AdjacentCount++;
        }
    }
コード例 #57
0
 public MazeGameCellViewModel(MazeCell cell) : base(cell, false)
 {
 }
コード例 #58
0
 public void Initialize(MazeCell cell)
 {
     transform.parent        = cell.transform;
     transform.localPosition = Vector3.zero;
 }
コード例 #59
0
    private void Start()
    {
        music         = GameObject.Find("audBGM").GetComponent <BGM>();
        music.fadeOut = true;
        //s = GameObject.FindObjectsOfType<Spawn>();
        sc = GameObject.FindObjectsOfType <SpawnC>();
        sm = GameObject.FindObjectsOfType <SpawnM>();
        PhotonNetwork.isMessageQueueRunning  = true;
        PhotonNetwork.automaticallySyncScene = true;

        // instantiate the maze
        mazeInstance = Instantiate(mazePrefab) as Maze;
        mazeSize     = mazeInstance.size.x - 4;

        // puzzle rooms
        for (int p = 0; p < 6; p++)
        {
            allPuzzleTypes.Add(p);
        }

        for (int p = 0; p < 3; p++)
        {
            float rseed     = Mathf.PerlinNoise(mazeInstance.getMazeGenerationNumber() * p, p / mazeInstance.getMazeGenerationNumber());
            int   getPuzzle = (int)(rseed * allPuzzleTypes.Count);
            activePuzzleTypes.Add(allPuzzleTypes[getPuzzle]);
            allPuzzleTypes.RemoveAt(getPuzzle);
        }

        SpawnMaze();

        // setup spawn locations
        // only the master needs to do this
        MazeCell[,] cellsInMaze = mazeInstance.getMazeCells();
        //if (PhotonNetwork.isMasterClient){
        // modify the spawn locations of the players
        // random coordinates, rerandom if its in a puzzle room
        bool goodLocation = false;
        int  locX         = 0;
        int  locZ         = 0;

        while (goodLocation == false)
        {
            locX = Random.Range(0, mazeSize + 3);
            locZ = Random.Range(0, mazeSize + 3);
            if (cellsInMaze[locX, locZ].transform.GetChild(0).GetComponent <Renderer>().material != puzzleRoomMat)
            {
                goodLocation = true;
            }
        }
        sc[0].transform.position = cellsInMaze[locX, locZ].transform.position;

        // then modify mouse locations, same thing as above except an extra range check because we dont want mice spawning too close to the cat
        for (int i = 0; i < sm.Length; i++)
        {
            goodLocation = false;
            while (goodLocation == false)
            {
                locX = Random.Range(0, mazeSize + 3);
                locZ = Random.Range(0, mazeSize + 3);
                if (cellsInMaze[locX, locZ].transform.GetChild(0).GetComponent <Renderer>().material != puzzleRoomMat && Vector3.Distance(sc[0].transform.position, cellsInMaze[locX, locZ].transform.position) > 10f)
                {
                    goodLocation = true;
                }
            }
            sm[i].transform.position = cellsInMaze[locX, locZ].transform.position;
        }
        //	}
        int numSpawnLocations = (int)Mathf.Sqrt((mazeSize + 4) / 2f);
        int interval          = (int)((mazeSize + 4) / numSpawnLocations);

        // spawn locations for monsters
        for (int i = 0; i < numSpawnLocations; i++)
        {
            for (int j = 0; j < numSpawnLocations; j++)
            {
                MazeCell     spawnCell = cellsInMaze[interval * i + 5, interval *j + 5];
                Vector3      spawnPos  = spawnCell.transform.position;
                Quaternion   spawnRot  = new Quaternion(0f, 0f, 0f, 0f);
                MonsterSpawn newSpawn  = Instantiate(mSpawn) as MonsterSpawn;
                mSpawn.transform.position = spawnPos;
                mSpawn.transform.rotation = spawnRot;
                monsterSpawnList.Add(newSpawn);
            }
        }
        Debug.Log("finished editng spawns");
        // spawn basic monsters and elite monsters
        for (int i = 0; i < monsterSpawnList.Count; i++)
        {
            SpawnMonsters(i);
        }
        // spawn boss monster
        SpawnBoss();

        SpawnKeysAndChests();
        // spawn 5 powerups
        for (int i = 0; i < 5; i++)
        {
            SpawnPowerup();
        }

        // if applicable, get ball/target lists
        if (activePuzzleTypes.IndexOf(3) >= 0 && activePuzzleTypes.IndexOf(3) <= 3)
        {
            ballArray   = GameObject.FindGameObjectsWithTag("Ball");
            targetArray = GameObject.FindGameObjectsWithTag("Target");
        }

        // finally, spawn the players
        if (GameObject.Find("TeamSelectionOBJ").GetComponent <teamselectiondata>().playertype == 0)
        {
            SpawnCat();
        }
        else
        {
            SpawnMouse();
        }


        GameObject.Find("Timer").GetComponent <Timer>().enabled = true;
    }
コード例 #60
0
    void Start()
    {
        if (!FullRandom)
        {
            Random.seed = RandomSeed;
        }
        switch (Algorithm)
        {
        case MazeGenerationAlgorithm.PureRecursive:
            mMazeGenerator = new RecursiveMazeGenerator(Rows, Columns);
            break;

        case MazeGenerationAlgorithm.RecursiveTree:
            mMazeGenerator = new RecursiveTreeMazeGenerator(Rows, Columns);
            break;

        case MazeGenerationAlgorithm.RandomTree:
            mMazeGenerator = new RandomTreeMazeGenerator(Rows, Columns);
            break;

        case MazeGenerationAlgorithm.OldestTree:
            mMazeGenerator = new OldestTreeMazeGenerator(Rows, Columns);
            break;

        case MazeGenerationAlgorithm.RecursiveDivision:
            mMazeGenerator = new DivisionMazeGenerator(Rows, Columns);
            break;
        }
        mMazeGenerator.GenerateMaze();
        for (int row = 0; row < Rows; row++)
        {
            for (int column = 0; column < Columns; column++)
            {
                float      x    = column * (CellWidth + (AddGaps ? 0.2f : 0));
                float      z    = row * (CellHeight + (AddGaps ? 0.2f : 0));
                MazeCell   cell = mMazeGenerator.GetMazeCell(row, column);
                GameObject tmp;
                tmp = Instantiate(Floor, new Vector3(x, 0, z), Quaternion.Euler(0, 0, 0)) as GameObject;
                tmp.transform.parent = transform;
                if (cell.WallRight)
                {
                    tmp = Instantiate(Wall, new Vector3(x + CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject;                       // right
                    tmp.transform.parent = transform;
                }
                if (cell.WallFront)
                {
                    tmp = Instantiate(Wall, new Vector3(x, 0, z + CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 0, 0)) as GameObject;                       // front
                    tmp.transform.parent = transform;
                }
                if (cell.WallLeft)
                {
                    tmp = Instantiate(Wall, new Vector3(x - CellWidth / 2, 0, z) + Wall.transform.position, Quaternion.Euler(0, 270, 0)) as GameObject;                       // left
                    tmp.transform.parent = transform;
                }
                if (cell.WallBack)
                {
                    tmp = Instantiate(Wall, new Vector3(x, 0, z - CellHeight / 2) + Wall.transform.position, Quaternion.Euler(0, 180, 0)) as GameObject;                       // back
                    tmp.transform.parent = transform;
                }

                /*
                 * if (cell.IsGoal && GoalPrefab != null) {
                 *      tmp = Instantiate (GoalPrefab, new Vector3 (x, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject;
                 *      tmp.transform.parent = transform;
                 * }
                 * if (cell.IsGoal && GoalPrefab2 != null) {
                 *      tmp = Instantiate (GoalPrefab2, new Vector3 (1, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject;
                 *      tmp.transform.parent = transform;
                 * }
                 * if (cell.IsGoal && GoalPrefab3 != null) {
                 *      tmp = Instantiate (GoalPrefab3, new Vector3 (2, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject;
                 *      tmp.transform.parent = transform;
                 * }
                 * if (cell.IsGoal && GoalPrefab4 != null) {
                 *      tmp = Instantiate (GoalPrefab4, new Vector3 (3, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject;
                 *      tmp.transform.parent = transform;
                 * }
                 * if (cell.IsGoal && GoalPrefab5 != null) {
                 *      tmp = Instantiate (GoalPrefab5, new Vector3 (4, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject;
                 *      tmp.transform.parent = transform;
                 * }
                 * if (cell.IsGoal && GoalPrefab6 != null) {
                 *      tmp = Instantiate (GoalPrefab6, new Vector3 (5, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject;
                 *      tmp.transform.parent = transform;
                 * }
                 * if (cell.IsGoal && GoalPrefab7 != null) {
                 *      tmp = Instantiate (GoalPrefab7, new Vector3 (6, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject;
                 *      tmp.transform.parent = transform;
                 * }
                 * if (cell.IsGoal && GoalPrefab8 != null) {
                 *      tmp = Instantiate (GoalPrefab8, new Vector3 (7, 1, z), Quaternion.Euler (0, 0, 0)) as GameObject;
                 *      tmp.transform.parent = transform;
                 * }
                 */
            }
        }
        bool[] usado = new bool[Columns * Rows + 9];
        usado [0] = true;

        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 1; j++)
            {
                int c = Random.Range(0, Columns);
                int r = Random.Range(0, Rows);

                while (usado [c * Rows + r])
                {
                    c = Random.Range(0, Columns);                  // + CellWidth / 2.0f;
                    r = Random.Range(0, Rows);                     // + CellHeight / 2.0f;
                }


                int w = (int)(c * CellWidth);                // + CellWidth / 2.0f;
                int h = (int)(r * CellHeight);               // + CellHeight / 2.0f;

                usado [(int)(c * Rows + r)] = true;

                GameObject tmp = Instantiate(Monedas [i], new Vector3(h, 1, w), Quaternion.Euler(0, 0, 0)) as GameObject;
            }
        }

        if (Pillar != null)
        {
            for (int row = 0; row < Rows + 1; row++)
            {
                for (int column = 0; column < Columns + 1; column++)
                {
                    float      x   = column * (CellWidth + (AddGaps?0.2f:0));
                    float      z   = row * (CellHeight + (AddGaps?0.2f:0));
                    GameObject tmp = Instantiate(Pillar, new Vector3(x - CellWidth / 2, 0, z - CellHeight / 2), Quaternion.identity) as GameObject;
                    tmp.transform.parent = transform;
                }
            }
        }
    }