protected override void Initialize() { //initialise all texture objects. Pixel = new Texture2D(this.GraphicsDevice, 1, 1); PlayerTexture = new Texture2D(this.GraphicsDevice, 32, 32); EntityTexture = new Texture2D(this.GraphicsDevice, 32, 32); Grass = new Texture2D(this.GraphicsDevice, Tile.TileSideLengthInPixels, Tile.TileSideLengthInPixels); HighMtn = new Texture2D(this.GraphicsDevice, Tile.TileSideLengthInPixels, Tile.TileSideLengthInPixels); LowMtn = new Texture2D(this.GraphicsDevice, Tile.TileSideLengthInPixels, Tile.TileSideLengthInPixels); Sand = new Texture2D(this.GraphicsDevice, Tile.TileSideLengthInPixels, Tile.TileSideLengthInPixels); Water = new Texture2D(this.GraphicsDevice, Tile.TileSideLengthInPixels, Tile.TileSideLengthInPixels); Torch = new Texture2D(this.GraphicsDevice, Tile.TileSideLengthInPixels, Tile.TileSideLengthInPixels); Pixel.SetData <Color>(new Color[] { Color.White }); //generate all textures using pre written functions. The fucntions take in a seed to generate them. GenTextures.setEntityTexture(1, ref EntityTexture); GenTextures.setGrassTexture(18390123, ref Grass); GenTextures.setStoneTexture(18390123, ref HighMtn); GenTextures.setStoneTexture(2134, ref LowMtn); GenTextures.setSandTexture(18390123, ref Sand); GenTextures.setWaterTexture(12341174, ref Water); GenTextures.setTorchTexture(45642323, ref Torch); //Initialize input manager for input inputManager = new Input(); //initialize screen manager object and add an instance of the main menu screenManager = new MScreenManager(inputManager); screenManager.addScreen(new ScreenMainMenu(screenManager, inputManager)); base.Initialize(); }
public void generate(int IX, int IY) { float NoiseVal; TileType Type = 0; // (old method)seed = (int)(0.5 * (double)((IX + IY) * (IX + IY + 1) + IY)); //pairing function, gives a unique integer based on two input coordinates seed = ((IX << 16) | IY) ^ 0x71EBA1C3; //bit shifts to combine the two coordinates and then adds an XOR bitmask over the top to create seed. GenTextures.setEntityTexture(seed, ref Game1.EntityTexture); //A new entity texture must be created using this seed. noise.setSeed(seed); for (int x = 0; x < 256; x++) { for (int y = 0; y < 256; y++) { NoiseVal = (float)noise.perlin(x, y, 0.01f) + //creates layered noise. The second layer is at a higher 0.5f * noise.perlin(x, y, 0.05f); // frequency and so creates more intricate details. float val = 1 - (float)Math.Sqrt(Math.Pow(127.5 - x, 2) + Math.Pow(127.5 - y, 2)) / 127f; NoiseVal *= val + 0.3f; //depending on how high the height map is, set the tile to a different type. if (NoiseVal < 0.9f) { Type = TileType.Mountain; } if (NoiseVal < 0.85f) { Type = TileType.Ridge; } if (NoiseVal < 0.70f) { if (new Random(seed + x << y).NextDouble() > 0.99) //use the seed and a combination of of the x and y to seed a random value. { //if the valeu is greater than 0.99, set the tile to a torhc. If else set it to grass. Type = TileType.Torch; } else { Type = TileType.Grass; } } if (NoiseVal < 0.58f) { Type = TileType.Sand; } if (NoiseVal < 0.55f) { Type = TileType.Shore; } if (NoiseVal < 0.45f) { Type = TileType.Ocean; } if (x == 0 || y == 255 || y == 0 || x == 255) { Type = TileType.OceanWall; //no matter what, the border tiles need to be ocean walls. } Map[x, y] = Tile.combineData(1, Type); } } Player = new EntityPlayer(findEmptySpace(seed)); //ReInitiliase the player object. generateEntities(seed + 1); generateLightMap(); }