示例#1
0
        public virtual void Update(GameTime pGameTime, ref InputHandler pInputHandler, Level.Level pLevel)
        {
            Vector2 currentPosition = this.Position;

            if (m_PlayerType == PlayerType.Local)
            {
                // When past a certain threshold then move with the given constant added on.
                if (pInputHandler.GetInput(this.m_PlayerIndex).ThumbSticks.Left.X > 0.15f)
                {
                    this.m_Direction = Direction.Right;
                    this.m_Action = ActionFlag.Running;
                    this.m_Position.X += RUN_SPEED;
                }

                // Same again, but opposite direction.
                if (pInputHandler.GetInput(this.m_PlayerIndex).ThumbSticks.Left.X < -0.15)
                {
                    this.m_Direction = Direction.Left;
                    this.m_Action = ActionFlag.Running;
                    this.m_Position.X += -RUN_SPEED;
                }

                // Make sure the stick is within the deadzone before declaring the character as idle.
                if (pInputHandler.GetInput(this.m_PlayerIndex).ThumbSticks.Left.X < 0.15f &&
                    pInputHandler.GetInput(this.m_PlayerIndex).ThumbSticks.Left.X > -0.15f)
                {
                    m_Action = ActionFlag.Idle;
                }

                if (pInputHandler.isButtonDown(this.m_PlayerIndex, Buttons.A))
                {
                   //Console.WriteLine("Player: Jump");
                    this.m_Action = ActionFlag.Jump;

                }

                #region Frame Handling

                switch (m_Action)
                {
                    case ActionFlag.Running:
                        m_FrameIndex.Y = 2;

                        if (m_FrameIndex.X == 0)
                        {
                            m_FrameIndex.X = 1;
                        }

                        // Increase the counter
                        m_FrameChangeCounter += (float) pGameTime.ElapsedGameTime.TotalMilliseconds;

                        // Has the counter exceeded the rate at which we want the animations to animate?
                        if (m_FrameChangeCounter > m_FrameChangeRate)
                        {
                            m_FrameChangeCounter = 0;
                            m_FrameIndex.X++;
                        }

                        // Out of animation bound -- restart.
                        if (m_FrameIndex.X > 2)
                        {
                            m_FrameIndex.X = 1;
                        }
                    break;

                    case ActionFlag.Jump:
                        m_FrameChangeCounter = 0;
                        m_FrameIndex.X = 0;
                        m_FrameIndex.Y = 3;
                    break;

                    case ActionFlag.Crouch:

                        m_FrameIndex.X = 0;
                        m_FrameIndex.Y = 3;
                    break;

                    case ActionFlag.Walking:

                        // Define the row that we want to animate from
                        m_FrameIndex.Y = 2;

                        if (m_FrameIndex.X > 3)
                        {
                            m_FrameIndex.X = 0;
                        }
                        else
                        {
                            m_FrameIndex.X++;
                        }
                    break;

                    case ActionFlag.Idle:
                        m_FrameIndex.Y = 2;
                        m_FrameIndex.X = 0;

                        m_FrameChangeCounter = 0f;
                     break;
                }

                #endregion

                // Check for collisions with the level here.

                // If there is a collision with the lev

            }
            else if (m_PlayerType == PlayerType.Net)
            {
                // Receive the data from the internets!

                //
            }

            base.Update(pGameTime, ref pInputHandler);
        }
        public void Update(GameTime pGameTime, ref InputHandler pInputHandler)
        {
            // Select item on the list properly.
            if (pInputHandler.isButtonDown(PlayerIndex.One, Buttons.DPadDown))
            {
                Console.WriteLine("Dpad was touched");
                NextItem();
            }

            if (pInputHandler.isButtonDown(PlayerIndex.One, Buttons.DPadUp))
            {
                Console.WriteLine("Dpad was touched");
                PreviousItem();
            }

            if (pInputHandler.isButtonDown(PlayerIndex.One, Buttons.A))
            {
                Main.INSTANCE.CurrentGameState = (GameState)m_SelectionIndex;
            }
        }