Ejemplo n.º 1
0
        public override void Update(GameTime gameTime, StateManager screens, GamePadState gamePadState, MouseState mouseState, KeyboardState keyState, InputHandler input)
        {
            if (oldKeyboardState != keyState)
            {
                if (keyState.IsKeyDown(Keys.P))
                {
                    StateManager.Push(new PauseScreen());
                }

                if (keyState.IsKeyDown(Keys.Escape))
                {
                    StateManager.Pop();
                }

                if (keyState.IsKeyDown(Keys.Enter) && lander.State == Lander.landerState.landed)
                {
                    StateManager.Pop();
                    terrainNumber += 1;
                    StateManager.Push(new PlayScreen((terrainNumber % 3)));
                }

                oldKeyboardState = keyState;
            }


            lander.Update(gameTime);
            terrain.Update(gameTime);

            if (testCollision(lander.Points.ToArray(), terrain.Land.ToArray()))
            {
                lander.Crash();
                bgColor = Color.DarkRed;
            }
            else if (testCollision(lander.Points.ToArray(), terrain.LandingPads.ToArray()))
            {
                if (lander.XSpeed < 0.3f && lander.YSpeed < 0.6f && lander.Angle == 0)
                {
                    if (!sentScore)
                    {
                        StateManager.Score = StateManager.Score + (int)(lander.Fuel * 100);
                        sentScore          = true;
                    }
                    lander.winGame();
                    bgColor = Color.DarkGreen;
                }
                else
                {
                    lander.Crash();
                    bgColor = Color.DarkRed;
                }
            }

            handleSound();
        }