示例#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();
        }
示例#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;
                }
            }
        }