示例#1
0
        private void Standing()
        {
            Jumped    = KB_preState.IsKeyDown(Keys.W) ? true : false;
            yVelocity = xVelocity = 0;

            //if (KB_curState.IsKeyDown(Keys.G) && !KB_preState.IsKeyDown(Keys.G))
            //{
            //    if (level == Level.Fire)
            //    {
            //        if (Game.FireBalls.Count < 2)
            //        {
            //            Game.Add_NewFireball();
            //            state = State.ThrowFire;
            //        }
            //    }
            //}

            if (KB_curState.IsKeyDown(Keys.D))
            {
                movingRight = true;
                state       = State.Walking;
            }
            else if (KB_curState.IsKeyDown(Keys.A))
            {
                movingRight = false;
                state       = State.Walking;
            }
            else if (KB_curState.IsKeyDown(Keys.W))
            {
                if (!Jumped)
                {
                    lastY     = positionRectangle.Y;
                    yVelocity = Constants.jump_velocity;
                    state     = State.Jumping;
                }
            }
        }
示例#2
0
        private void Walking()
        {
            Jumped = KB_preState.IsKeyDown(Keys.W) ? true : false;
            state  = State.Walking;
            float max_v;

            if (KB_curState.IsKeyDown(Keys.G)) //run key
            {
                max_v         = Constants.max_run_velocity;
                xAcceleration = Constants.run_accelerate;
                Speedup       = true;
            }
            else
            {
                max_v         = Constants.max_walk_velocity;
                xAcceleration = Constants.walk_accelerate;
                Speedup       = false;
            }

            if (KB_curState.IsKeyDown(Keys.D))
            {
                //moving right
                movingRight = true;
                if (xVelocity < 0) //walking left earlier
                {
                    state          = State.Turn;
                    xAcceleration += 0.3f;
                }

                if (xVelocity > max_v) //slow down if pre-state was spdup
                {
                    xVelocity -= xAcceleration;
                }
                else if (xVelocity < max_v) //speed up if not reach max_v
                {
                    xVelocity += xAcceleration;
                }
            }
            else if (KB_curState.IsKeyDown(Keys.A))
            {
                //moving left
                movingRight = false;
                if (xVelocity > 0) //walking right earlier
                {
                    state          = State.Turn;
                    xAcceleration += 0.3f;
                }

                if (xVelocity < max_v * -1) //slow down if pre-state was spdup
                {
                    xVelocity += xAcceleration;
                }
                else if (xVelocity > max_v * -1) //speed up if not reach max_v
                {
                    xVelocity -= xAcceleration;
                }
            }
            else
            {
                //slow down (moving right or left)
                if (movingRight)
                {
                    if (xVelocity > 0) //slow down then stop
                    {
                        xVelocity -= xAcceleration * 5;
                    }
                    else // moving left earlier -> stop immediately
                    {
                        xVelocity = 0;
                        state     = State.Standing;
                    }
                }
                else
                {
                    if (xVelocity < 0) //slow down then stop
                    {
                        xVelocity += xAcceleration * 5;
                    }
                    else // moving left earlier -> stop immediately
                    {
                        xVelocity = 0;
                        state     = State.Standing;
                    }
                }
            }
            if (KB_curState.IsKeyDown(Keys.W))
            {
                if (!Jumped)
                {
                    lastY     = positionRectangle.Y;
                    yVelocity = Constants.jump_velocity;
                    state     = State.Jumping;
                }
            }
        }