Ejemplo n.º 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // Handles animation for you
            mario.UpdateAnimation(gameTime);

            // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
            // PRACTICE EXERCISE: Add your finite state machine code (switch statement) here!
            // - Be sure to check the finite state machine's state first
            // - Then check for specific transitions inside each state (may require keyboard input)
            // - Update Mario's state as needed

            // Step 1: Grab user input

            // Step 2: Change state
            // Step 3: Move Mario only when walking

            // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

            base.Update(gameTime);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // Handles animation for you
            mario.UpdateAnimation(gameTime);

            // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
            // PRACTICE EXERCISE: Add your finite state machine code (switch statement) here!
            // - Be sure to check the finite state machine's state first
            // - Then check for specific transitions inside each state (may require keyboard input)
            // - Update Mario's state as needed

            // Step 1: Grab user input

            // Step 2: Change state
            // Step 3: Move Mario only when walking

            // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
            KeyboardState kbState = Keyboard.GetState();

            switch (mario.State)
            {
                case MarioState.FaceLeft:
                    if (kbState.IsKeyDown(Keys.Left) == true)
                    {
                        mario.State = MarioState.WalkLeft;
                    }
                    else if(kbState.IsKeyDown(Keys.Right) == true)
                    {
                        mario.State = MarioState.FaceRight;
                        break;
                    }
                    else if(kbState.IsKeyDown(Keys.Down) == true)
                    {
                        mario.State = MarioState.CrouchLeft;
                        break;
                    }
                    break;
                case MarioState.WalkLeft:
                    if(kbState.IsKeyDown(Keys.Left) == true)
                    {
                        mario.X -= 3.0f;
                        break;
                    }
                    else if(kbState.IsKeyUp(Keys.Left) == true)
                    {
                        mario.State = MarioState.FaceLeft;
                        break;
                    }
                    break;
                case MarioState.FaceRight:
                    if (kbState.IsKeyDown(Keys.Right) == true)
                    {
                        mario.State = MarioState.WalkRight;
                        break;
                    }
                    else if(kbState.IsKeyDown(Keys.Left) == true)
                    {
                        mario.State = MarioState.FaceLeft;
                        break;
                    }
                    else if(kbState.IsKeyDown(Keys.Down) == true)
                    {
                        mario.State = MarioState.CrouchRight;
                        break;
                    }
                    break;
                case MarioState.WalkRight:
                    if(kbState.IsKeyDown(Keys.Right) == true)
                    {
                        mario.X += 3.0f;
                        break;
                    }
                    else if(kbState.IsKeyUp(Keys.Right) == true)
                    {
                        mario.State = MarioState.FaceRight;
                        break;
                    }
                    break;
                case MarioState.CrouchLeft:
                    if(kbState.IsKeyDown(Keys.Down) == true)
                    {
                        break;
                    }
                    else if(kbState.IsKeyUp(Keys.Down) == true)
                    {
                        mario.State = MarioState.FaceLeft;
                        break;
                    }
                    break;
                case MarioState.CrouchRight:
                    if(kbState.IsKeyDown(Keys.Down) == true)
                    {
                        break;
                    }
                    else if(kbState.IsKeyUp(Keys.Down) == true)
                    {
                        mario.State = MarioState.FaceRight;
                        break;
                    }
                    break;
                default:
                    break;
            }

            base.Update(gameTime);
        }