public static void Lands() { for (int y = 0; y < (displayHeight / CurrentTileSize) + 2; y++) { for (int x = 0; x < (displayWidth / CurrentTileSize) + 2; x++) { Land land = landArray[Check.Range(cameraLocationX + x, 0, MapWidth - 1), Check.Range(cameraLocationY + y, 0, MapHeight - 1)]; Rectangle tile = TileFrame[x, y]; if (land.biome == 1) { int grass = Check.LoopIntPos((cameraLocationX + x) + (cameraLocationY + y), 0, 3); spriteBatch.Draw(DrawingBoard.Biomes[1, 0, grass], tile, Color.White); if (land.IsBorder) { spriteBatch.Draw(DrawingBoard.Borders[land.BorderBiome, land.Border], tile, Color.White); } } else if (land.biome == 2) { int snow = Check.LoopIntPos((cameraLocationX + x) + (cameraLocationY + y), 0, 2); spriteBatch.Draw(DrawingBoard.Biomes[2, 0, snow], tile, Color.White); } else if (land.biome == 3) { int sandX = Check.LoopIntPos((cameraLocationX + x), 0, 29); int sandY = Check.LoopIntPos((cameraLocationY + y), 0, 19); spriteBatch.Draw(DrawingBoard.Biomes[3, sandX, sandY], tile, Color.White); } else { spriteBatch.Draw(DrawingBoard.Tiles[0, land.biome, 5], tile, Color.White); } } } }
/* DrawTiles; * Input Values: cameraLocationX, cameraLocation Y; * This function will run a number of times that is less than * the display height divided by default tile rendering dimension 50 * divided by the scale of tile drawings to get number of tiles on screen * then add overflow number of 2 divided by tile scale to draw past screen broders (+2) * Steps: Determine global tile at current position camera x & y plus * the point at which in this function (int x or y) it has already drawn to * then check for biome before using tile scale and location data to draw tile * * --Pending 60x60 Optimization */ public static void Tiles() { double rnd; Color color = new Color(Color.Black, 0.2f); for (int y = 0; y < (displayHeight / CurrentTileSize) + 2; y++) { for (int x = 0; x < (displayWidth / CurrentTileSize) + 2; x++) { /*rnd = Random.Next(0, 10000); * if (rnd == 5 || rnd == 9995 && landArray[cameraLocationX + x, cameraLocationY + y].land == 5) * { * if (landArray[cameraLocationX + x, cameraLocationY + y].frame < 5 && rnd > 5000) * { * landArray[cameraLocationX + x, cameraLocationY + y].frame = Check.Max(landArray[cameraLocationX + x, cameraLocationY + y].frame + 1, 5); * landArray[cameraLocationX + x + 1, cameraLocationY + y].frame = Check.Max(landArray[cameraLocationX + x + 1, cameraLocationY + y].frame + 1, 5); * landArray[cameraLocationX + x, cameraLocationY + y + 1].frame = Check.Max(landArray[cameraLocationX + x, cameraLocationY + y + 1].frame + 1, 5); * } * else if (landArray[cameraLocationX + x, cameraLocationY + y].frame > 0 && rnd < 5000) * { * rnd = Random.Next(3, 6); * for (int i = 1; i < rnd; i++) * { * landArray[cameraLocationX + x, cameraLocationY + y].frame = Check.Min(landArray[cameraLocationX + x, cameraLocationY + y].frame - 1, 0); * landArray[cameraLocationX + x + i, cameraLocationY + y].frame = Check.Min(landArray[cameraLocationX + x + i, cameraLocationY + y].frame - 1, 0); * landArray[cameraLocationX + x, cameraLocationY + y + i].frame = Check.Min(landArray[cameraLocationX + x, cameraLocationY + y + i].frame - 1, 0); * landArray[cameraLocationX + x + i, cameraLocationY + y + i].frame = Check.Min(landArray[cameraLocationX + x + i, cameraLocationY + y + i].frame - 1, 0); * } * } * }*/ /// // I may be eventually make a Rectangle Container Class to just have them hold the tile information // I may also be able to pre-pack tiles into 16:9 chunks? // // I think this is how I'm going to do it: // First of all we need three separate layers; Biome, Unit, Object // We then need to call these in order, likely in different spriteBatch.End() calls // The biome layer and maybe object (building) layer could then be pre-packed (or rendered) Land land = landArray[Check.Range(cameraLocationX + x, 0, MapWidth - 1), Check.Range(cameraLocationY + y, 0, MapHeight - 1)]; if (land.land != 0) { Texture2D texture = DrawingBoard.Tiles[land.land, land.biome, land.frame]; Object obj = Objects[land.land]; Rectangle tile = TileFrame[x, y]; int[] adjustLand = { 0, 0 }; if (land.land == 5) { int halfTileSize = CurrentTileSize / 2; adjustLand = new int[2] { halfTileSize, -(halfTileSize / 2) }; } Rectangle rectangle = new Rectangle(tile.X - (int)((obj.X - 50) * tileScale) + adjustLand[0], tile.Y - (int)((obj.Y - 50) * tileScale) + adjustLand[1], (int)(obj.X * tileScale), (int)(obj.Y * tileScale)); if (Math.Abs(Player.player.tileX - x) < 5 && Math.Abs(Player.player.tileY - y) < 5 && rectangle.Contains(Player.player.DrawX, Player.player.DrawY)) { spriteBatch.Draw(texture, rectangle, color); } else { spriteBatch.Draw(texture, rectangle, Color.White); } } } /*if (land.IsOwned) { * spriteBatch.Draw(outline, tile, Color.White); }*/ /*float fl = 1.0f; * Vector2 origin = new Vector2(0, 0); * if (land.land == 5) { * origin.X = -12; * origin.Y = 8; * fl = 2.0f; }*/ /*spriteBatch.Draw(texture, * new Vector2((x - ((obj.X / 50) - 1)) * (CurrentTileSize) + Player.player.TileOffsetXY[0], * (y - ((obj.Y / 50) - 1)) * (CurrentTileSize) + Player.player.TileOffsetXY[1]), * new Rectangle(0, 0, obj.X, obj.Y), * Color.White, 0, origin, * fl * (float)tileScale, SpriteEffects.None, 1);*/ //spriteBatch.DrawString(TileInfoFont, Objects[land.land].Name, new Vector2(x * modifiedTileScale, y * modifiedTileScale), Color.Black); } }
public static void Edges() { // Draw Edges Around Snow for (int definition = 0; definition < 2; definition++) { for (int y = 1; y < 999; y++) { for (int x = 1; x < 999; x++) { Land land = landArray[x, y]; if (land.biome == 1) { int border = 0; for (int i = 0; i < 4; i++) { if (landArray[x + MovementXY2[i, 0], y + MovementXY2[i, 1]].biome == 2) { border += (int)Math.Pow(2, i); } } if (border > 0 && border % 3 == 0) { if (border == 15) { land.biome = 2; } else { land.IsBorder = true; land.BorderBiome = 2; land.Border = border / 3; } } } else if (land.biome == 2) { int border = 0; for (int i = 0; i < 4; i++) { Land adjacentLand = landArray[x - MovementXY2[i, 0], y - MovementXY2[i, 1]]; if (!adjacentLand.IsBorder && (adjacentLand.biome != 2 || adjacentLand.IsBorder)) { border += (int)Math.Pow(2, i); } } if (border > 0 && border % 3 == 0) { if (border == 15) { land.biome = 2; } else { land.biome = 1; land.IsBorder = true; land.BorderBiome = 2; land.Border = border / 3; } } } } } } // Draw Edges Around Sand for (int definition = 0; definition < 2; definition++) { for (int y = 1; y < 999; y++) { for (int x = 1; x < 999; x++) { Land land = landArray[x, y]; if (land.biome == 1 && !land.IsBorder) { int border = 0; for (int i = 0; i < 4; i++) { if (landArray[x + MovementXY2[i, 0], y + MovementXY2[i, 1]].biome == 3) { border += (int)Math.Pow(2, i); } } if (border > 0 && border % 3 == 0) { if (border == 15) { land.biome = 3; } else { land.IsBorder = true; land.BorderBiome = 3; land.Border = border / 3; } } } else if (land.biome == 3) { int border = 0; for (int i = 0; i < 4; i++) { Land adjacentLand = landArray[x - MovementXY2[i, 0], y - MovementXY2[i, 1]]; if (!adjacentLand.IsBorder && (adjacentLand.biome != 3 || adjacentLand.IsBorder)) { border += (int)Math.Pow(2, i); } } if (border > 0 && border % 3 == 0) { if (border == 15) { land.biome = 3; } else { land.biome = 1; land.IsBorder = true; land.BorderBiome = 3; land.Border = border / 3; } } } } } } }
public static async Task All() { double rnd; byte biomeHolder; Land checkPosX; Land checkPosY; Land checkNegX; Land checkNegY; Land checkTile; /* * The following statements will populate the land values of the default array 1000 x 1000 * as well as the tile cache array currently 400 x 250 which will * support the tile scale .1 (10x) on most resolution scales * ^^--pending optimization--^^ * a roll is done to determine some land values as well as if the tile will be a new biome * and then check the previously drawn X & Y tiles for water or trees to increase clumping * before going on to generate full biomes, to scale * the biomes are then expanded on with more complex near-by random tile generation * done through multiple rescans of the default global land array for definition * default snow i = 40 * default ore i = 5 */ for (int y = 0; y < 1000; y++) { for (int x = 0; x < 1000; x++) { rnd = Random.Next(0, 10000); ///////////////////////// // New Biome Initiator // ///////////////////////// if (rnd < 5) { biomeHolder = 0; } else { biomeHolder = 1; } ///////////////////////////////////////////////////////////// // Randomly Generate and Instantiate Land Stored in Arrays // ///////////////////////////////////////////////////////////// landArray[x, y] = new Land(); landArray[x, y].biome = biomeHolder; if (rnd <= 9390) { landArray[x, y].land = 0; } else if (rnd > 9390 && rnd <= 9400) { landArray[x, y].land = 2; } else if (rnd > 9400 && rnd <= 9800) { landArray[x, y].land = 3; } else if (rnd > 9800 && rnd <= 9900) { landArray[x, y].land = 4; } else if (rnd > 9900 && rnd <= 9995) { landArray[x, y].land = 5; } else if (rnd > 9995) { landArray[x, y].land = -6; } ///////////////////// // Realistic Water // ///////////////////// if (landArray[Check.Min(x - 1, 0), y].land == 2 && rnd < 5300) { landArray[x, y].land = 2; } else if (landArray[x, Check.Min(y - 1, 0)].land == 2 && rnd < 5300) { landArray[x, y].land = 2; } else if (landArray[x, Check.Min(y - 1, 0)].land == 2 && landArray[Check.Min(x - 1, 0), y].land == 2 && rnd < 9900) { landArray[x, y].land = 2; } /////////////////////// // Realistic Forests // /////////////////////// if (landArray[Check.Min(x - 1, 0), y].land == 5 && rnd < 3500) { landArray[x, y].land = 5; } else if (landArray[x, Check.Min(y - 1, 0)].land == 5 && rnd < 3500) { landArray[x, y].land = 5; } else if (landArray[x, Check.Min(y - 1, 0)].land == 5 && landArray[Check.Min(x - 1, 0), y].land == 5 && rnd < 9600) { landArray[x, y].land = 5; } } } MainMenuOpen = false; Show.CursorOutline = true; LogicClock40.Start(); LogicClock100.Start(); LogicClock250.Start(); LogicClock500.Start(); LogicClock1000.Start(); UpdateDestination.Start(); ///////////////////// // Generate Biomes // ///////////////////// for (int y = 0; y < 1000; y++) { for (int x = 0; x < 1000; x++) { if (landArray[x, y].biome == 0) { rnd = Random.Next(2, 4); landArray[x, y].biome = (int)rnd; Biome(x - 1, y - 1, (int)rnd, landArray); } if (landArray[x, y].land == -6) { landArray[x, y].land = 6; Land(x - 1, y - 1, 6, landArray); } } } ///////////////////////////////////// // Expanded Deserts || Default i < 50 // ///////////////////////////////////// for (int i = 0; i < 30; i++) { for (int y = 0; y < 1000; y++) { for (int x = 0; x < 1000; x++) { checkTile = landArray[x, y]; checkPosX = landArray[Check.Max(x + 1, 999), y]; checkPosY = landArray[x, Check.Max(y + 1, 999)]; checkNegX = landArray[Check.Min(x - 1, 0), y]; checkNegY = landArray[x, Check.Min(y - 1, 0)]; if (checkTile.biome != 3) { rnd = Random.Next(0, 1000); if (checkNegX.biome == 3) { rnd = rnd * 1.25; } if (checkNegY.biome == 3) { rnd = rnd * 1.25; } if (checkPosX.biome == 3) { rnd = rnd * 1.25; } if (checkPosY.biome == 3) { rnd = rnd * 1.25; } if (rnd > 1120) { landArray[x, y].biome = 3; } } } } } ///////////////////////////////////// // Expanded Snow || Default i < 50 // ///////////////////////////////////// for (int i = 0; i < 40; i++) { for (int y = 0; y < 1000; y++) { for (int x = 0; x < 1000; x++) { checkTile = landArray[x, y]; checkPosX = landArray[Check.Max(x + 1, 999), y]; checkPosY = landArray[x, Check.Max(y + 1, 999)]; checkNegX = landArray[Check.Min(x - 1, 0), y]; checkNegY = landArray[x, Check.Min(y - 1, 0)]; if (checkTile.biome != 2) { rnd = Random.Next(0, 1000); if (checkNegX.biome == 2) { rnd = rnd * 1.25; } if (checkNegY.biome == 2) { rnd = rnd * 1.25; } if (checkPosX.biome == 2) { rnd = rnd * 1.25; } if (checkPosY.biome == 2) { rnd = rnd * 1.25; } if (rnd > 1120) { landArray[x, y].biome = 2; } } } } } //////////////////////////////////// // Sparse Nodes || Default i < 5 // //////////////////////////////////// for (int i = 0; i < 5; i++) { for (int y = 0; y < 1000; y++) { for (int x = 0; x < 1000; x++) { checkTile = landArray[x, y]; checkPosX = landArray[Check.Max(x + 1, 999), y]; checkPosY = landArray[x, Check.Max(y + 1, 999)]; checkNegX = landArray[Check.Min(x - 1, 0), y]; checkNegY = landArray[x, Check.Min(y - 1, 0)]; if (landArray[x, y].biome != 3) { rnd = Random.Next(0, 1000); int node = 6; if (Random.Next(0, 6) == 5) { node = Random.Next(10, 19); } if (landArray[Check.Min(x - 1, 0), y].land == 6 && rnd > 650) { landArray[x, y].land = node; } if (landArray[x, Check.Min(y - 1, 0)].land == 6 && rnd > 650) { landArray[x, y].land = node; } if (landArray[Check.Max(x + 1, 999), y].land == 6 && rnd > 650) { landArray[x, y].land = node; } if (landArray[x, Check.Max(y + 1, 999)].land == 6 && rnd > 650) { landArray[x, y].land = node; } } if (checkTile.land != 5 && checkTile.land != 2) { rnd = Random.Next(0, 1000); if (checkNegX.land == 5) { rnd = rnd * 1.5; } if (checkNegY.land == 5) { rnd = rnd * 1.5; } if (checkPosX.land == 5) { rnd = rnd * 1.5; } if (checkPosY.land == 5) { rnd = rnd * 1.5; } if (rnd > 1050) { checkTile.land = 5; } } } } } Edges(); Player.WorldItems.Add(new GPS(50, 50, 0), 0); }