private void GenerateWorldData() { int numberVillages = 5; int numberDungeons = 10; //Generate VillageLocations for (int i = 0; i < numberVillages; i++) { VillageData d = new VillageData(); d.Loc = GenerateVillageChunkLocation(); wData.Villages.Add(d); } //Connect each village to a random village for (int j = 0; j < wData.Villages.Count; j++) { wData.Villages[j].ConnectedVillageLoc = wData.Villages[Game.rng.Next(wData.Villages.Count)].Loc; wData.Villages[j].VillageToVillage = new Ray(wData.Villages[j].Loc, wData.Villages[j].ConnectedVillageLoc); for (int x = 0; x < wData.worldSize; x++) { for (int y = 0; y < wData.worldSize; y++) { Rectangle chunkRect = new Rectangle(x * wData.chunkSize, y * wData.chunkSize, wData.chunkSize, wData.chunkSize); if (Ray.isIntersectingRect(wData.Villages[j].VillageToVillage, chunkRect)) { if (wData.Villages[j].roadChunks == null) { wData.Villages[j].roadChunks = new List <Point>(); } wData.Villages[j].roadChunks.Add(new Point(x, y)); } } } } for (int k = 0; k < numberDungeons; k++) { DungeonData d = new DungeonData(); d.DoorChunkLoc = GenerateDungeonLocation(); d.DoorLoc = new Point(d.DoorChunkLoc.X % 100, d.DoorChunkLoc.Y % 100); d.seed = Game.rng.Next(); wData.Dungeons.Add(d); } }
private Chunk GenerateDungeon(DungeonData dData) { Random rng = new Random(dData.seed); Point chunk = new Point(dData.DoorChunkLoc.X / 100, dData.DoorChunkLoc.Y / 100); int randomFillPercent = 50; int iterations = 5; int xSize = rng.Next(20, 80); Chunk tempChunk = new Chunk(xSize, chunk.X, chunk.Y); worldTile wall = new worldTile(); wall.graphics = new Tile(); wall.graphics.tAtlas = wData.tAtlas; wall.graphics.TexID = (int)WorldTexID.wall; wall.isCollideable = true; wall.isContainer = false; wall.isRoad = false; wall.type = "wall"; worldTile air = new worldTile(); air.graphics = new Tile(); air.graphics.tAtlas = wData.tAtlas; air.graphics.TexID = (int)WorldTexID.air; air.isCollideable = false; air.isContainer = false; air.isRoad = false; air.type = "air"; for (int x = 0; x < xSize; x++) { for (int y = 0; y < xSize; y++) { if (rng.Next(100) > randomFillPercent - 1) { tempChunk.backgroundTiles[x, y] = wall; } else { tempChunk.backgroundTiles[x, y] = air; } } } for (int i = 0; i < iterations; i++) { for (int x = 0; x < xSize; x++) { for (int y = 0; y < xSize; y++) { int neighbors = getNumberNeighbors(tempChunk, x, y, "wall", xSize); if (tempChunk.backgroundTiles[x, y].type == "wall") { if (neighbors >= 4) { tempChunk.backgroundTiles[x, y] = wall; } } else { if (neighbors >= 5) { tempChunk.backgroundTiles[x, y] = wall; } } } } } return(tempChunk); }