/// <summary> /// Performs several functions to prepare a Level for the Gameplay state, /// including setting up the WorldState, TileGrid, determining cover positions, /// adding objects to the collision detector, etc. /// </summary> public void initializeForGameplay() { Tile[,] tilesForCollisionGeneration = new Tile[getHeight(), getWidth()]; for (int i = 0; i < getHeight(); i++) { for (int j = 0; j < getWidth(); j++) { Height h = tileSet_.getHeight(tiles_[i, j]); if (h.blocksHigh_) { tilesForCollisionGeneration[i, j].highDistance_ = 0f; } else { tilesForCollisionGeneration[i, j].highDistance_ = 1f; } if (h.blocksLow_) { tilesForCollisionGeneration[i, j].lowDistance_ = 0f; } else { tilesForCollisionGeneration[i, j].lowDistance_ = 1f; } } } List<BoxObject> boxesToBeAddedForReal = Tiler.mergeBoxes(tilesForCollisionGeneration); // Calculate distances from walls to each tile Tile[,] tilesForGrid = CoverGenerator.generateRealTileDistances(tilesForCollisionGeneration); if (Settings.getInstance().IsInDebugMode_) { for (int i = 0; i < tilesForGrid.GetLength(0); i++) { for (int j = 0; j < tilesForGrid.GetLength(1); j++) { Console.Write(tilesForGrid[i, j].highDistance_.ToString("F1")); Console.Write(" "); } Console.WriteLine(); } } GlobalHelper.getInstance().setCurrentLevelTileGrid(new TileGrid(tilesForGrid)); // Generate cover objects and add them to collision detection List<CoverObject> coverObjects = CoverGenerator.generateCoverObjects(tilesForGrid); for (int i = 0; i < boxesToBeAddedForReal.Count; i++) { CollisionDetector_.register(boxesToBeAddedForReal[i]); } // Add other entities to collision detection and WorldState for (int i = 0; i < getEnemies().Count; i++) { getEnemies()[i].setCollisionDetector(CollisionDetector_); } for (int i = 0; i < getItems().Count; i++) { getItems()[i].setCollisionDetector(CollisionDetector_); if (getItems()[i] is AmmoBox) WorldState.AmmoList_.Add(getItems()[i] as AmmoBox); } for (int i = 0; i < coverObjects.Count; i++) { coverObjects[i].setCollisionDetector(CollisionDetector_); WorldState.CoverList_.Add(coverObjects[i]); } List<CharacterAbstract> characterList = new List<CharacterAbstract>(); for (int i = 0; i < getEnemies().Count; i++) { characterList.Add(getEnemies()[i]); } if (player_ != null) { characterList.Add(player_); } WorldState.CharacterList_ = characterList; }
protected static bool collision(Tile tile) { return tile.collides(searchHeight_, searchRadius_); }
public void initializeForEditor() { Tile[,] tilesForCollisionGeneration = new Tile[getHeight(), getWidth()]; for (int i = 0; i < getHeight(); i++) { for (int j = 0; j < getWidth(); j++) { Height h = tileSet_.getHeight(tiles_[i, j]); if (h.blocksHigh_) { tilesForCollisionGeneration[i, j].highDistance_ = 0f; } else { tilesForCollisionGeneration[i, j].highDistance_ = 1f; } if (h.blocksLow_) { tilesForCollisionGeneration[i, j].lowDistance_ = 0f; } else { tilesForCollisionGeneration[i, j].lowDistance_ = 1f; } } } List<BoxObject> boxesToBeAddedForReal = Tiler.mergeBoxes(tilesForCollisionGeneration); // Calculate distances from walls to each tile Tile[,] tilesForGrid = CoverGenerator.generateRealTileDistances(tilesForCollisionGeneration); if (Settings.getInstance().IsInDebugMode_) { for (int i = 0; i < tilesForGrid.GetLength(0); i++) { for (int j = 0; j < tilesForGrid.GetLength(1); j++) { Console.Write(tilesForGrid[i, j].highDistance_.ToString("F1")); Console.Write(" "); } Console.WriteLine(); } } GlobalHelper.getInstance().setCurrentLevelTileGrid(new TileGrid(tilesForGrid)); // Generate cover objects and add them to collision detection }
public static List<CoverObject> generateCoverObjects(Tile[,] tiles) { List<CoverObject> returnList = new List<CoverObject>(); newTiles_ = tiles; for (int i = 0; i < newTiles_.GetLength(0); i++) { for (int j = 0; j < newTiles_.GetLength(1); j++) { //Are we on an edge if (get(j, i, HeightEnum.LOW) == 1f && get(j, i, HeightEnum.HIGH) > 0f) { // We're checking to make sure that this is the case: // >0 | | >0 // ------------------ // >0 | j,i | 0, low only // ------------------ // | >0 | 0, low only // if (((get(j - 1, i - 1, HeightEnum.LOW) > 0f //Upper Left is not a wall && get(j + 1, i - 1, HeightEnum.LOW) > 0f) //Upper Right not a wall || ((get(j - 1, i - 1, HeightEnum.LOW) == 0f //Upper Left is a wall && get(j + 1, i - 1, HeightEnum.LOW) == 0f) //Upper Right is a wall && get(j, i - 1, HeightEnum.LOW) == 0f) //Top is a wall ) && get(j - 1, i, HeightEnum.LOW) > 0f //Left is not a wall && get(j, i + 1, HeightEnum.LOW) > 0f //Below is not a wall && get(j + 1, i, HeightEnum.LOW) == 0f //Right is a wall && get(j + 1, i + 1, HeightEnum.LOW) == 0f //Lower Right is a wall && get(j + 1, i, HeightEnum.HIGH) > 0f //Right is not blocked high && get(j + 1, i + 1, HeightEnum.HIGH) > 0f //Lower Right is not blocked high ) { //We are now sure that we need to start cover going down CoverObject temp = genVerticalCoverObjectLeft(j, i); if (temp != null) { returnList.Add(temp); } } // We're checking to make sure that this is the case: // >0 | | >0 // ------------------ // 0, low | j,i | >0 // ------------------ // 0, low | >0 | // else if (get(j - 1, i - 1, HeightEnum.LOW) > 0f //Upper Left is not a wall && get(j + 1, i - 1, HeightEnum.LOW) > 0f //Upper Right not a wall && get(j + 1, i, HeightEnum.LOW) > 0f //Right is not a wall && get(j, i + 1, HeightEnum.LOW) > 0f //Below is not a wall && get(j - 1, i, HeightEnum.LOW) == 0f //Left is a wall && get(j - 1, i + 1, HeightEnum.LOW) == 0f //Lower Left is a wall && get(j - 1, i, HeightEnum.HIGH) > 0f //Left is not blocked high && get(j - 1, i + 1, HeightEnum.HIGH) > 0f //Lower Left is not blocked high ) { //We are now sure that we need to start cover going down CoverObject temp = genVerticalCoverObjectRight(j, i); if (temp != null) { returnList.Add(temp); } } // We're checking to make sure that this is the case: // >0 | 0, l | 0, low only // ------------------ // | j,i | >0 // ------------------ // >0 | >0 | // if (((get(j - 1, i - 1, HeightEnum.LOW) > 0f //Upper Left is not a wall && get(j - 1, i + 1, HeightEnum.LOW) > 0f) //Lower Left not a wall || ((get(j - 1, i + 1, HeightEnum.LOW) == 0f //Lower Left is a wall && get(j - 1, i, HeightEnum.LOW) == 0f) //Left is a wall && get(j - 1, i - 1, HeightEnum.LOW) == 0f) //Upper Left is a wall ) && get(j, i + 1, HeightEnum.LOW) > 0f //Bottom is not a wall && get(j + 1, i, HeightEnum.LOW) > 0f //Right is not a wall && get(j, i - 1, HeightEnum.LOW) == 0f //Top is a wall && get(j + 1, i - 1, HeightEnum.LOW) == 0f //Upper Right is a wall && get(j, i - 1, HeightEnum.HIGH) > 0f //Top is not blocked high && get(j + 1, i - 1, HeightEnum.HIGH) > 0f //Upper Right is not blocked high ) { //We are now sure that we need to start cover going right CoverObject temp = genHorizontalCoverObjectBottom(j, i); if (temp != null) { returnList.Add(temp); } } // We're checking to make sure that this is the case: // >0 | >0 | // ------------------ // | j,i | >0 // ------------------ // >0 | 0, l | 0, low only // else if (((get(j - 1, i - 1, HeightEnum.LOW) > 0f //Upper Left is not a wall && get(j - 1, i + 1, HeightEnum.LOW) > 0f) //Lower Left not a wall || ((get(j - 1, i + 1, HeightEnum.LOW) == 0f //Lower Left is a wall && get(j - 1, i, HeightEnum.LOW) == 0f) //Left is a wall && get(j - 1, i - 1, HeightEnum.LOW) == 0f) //Upper Left is a wall ) && get(j, i - 1, HeightEnum.LOW) > 0f //Top is not a wall && get(j + 1, i, HeightEnum.LOW) > 0f //Right is not a wall && get(j, i + 1, HeightEnum.LOW) == 0f //Bottom is a wall && get(j + 1, i + 1, HeightEnum.LOW) == 0f //Lower Right is a wall && get(j, i + 1, HeightEnum.HIGH) > 0f //Bottom is not blocked high && get(j + 1, i + 1, HeightEnum.HIGH) > 0f //Lower Right is not blocked high ) { //We are now sure that we need to start cover going right CoverObject temp = genHorizontalCoverObjectTop(j, i); if (temp != null) { returnList.Add(temp); } } } } } return returnList; }
/* * public static List<CoverObject> generateCoverObjects(Tile[,] tiles) { List<CoverObject> returnList = new List<CoverObject>(); newTiles_ = tiles; for (int i = 0; i < newTiles_.GetLength(0); i++) { for (int j = 0; j < newTiles_.GetLength(1); j++) { //Are we on an edge if (get(j, i, HeightEnum.LOW) == 0.5f && get(j, i, HeightEnum.HIGH) > 0f) { /// We're checking to make sure that this is the case: /// >0 | | >0 /// ------------------ /// >0 | j,i | 0, low only /// ------------------ /// | >0 | 0, low only /// if (((get(j - 1, i - 1, HeightEnum.LOW) > 0f //Upper Left is not a wall && get(j + 1, i - 1, HeightEnum.LOW) > 0f) //Upper Right not a wall || ((get(j - 1, i - 1, HeightEnum.LOW) == 0f //Upper Left is a wall && get(j + 1, i - 1, HeightEnum.LOW) == 0f) //Upper Right is a wall && get(j, i - 1, HeightEnum.LOW) == 0f) //Top is a wall ) && get(j - 1, i, HeightEnum.LOW) > 0f //Left is not a wall && get(j, i + 1, HeightEnum.LOW) > 0f //Below is not a wall && get(j + 1, i, HeightEnum.LOW) == 0f //Right is a wall && get(j + 1, i + 1, HeightEnum.LOW) == 0f //Lower Right is a wall && get(j + 1, i, HeightEnum.HIGH) > 0f //Right is not blocked high && get(j + 1, i + 1, HeightEnum.HIGH) > 0f //Lower Right is not blocked high ) { ///We are now sure that we need to start cover going down CoverObject temp = genVerticalCoverObjectLeft(j, i); if (temp != null) { returnList.Add(temp); } } /// We're checking to make sure that this is the case: /// >0 | | >0 /// ------------------ /// 0, low | j,i | >0 /// ------------------ /// 0, low | >0 | /// else if (get(j - 1, i - 1, HeightEnum.LOW) > 0f //Upper Left is not a wall && get(j + 1, i - 1, HeightEnum.LOW) > 0f //Upper Right not a wall && get(j + 1, i, HeightEnum.LOW) > 0f //Right is not a wall && get(j, i + 1, HeightEnum.LOW) > 0f //Below is not a wall && get(j - 1, i, HeightEnum.LOW) == 0f //Left is a wall && get(j - 1, i + 1, HeightEnum.LOW) == 0f //Lower Left is a wall && get(j - 1, i, HeightEnum.HIGH) > 0f //Left is not blocked high && get(j - 1, i + 1, HeightEnum.HIGH) > 0f //Lower Left is not blocked high ) { ///We are now sure that we need to start cover going down CoverObject temp = genVerticalCoverObjectRight(j, i); if (temp != null) { returnList.Add(temp); } } /// We're checking to make sure that this is the case: /// >0 | 0, l | 0, low only /// ------------------ /// | j,i | >0 /// ------------------ /// >0 | >0 | /// if (((get(j - 1, i - 1, HeightEnum.LOW) > 0f //Upper Left is not a wall && get(j - 1, i + 1, HeightEnum.LOW) > 0f) //Lower Left not a wall || ((get(j - 1, i + 1, HeightEnum.LOW) == 0f //Lower Left is a wall && get(j - 1, i, HeightEnum.LOW) == 0f) //Left is a wall && get(j - 1, i - 1, HeightEnum.LOW) == 0f) //Upper Left is a wall ) && get(j, i + 1, HeightEnum.LOW) > 0f //Bottom is not a wall && get(j + 1, i, HeightEnum.LOW) > 0f //Right is not a wall && get(j, i - 1, HeightEnum.LOW) == 0f //Top is a wall && get(j + 1, i - 1, HeightEnum.LOW) == 0f //Upper Right is a wall && get(j, i - 1, HeightEnum.HIGH) > 0f //Top is not blocked high && get(j + 1, i - 1, HeightEnum.HIGH) > 0f //Upper Right is not blocked high ) { ///We are now sure that we need to start cover going right CoverObject temp = genHorizontalCoverObjectBottom(j, i); if (temp != null) { returnList.Add(temp); } } /// We're checking to make sure that this is the case: /// >0 | >0 | /// ------------------ /// | j,i | >0 /// ------------------ /// >0 | 0, l | 0, low only /// else if (((get(j - 1, i - 1, HeightEnum.LOW) > 0f //Upper Left is not a wall && get(j - 1, i + 1, HeightEnum.LOW) > 0f) //Lower Left not a wall || ((get(j - 1, i + 1, HeightEnum.LOW) == 0f //Lower Left is a wall && get(j - 1, i, HeightEnum.LOW) == 0f) //Left is a wall && get(j - 1, i - 1, HeightEnum.LOW) == 0f) //Upper Left is a wall ) && get(j, i - 1, HeightEnum.LOW) > 0f //Top is not a wall && get(j + 1, i, HeightEnum.LOW) > 0f //Right is not a wall && get(j, i + 1, HeightEnum.LOW) == 0f //Bottom is a wall && get(j + 1, i + 1, HeightEnum.LOW) == 0f //Lower Right is a wall && get(j, i + 1, HeightEnum.HIGH) > 0f //Bottom is not blocked high && get(j + 1, i + 1, HeightEnum.HIGH) > 0f //Lower Right is not blocked high ) { ///We are now sure that we need to start cover going right CoverObject temp = genHorizontalCoverObjectTop(j, i); if (temp != null) { returnList.Add(temp); } } } } } return returnList; } protected static CoverObject genVerticalCoverObjectLeft(int j, int i) { float top = (float)i * 15f; float bottom = (float)i * 15f; float rightEdge = (float)(j + 1) * 15f; float leftEdge = (float)(j - 1) * 15f; /// We're checking to make sure that this is the case: /// | | /// ------------------ /// >0 | j,i | 0 /// ------------------ /// | | /// while (get(j, i, HeightEnum.LOW) == 0.5f && get(j, i, HeightEnum.HIGH) > 0f && get(j + 1, i, HeightEnum.LOW) == 0f && get(j + 1, i, HeightEnum.HIGH) > 0f && get(j - 1, i, HeightEnum.LOW) > 0f ) { bottom += 15f; i++; } if (bottom - top < 45f) { return null; } Vector2 position = new Vector2((rightEdge + leftEdge) / 2f, (bottom + top) / 2f); List<Vector2> bounds = new List<Vector2>(); bounds.Add(new Vector2(leftEdge - position.X, top - position.Y)); bounds.Add(new Vector2(rightEdge - position.X, top - position.Y)); bounds.Add(new Vector2(rightEdge - position.X, bottom - position.Y)); bounds.Add(new Vector2(leftEdge - position.X, bottom - position.Y)); return new CoverObject(null, bounds, position, new Vector2(rightEdge, top), new Vector2(rightEdge, bottom)); } protected static CoverObject genVerticalCoverObjectRight(int j, int i) { float top = (float)i * 15f; float bottom = (float)i * 15f; float rightEdge = (float)(j + 2) * 15f; float leftEdge = (float)j * 15f; /// We're checking to make sure that this is the case: /// | | /// ------------------ /// 0 | j,i | >0 /// ------------------ /// | | /// while (get(j, i, HeightEnum.LOW) == 0.5f && get(j, i, HeightEnum.HIGH) > 0f && get(j - 1, i, HeightEnum.LOW) == 0f && get(j - 1, i, HeightEnum.HIGH) > 0f && get(j + 1, i, HeightEnum.LOW) > 0f ) { bottom += 15f; i++; } if (bottom - top < 45f) { return null; } Vector2 position = new Vector2((rightEdge + leftEdge) / 2f, (bottom + top) / 2f); List<Vector2> bounds = new List<Vector2>(); bounds.Add(new Vector2(leftEdge - position.X, top - position.Y)); bounds.Add(new Vector2(rightEdge - position.X, top - position.Y)); bounds.Add(new Vector2(rightEdge - position.X, bottom - position.Y)); bounds.Add(new Vector2(leftEdge - position.X, bottom - position.Y)); return new CoverObject(null, bounds, position, new Vector2(leftEdge, top), new Vector2(leftEdge, bottom)); } protected static CoverObject genHorizontalCoverObjectTop(int j, int i) { float topEdge = (float)(i - 1) * 15f; float bottomEdge = (float)(i + 1) * 15f; float right = (float)j * 15f; float left = (float)j * 15f; /// We're checking to make sure that this is the case: /// | >0 | /// ------------------ /// | j,i | /// ------------------ /// | 0, l | /// while (get(j, i, HeightEnum.LOW) == 0.5f && get(j, i, HeightEnum.HIGH) > 0f && get(j, i + 1, HeightEnum.LOW) == 0f && get(j, i + 1, HeightEnum.HIGH) > 0f && get(j, i - 1, HeightEnum.LOW) > 0f ) { right += 15f; j++; } if (right - left < 45f) { return null; } Vector2 position = new Vector2((right + left) / 2f, (bottomEdge + topEdge) / 2f); List<Vector2> bounds = new List<Vector2>(); bounds.Add(new Vector2(left - position.X, topEdge - position.Y)); bounds.Add(new Vector2(right - position.X, topEdge - position.Y)); bounds.Add(new Vector2(right - position.X, bottomEdge - position.Y)); bounds.Add(new Vector2(left - position.X, bottomEdge - position.Y)); return new CoverObject(null, bounds, position, new Vector2(left, topEdge), new Vector2(right, topEdge)); } protected static CoverObject genHorizontalCoverObjectBottom(int j, int i) { float topEdge = (float)i * 15f; float bottomEdge = (float)(i + 2) * 15f; float right = (float)j * 15f; float left = (float)j * 15f; /// We're checking to make sure that this is the case: /// | 0 | /// ------------------ /// | j,i | /// ------------------ /// | >0 | /// while (get(j, i, HeightEnum.LOW) == 0.5f && get(j, i, HeightEnum.HIGH) > 0f && get(j, i - 1, HeightEnum.LOW) == 0f && get(j, i - 1, HeightEnum.HIGH) > 0f && get(j, i + 1, HeightEnum.LOW) > 0f ) { right += 15f; j++; } if (right - left < 45f) { return null; } Vector2 position = new Vector2((right + left) / 2f, (bottomEdge + topEdge) / 2f); List<Vector2> bounds = new List<Vector2>(); bounds.Add(new Vector2(left - position.X, topEdge - position.Y)); bounds.Add(new Vector2(right - position.X, topEdge - position.Y)); bounds.Add(new Vector2(right - position.X, bottomEdge - position.Y)); bounds.Add(new Vector2(left - position.X, bottomEdge - position.Y)); return new CoverObject(null, bounds, position, new Vector2(left, bottomEdge), new Vector2(right, bottomEdge)); } */ public static Tile[,] generateRealTileDistances(Tile[,] tiles) { oldTiles_ = tiles; newTiles_ = new Tile[tiles.GetLength(0), tiles.GetLength(1)]; initialize(); for (int i = 0; i < newTiles_.GetLength(0); i++) { for (int j = 0; j < newTiles_.GetLength(1); j++) { set(j, i, HeightEnum.HIGH); set(j, i, HeightEnum.LOW); } } return newTiles_; }
public TileGrid(Tile[,] tiles) { tiles_ = tiles; width_ = tiles.GetLength(1); height_ = tiles.GetLength(0); }
/// <summary> /// Generate a list of TileObjects from a two dimensional array of ints, where each /// number in the array represents the type of tile to use at that cooridinate. /// </summary> /// <param name="pipeline">Drawing pipeline in which to register the object</param> /// <param name="tiles">Array of ints representing types of tiles</param> /// <returns>List of TileObjects</returns> /* public static List<TileObject> getTiles(List<DrawableObjectAbstract> pipeline, int[,] tiles) { List<TileObject> retList = new List<TileObject>(); for (int y = 0; y < tiles.GetLength(0); y++) { for (int x = 0; x < tiles.GetLength(1); x++) { retList.Add(new TileObject(tiles[y, x], pipeline, TextureMap.getInstance().getTexture("Tile_" + tiles[y, x]), new Vector2((float)x * tileSideLength_, (float)y * tileSideLength_), Vector2.Zero, 0.0f)); } } return retList; } */ public static List<BoxObject> mergeBoxes(Tile[,] boxes) { //List<List<BoxObject>> tempMergedBoxes = new List<List<BoxObject>>(); List<List<int[]>> tempMergedDimsHigh = new List<List<int[]>>(); List<List<int[]>> tempMergedDimsLow = new List<List<int[]>>(); List<Vector2> tempPoints = new List<Vector2>(); tempPoints.Add(new Vector2(-7.5f, -7.5f)); tempPoints.Add(new Vector2(7.5f, -7.5f)); tempPoints.Add(new Vector2(7.5f, 7.5f)); tempPoints.Add(new Vector2(-7.5f, 7.5f)); int[] tempSetHigh = new int[4]; int[] tempSetLow = new int[4]; bool startedHigh = false; bool startedLow = false; List<BoxObject> returnBoxes = new List<BoxObject>(); for (int y = 0; y < boxes.GetLength(0); y++) { tempMergedDimsHigh.Add(new List<int[]>()); tempMergedDimsLow.Add(new List<int[]>()); for (int x = 0; x < boxes.GetLength(1); x++) { if (!startedHigh && boxes[y,x].highDistance_ == 0) { startedHigh = true; tempSetHigh[0] = x; tempSetHigh[1] = y; tempSetHigh[2] = x; tempSetHigh[3] = y; } else if (startedHigh && boxes[y,x].highDistance_ == 0) { tempSetHigh[2] = x; } else if (startedHigh && !(boxes[y,x].highDistance_ == 0)) { tempMergedDimsHigh[y].Add(tempSetHigh); tempSetHigh = new int[4]; startedHigh = false; } if (!startedLow && boxes[y, x].lowDistance_ == 0) { startedLow = true; tempSetLow[0] = x; tempSetLow[1] = y; tempSetLow[2] = x; tempSetLow[3] = y; } else if (startedLow && boxes[y, x].lowDistance_ == 0) { tempSetLow[2] = x; } else if (startedLow && !(boxes[y, x].lowDistance_ == 0)) { tempMergedDimsLow[y].Add(tempSetLow); tempSetLow = new int[4]; startedLow = false; } } if (startedHigh) { tempMergedDimsHigh[y].Add(tempSetHigh); tempSetHigh = new int[4]; startedHigh = false; } if (startedLow) { tempMergedDimsLow[y].Add(tempSetLow); tempSetLow = new int[4]; startedLow = false; } } for (int i = 0; i < boxes.GetLength(0); i++) { for (int j = tempMergedDimsHigh[i].Count - 1; j >= 0; j--) { bool finished = false; int[] tempCheckingSet = tempMergedDimsHigh[i][j]; tempMergedDimsHigh[i].RemoveAt(j); for (int k = i + 1; k < boxes.GetLength(0); k++) { finished = true; for (int l = tempMergedDimsHigh[k].Count - 1; l >= 0; l--) { int[] temp = tempMergedDimsHigh[k][l]; if (temp[0] == tempCheckingSet[0] && temp[2] == tempCheckingSet[2]) { tempCheckingSet[3] = temp[3]; finished = false; tempMergedDimsHigh[k].RemoveAt(l); break; } } if (finished) { break; } } returnBoxes.Add(createBox(tempCheckingSet[0], tempCheckingSet[1], tempCheckingSet[2], tempCheckingSet[3], HeightEnum.HIGH)); } for (int j = tempMergedDimsLow[i].Count - 1; j >= 0; j--) { bool finished = false; int[] tempCheckingSet = tempMergedDimsLow[i][j]; tempMergedDimsLow[i].RemoveAt(j); for (int k = i + 1; k < boxes.GetLength(0); k++) { finished = true; for (int l = tempMergedDimsLow[k].Count - 1; l >= 0; l--) { int[] temp = tempMergedDimsLow[k][l]; if (temp[0] == tempCheckingSet[0] && temp[2] == tempCheckingSet[2]) { tempCheckingSet[3] = temp[3]; finished = false; tempMergedDimsLow[k].RemoveAt(l); break; } } if (finished) { break; } } returnBoxes.Add(createBox(tempCheckingSet[0], tempCheckingSet[1], tempCheckingSet[2], tempCheckingSet[3], HeightEnum.LOW)); } } return returnBoxes; }