示例#1
0
        /// <summary>
        /// Update based on user input and state
        /// </summary>
        /// <param name="gameTime">Game's time</param>
        private void updateState(GameTime gameTime)
        {
            // Reset direction
            movementDirection = Vector2.Zero;

            // Update existing pepper
            if (pepper != null)
            {
                pepper.Update(gameTime);

                if (pepper.IsTimeUp)
                {
                    pepper = null;
                }
            }

            // Update state based on state and behaviour
            switch (state)
            {
                case State.Dead:

                    break;

                case State.Dying:

                    if (artist.IsAnimationComplete)
                    {
                        TransitionToState(State.Dead);
                    }

                    break;

                case State.Walking:

                    // Check input
                    handleInput();

                    // If no movement, static
                    if (movementDirection == Vector2.Zero && inputTimer > inputTime)
                    {
                        TransitionToState(State.StaticWalk);
                    }

                    break;

                case State.Climbing:

                    // Check input
                    handleInput();

                    // If no movement, static
                    if (movementDirection == Vector2.Zero && inputTimer > inputTime)
                    {
                        TransitionToState(State.StaticClimb);
                    }

                    break;

                case State.StaticWalk:

                    // Check input
                    handleInput();

                    // If no movement, static
                    if (movementDirection != Vector2.Zero)
                    {
                        if ((int)Math.Round(Math.Abs(movementDirection.X)) == 1)
                        {
                            TransitionToState(State.Walking);
                        }
                        else
                        {
                            TransitionToState(State.Climbing);
                        }
                    }

                    break;

                case State.StaticClimb:

                    // Check input
                    handleInput();

                    // If no movement, static
                    if (movementDirection != Vector2.Zero)
                    {
                        if ((int)Math.Round(Math.Abs(movementDirection.X)) == 1)
                        {
                            TransitionToState(State.Walking);
                        }
                        else
                        {
                            TransitionToState(State.Climbing);
                        }
                    }

                    break;

                case State.Pepper:

                    // Done with pepper animation
                    if (artist.IsAnimationComplete)
                    {
                        createPepper();

                        DataManager.GetInstance().UsePepper();

                        if (faceDirection == Vector2.UnitY || faceDirection == -Vector2.UnitY)
                        {
                            TransitionToState(State.Climbing);
                        }
                        else
                        {
                            TransitionToState(State.Walking);
                        }
                    }

                    break;
            }
        }
示例#2
0
        /// <summary>
        /// Create a pepper attack
        /// </summary>
        private void createPepper()
        {
            float scale = SettingsManager.GetInstance().Scale;

            if (faceDirection == Vector2.UnitX)
            {
                pepper = new Pepper(position + new Vector2(boundingBox.Bounds.Width * 2, 0), 25 * scale, 39 * scale, 0, 300);
            }
            else if (faceDirection == -Vector2.UnitX)
            {
                pepper = new Pepper(position - new Vector2(boundingBox.Bounds.Width * 2, 0), 25 * scale, 39 * scale, 0, 300);
            }
            else if (faceDirection == Vector2.UnitY)
            {
                pepper = new Pepper(position + new Vector2(0, boundingBox.Bounds.Height * 2), 25 * scale, 39 * scale, 0, 300);
            }
            else
            {
                pepper = new Pepper(position - new Vector2(0, boundingBox.Bounds.Height * 2), 25 * scale, 39 * scale, 0, 300);
            }
        }