Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        public override void update(GameTime gameTime, bool hasFocus)
        {
            //each update the timer for the ocean tile update is increased by the elapsed time between the last update and this one.
            OceanTextureUpdateTimer += gameTime.ElapsedGameTime.TotalSeconds;
            if (OceanTextureUpdateTimer >= 1) //if the elapsed time is more than one second then generate a new texture for the water tiles and reset the timer
            {
                GenTextures.setWaterTexture(new Random().Next(), ref Game1.Water);
                OceanTextureUpdateTimer = 0f;
            }

            //if the screen is active
            if (state == ScreenState.Active)
            {
                //handles input. If T is pressed we need to make the GUI to leave the island appear, if escape is pressed then we need to pause the game
                if (input.isNewPress(Keys.T))
                {
                    manager.addScreen(new ScreenLeaveIslandDialogue(manager, input, this));
                }
                if (input.isNewPress(Keys.Escape))
                {
                    manager.addScreen(new ScreenPauseGame(manager, input, this));
                }

                Island.update(gameTime); //update the Island object where our level is stored.
                OverlayAlpha = 0;
            }
            //when the screen is transitioning on we need to increase the overlay alpha until it is 255 which means that it is completely transparent.
            else if (state == ScreenState.TransitionOn)
            {
                Island.update(gameTime);
                FadeTimer += gameTime.ElapsedGameTime.TotalSeconds;
                if (FadeTimer <= 2)
                {
                    OverlayAlpha = 255 - (int)(FadeTimer / 2.0 * 255);
                }
                else
                {
                    FadeTimer = 0;
                    state     = ScreenState.Active;
                }
            }
            //when transitioning off we need to decrease the overlay alpha until it is 0. When it is 0 we need to generate a new island
            //and set the screen to transition back on.
            else if (state == ScreenState.TransitionOff)
            {
                OverlayAlpha = (int)(FadeTimer / 2.0 * 255);

                FadeTimer += gameTime.ElapsedGameTime.TotalSeconds;
                if (FadeTimer >= 2)
                {
                    Island.generate(X, Y);
                    FadeTimer = 0;
                    state     = ScreenState.TransitionOn;
                }
            }
        }
Esempio n. 3
0
        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();
        }