/// <summary> /// This function creates loops at random in the maze by joining corridors together. /// </summary> /// <param name="chance">Probability for a dead-end to join.</param> public void ConnectRandomNodes(float chance) { bool gen = false; for (int y = 0; y < grid.sizeY; ++y) { for (int x = 0; x < grid.sizeX; ++x) { int c = grid.Get(x, y); // If the cell is a dead-end if (c == Maze.LEFT_BIT || c == Maze.RIGHT_BIT || c == Maze.DOWN_BIT || c == Maze.UP_BIT) { // Connecting can fail, so we try to do it here and at the next iteration until it works. // In that case, gen is set to false. gen = gen | (Random.Range(0f, 1f) < chance); if (gen) { List <int> unavailableDirs = new List <int>(); if ((c & Maze.LEFT_BIT) == 0) { unavailableDirs.Add(Dir.LEFT); } if ((c & Maze.RIGHT_BIT) == 0) { unavailableDirs.Add(Dir.RIGHT); } if ((c & Maze.DOWN_BIT) == 0) { unavailableDirs.Add(Dir.DOWN); } if ((c & Maze.UP_BIT) == 0) { unavailableDirs.Add(Dir.UP); } if (unavailableDirs.Count > 0) { int dir = unavailableDirs[Random.Range(0, unavailableDirs.Count)]; int nx = x + Dir.vec2i[dir].X; int ny = y + Dir.vec2i[dir].Y; if (grid.Contains(nx, ny)) { grid.data[grid.EncodeLocation(x, y)] |= (1 << dir); grid.data[grid.EncodeLocation(nx, ny)] |= (1 << Dir.opposite[dir]); gen = false; } } } } } } }
public int GetCollisionValue(int x, int y) { if (_collisionMap.Contains(x, y)) { return(_collisionMap[x, y]); } else { return(defaultCollisionValue); } }
private int GetCell(Array2D <int> cells, int x, int y) { if (cells.Contains(x, y)) { int c = cells[x, y]; if (mapInput != null) { return(mapInput[cells[x, y]]); } return(c); } else { return(defaultInput); } }