/// <summary> /// Check if a 2x2 chunk would fit /// </summary> /// <param name="x">X position to check (tiles)</param> /// <param name="y">Y position to check (tiles)</param> /// <param name="checkedList">Reference list of tiles already checked</param> /// <param name="tileManager">Tile Manager</param> /// <returns>True if chunk fits</returns> private static bool CheckFor2x2(int x, int y, ref List <Tuple <int, int> > checkedList, TileManager tileManager) { //Check if tiles solid and 1x2 area isn't in the checked list //Check if current tile okay if (!tileManager.GetTile(x, y)) { return(false); } //Check if other tiles okay if (!tileManager.GetTile(x + 1, y)) { return(false); } if (!tileManager.GetTile(x, y + 1)) { return(false); } if (!tileManager.GetTile(x + 1, y + 1)) { return(false); } //Check if tiles are valid if (checkedList.Any(t => (t.Item1 >= x && t.Item1 < x + 2) && (t.Item2 >= y && t.Item2 < y + 2))) { return(false); } return(true); }
/// <summary> /// Check if a 1x2 chunk would fit /// </summary> /// <param name="x">X position to check (tiles)</param> /// <param name="y">Y position to check (tiles)</param> /// <param name="checkedList">Reference list of tiles already checked</param> /// <param name="tileManager">Tile Manager</param> /// <returns>True if chunk fits</returns> private static bool CheckFor1x2(int x, int y, ref List<Tuple<int, int>> checkedList, TileManager tileManager) { //Check if tiles solid and 1x2 area isn't in the checked list //Check if current tile okay if (!tileManager.GetTile(x, y)) return false; //Check if next tile okay if (!tileManager.GetTile(x, y + 1)) return false; //Check if tiles are valid if (checkedList.Any(t => t.Item1 == x && (t.Item2 >= y && t.Item2 < y + 2))) return false; return true; }
/// <summary> /// Generate all remaining 1x1 areas /// </summary> /// <param name="tileRectList">Reference list of tile rectangles to add to</param> /// <param name="checkedList">Reference list of tiles already checked</param> /// <param name="tileManager">Tile Manager</param> private static void Generate1x1Chunks(ref List <TileRectangle> tileRectList, ref List <Tuple <int, int> > checkedList, TileManager tileManager) { //3) Create the remaining 1x1 Chunks //Loop through each tile for (int y = 0; y < tileManager.Height; ++y) { for (int x = 0; x < tileManager.Width; ++x) { //Check if tile solid and 2x2 area isn't in the checked list (may be buggy) if (tileManager.GetTile(x, y) && !checkedList.Any(t => t.Item1 == x && t.Item2 == y)) { //Create the 1x1 rectangle tileRectList.Add(new TileRectangle(x, y, 1, 1)); //Add them to the checked list checkedList.Add(new Tuple <int, int>(x, y)); } } } }
/// <summary> /// Generate all remaining 1x1 areas /// </summary> /// <param name="tileRectList">Reference list of tile rectangles to add to</param> /// <param name="checkedList">Reference list of tiles already checked</param> /// <param name="tileManager">Tile Manager</param> private static void Generate1x1Chunks(ref List<TileRectangle> tileRectList, ref List<Tuple<int, int>> checkedList, TileManager tileManager) { //3) Create the remaining 1x1 Chunks //Loop through each tile for (int y = 0; y < tileManager.Height; ++y) { for (int x = 0; x < tileManager.Width; ++x) { //Check if tile solid and 2x2 area isn't in the checked list (may be buggy) if (tileManager.GetTile(x, y) && !checkedList.Any(t => t.Item1 == x && t.Item2 == y)) { //Create the 1x1 rectangle tileRectList.Add(new TileRectangle(x, y, 1, 1)); //Add them to the checked list checkedList.Add(new Tuple<int, int>(x, y)); } } } }