protected override void LoadContent() { //Create sprite batch spriteBatch = new SpriteBatch(GraphicsDevice); //Create chunks Chunks = new Chunk[WorldMetrics.ChunkCountX, WorldMetrics.ChunkCountY]; //Load ground and damage textures GroundTexture = Content.Load <Texture2D>("Environment/Blocks/Terrain/Terrain_SpriteSheet"); BreakTextures = new Texture2D[5]; for (int i = 1; i <= 5; i++) { BreakTextures[i - 1] = Content.Load <Texture2D>("Environment/Blocks/Damage/" + i.ToString()); } //Load other textures Player = Content.Load <Texture2D>("UI/Cursor"); defaultFont = Content.Load <SpriteFont>("Fonts/Arial"); Cursor = Content.Load <Texture2D>("UI/Cursor"); BackgroundTexture = Content.Load <Texture2D>("Environment/Blocks/Background/Background"); player = new Player(); //Block data Data = new BlockData[] { new BlockData("Stone", 61, 61, 61, 0, 900, 10), new BlockData("Copper", 197, 105, 70, 900, 910, 4), new BlockData("Iron", 151, 176, 212, 910, 920, 4), new BlockData("Aluminum", 173, 178, 183, 920, 930, 3), new BlockData("Coal", 33, 33, 33, 930, 940, 5), new BlockData("Lithium", 158, 183, 188, 940, 945, 2), new BlockData("Sulfur", 224, 250, 103, 945, 950, 1), new BlockData("Titanium", 242, 242, 242, 950, 955, 2), new BlockData("Chrome", 204, 202, 228, 955, 958, 1), new BlockData("Nickel", 229, 214, 132, 958, 968, 3), new BlockData("Silver", 215, 205, 243, 968, 971, 1), new BlockData("Tin", 144, 153, 184, 971, 981, 4), new BlockData("Tungsten", 44, 45, 51, 981, 986, 2), new BlockData("Lead", 51, 29, 60, 986, 996, 3), new BlockData("Iridium", 244, 243, 245, 996, 997, 0), new BlockData("Uranium", 146, 217, 136, 997, 998, 1), new BlockData("Gold", 239, 169, 46, 998, 1000, 1) }; //Generate world : //Create random instance IOModule.Init(); //string worldData = IOModule.ReadFull(); string worldData = ""; if (worldData == "") { NoiseGenerator.generateNoise(6, 45, 0.16, 0.45, seed); Random r = new Random(seed.GetHashCode()); for (int ChunkX = 0; ChunkX < WorldMetrics.ChunkCountX; ChunkX++) { for (int ChunkY = 0; ChunkY < WorldMetrics.ChunkCountY; ChunkY++) { //Loop through all chunks Chunks[ChunkX, ChunkY] = new Chunk(WorldMetrics.ChunkSizeX, WorldMetrics.ChunkSizeY, ChunkX, ChunkY, this); for (int x = 0; x < WorldMetrics.ChunkSizeX; x++) { for (int y = 0; y < WorldMetrics.ChunkSizeY; y++) { //Loop through all blocks and randomize thems //Generate noise float noise = (float)NoiseGenerator.Noise(ChunkX * WorldMetrics.ChunkSizeX + x, ChunkY * WorldMetrics.ChunkSizeY + y); Chunks[ChunkX, ChunkY].Blocks[x, y].ID = (noise >= 0.4f) ? 1 : 0; Chunks[ChunkX, ChunkY].Blocks[x, y].Hardness = 6; if (Chunks[ChunkX, ChunkY].GetBlock(x, y) == 0) { CameraPosition = new Vector2(ChunkX * WorldMetrics.ChunkSizeX + x, ChunkY * WorldMetrics.ChunkSizeY + y); CameraPosition -= new Vector2(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2); } else { int i = 1; foreach (BlockData bd in Data) { float rL = bd.RarityL / 1000f; float rR = bd.RarityR / 1000f; if (rL <= noise && rR > noise) { Chunks[ChunkX, ChunkY].Blocks[x, y].ID = i; if (i != 1) { PopulateOre(ChunkX * WorldMetrics.ChunkSizeX + x, ChunkY * WorldMetrics.ChunkSizeY + y, i, r); } break; } i++; } } } } } } //Loop through all chunks and smooth them using Cellular Automata for (int x = 0; x < WorldMetrics.ChunkCountX; x++) { for (int y = 0; y < WorldMetrics.ChunkCountY; y++) { for (int i = 0; i < 2; i++) { //Chunks[x, y].Smooth(r); } } } } else { worldData = worldData.Replace("\r", ""); string[] DataSplit = worldData.Split('\n'); int index = 0; for (int ChunkX = 0; ChunkX < WorldMetrics.ChunkCountX; ChunkX++) { for (int ChunkY = 0; ChunkY < WorldMetrics.ChunkCountY; ChunkY++) { string a = DataSplit[index]; index++; //Loop through all chunks Chunks[ChunkX, ChunkY] = new Chunk(WorldMetrics.ChunkSizeX, WorldMetrics.ChunkSizeY, ChunkX, ChunkY, this); for (int x = 0; x < WorldMetrics.ChunkSizeX; x++) { string Row = DataSplit[index]; string[] RowCols = Row.Split(' '); for (int y = 0; y < WorldMetrics.ChunkSizeY; y++) { Chunks[ChunkX, ChunkY].Blocks[x, y].ID = System.Convert.ToInt32(RowCols[y]); Chunks[ChunkX, ChunkY].Blocks[x, y].Hardness = 6; } index++; } } } string CamPos = DataSplit[index]; float xc = (float)System.Convert.ToDouble(CamPos.Split(',')[0]); float yc = (float)System.Convert.ToDouble(CamPos.Split(',')[1]); CameraPosition = new Vector2(xc, yc); } //Recalculate block states for (int x = 0; x < WorldMetrics.ChunkCountX; x++) { for (int y = 0; y < WorldMetrics.ChunkCountY; y++) { Chunks[x, y].Recalculate(); } } ScreenWidthSquared = (int)Math.Pow(graphics.PreferredBackBufferWidth / 2f, 2) * 2f; }