void PaintRoom(ProcRoom room) { bool successful = false; int attempts = 0; map.BeginBulkEdit(); while (!successful && attempts < 5) { // get random coordinates to attempt to place new room // int originX = (int) MLib.NextGaussian(mapColumns / 2, mapColumns / 2, mapMarginX, mapColumns); // int originY = (int) MLib.NextGaussian(mapRows / 2, mapRows / 2, mapMarginY, mapRows); Random rand = new Random(); int originX = rand.DivFour(mapMarginX, mapColumns - mapMarginX); int originY = rand.DivFour(mapMarginY, mapRows - mapMarginY); // check that room will fit within map bounds if (RoomInBounds(originX, originY, room) && !TouchingRooms(originX, originY, room)) { // paint room for (int x = 0; x < room.width; x++) { for (int y = 0; y < room.height; y++) { map.EraseTile(originY + y, originX + x); map.RefreshSurroundingTiles(originY + y, originX + x); } } // with room succesfully placed, set origin then add to List room.originX = originX; room.originY = originY; rooms.Add(room); successful = true; } attempts++; } map.EndBulkEdit(); }