Exemplo n.º 1
0
        public override void Update(GameTime gameTime, StateManager screen, GamePadState gamePadState, MouseState mouseState, KeyboardState keyboardState, InputHandler input)
        {
            #region Key Presses
            if (input.KeyboardState.WasKeyPressed(Keys.Escape) || input.WasPressed(0, InputHandler.ButtonType.A, Keys.P))
            {
                screen.Push(new PauseScreen());
            }
            #endregion

            #region Global Checks [Reset Game, Main Menu]
            if (GlobalValues.ResetGame)
            {
                ResetValues();
            }

            if (GlobalValues.GoToMainMenu)
            {
                screen.Pop();
            }
            else
            {
                lander.Update(gameTime);
            }
            #endregion

            #region Scroll Map

            if (GlobalValues.LevelLoaded == "Random")
            {
                shiftTime += gameTime.ElapsedGameTime;

                float xVelocity = LanderValues.Velocity.X;

                if (xVelocity < 0)
                {
                    xVelocity *= -1;
                }

                float speed = (MathHelper.Lerp(800, 75, (xVelocity / 5f)));

                if (speed < 0)
                {
                    speed *= -1;
                }

                if (shiftTime > TimeSpan.FromMilliseconds(speed))
                {
                    shiftTime -= TimeSpan.FromMilliseconds(speed);

                    if (LanderValues.RightBoundHit)
                    {
                        mapShiftPosition -= new Vector2(GlobalValues.ScreenBuffer, 0);
                        Terrain.NewRandomLine(false, mapShiftPosition.X);
                    }

                    if (LanderValues.LeftBoundHit)
                    {
                        mapShiftPosition += new Vector2(GlobalValues.ScreenBuffer, 0);
                        Terrain.NewRandomLine(true, mapShiftPosition.X);
                    }

                    Terrain.FixTerrainHitboxes(mapShiftPosition);
                    Terrain.FixPadHitboxes(mapShiftPosition);
                }
            }

            #endregion

            #region Win Loss Check
            if (lander.DidLose())
            {
                LoadContent();
                ResetValues();
                screen.Push(new LoseScreen());
            }

            if (lander.DidWin())
            {
                TimeSpan landerTime = lander.GetGameTime();
                LoadContent();
                lander.SetGameTime(landerTime);
                screen.Push(new WinScreen());
            }
            #endregion

            #region Debug
            //Show debug info
            if (input.KeyboardState.WasKeyPressed(Keys.OemTilde))
            {
                //Switches debug mode on or off
                debugMode = !debugMode;
            }
            #endregion
        }