示例#1
0
 private void StandingUpdate()
 {
     if (ActionMapper.IsPressed(UserAction.Jump))
     {
         Jump();
     }
 }
示例#2
0
        private void JumpingUpdate()
        {
            Body.ApplyLinearImpulse(new Vector2(0, -JUMP_IMPULSE));

            if (--jumpFramesRemaining <= 0 || !ActionMapper.IsPressed(UserAction.Jump))
            {
                state = States.Falling;
            }
        }
示例#3
0
        public override void Update(IScene scene, GameTime gameTime)
        {
            switch (state)
            {
            case States.Standing:
                StandingUpdate();
                break;

            case States.Jumping:
                JumpingUpdate();
                break;

            case States.Falling:
                FallingUpdate();
                break;

            case States.Walking:
                WalkingUpdate();
                break;
            }

            float xVel = 0;

            if (ActionMapper.IsPressed(UserAction.MoveLeft))
            {
                xVel -= WALK_IMPULSE;
            }

            if (ActionMapper.IsPressed(UserAction.MoveRight))
            {
                xVel += WALK_IMPULSE;
            }

            Body.ApplyLinearImpulse(new Vector2(xVel, 0));

            if (Body.LinearVelocity.X > MAX_HORIZONTAL_SPEED)
            {
                Body.LinearVelocity = new Vector2(MAX_HORIZONTAL_SPEED, Body.LinearVelocity.Y);
            }
            else if (Body.LinearVelocity.X < -MAX_HORIZONTAL_SPEED)
            {
                Body.LinearVelocity = new Vector2(-MAX_HORIZONTAL_SPEED, Body.LinearVelocity.Y);
            }

            lastVelocity = Body.LinearVelocity;
        }