Ejemplo n.º 1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            playerOne = new Player();
            input     = new InputClass();

            base.Initialize();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            playerOne = new Player();
            input = new InputClass();

            base.Initialize();
        }
Ejemplo n.º 3
0
        public void Update(InputClass input)
        {
            if (input.currentKeyboardState.IsKeyDown(Keys.Space) &&
                input.prevKeyboardState.IsKeyUp(Keys.Space) &&
                state != PlayerState.JUMPING && state != PlayerState.FALLING)
            {
                state = PlayerState.JUMPING;
                yVel  = -jumpHeight;
            }
            if (input.currentKeyboardState.IsKeyUp(Keys.Space) && state == PlayerState.JUMPING)
            {
                state = PlayerState.FALLING;
                yVel  = 0;
            }
            if (yVel >= 0 && state == PlayerState.JUMPING)
            {
                state = PlayerState.FALLING;
            }

            if (input.currentKeyboardState.IsKeyDown(Keys.Right))
            {
                xVel += acceleration;
                if (xVel > maxMoveSpeed)
                {
                    xVel = maxMoveSpeed;
                }
                if (yVel == 0 && state != PlayerState.FALLING)
                {
                    state = PlayerState.MOVING;
                }
            }
            else
            if (xVel > 0)
            {
                xVel -= acceleration;
                if (xVel < 0)
                {
                    xVel = 0;
                }
            }
            if (input.currentKeyboardState.IsKeyDown(Keys.Left))
            {
                xVel -= acceleration;
                if (xVel < -maxMoveSpeed)
                {
                    xVel = -maxMoveSpeed;
                }
                if (yVel == 0 && state != PlayerState.FALLING)
                {
                    state = PlayerState.MOVING;
                }
            }
            else
            if (xVel < 0)
            {
                xVel += acceleration;
                if (xVel > 0)
                {
                    xVel = 0;
                }
            }

            if (state != PlayerState.IDLE)
            {
                yVel += gravity;
                if (yVel > maxFallSpeed)
                {
                    yVel = maxFallSpeed;
                }
            }

            if (input.currentKeyboardState.IsKeyDown(Keys.LeftShift))
            {
                maxMoveSpeed = 15;
            }
            else
            {
                maxMoveSpeed = 6;
            }

            if (yVel > 0)
            {
                state = PlayerState.FALLING;
            }

            x += xVel;
            y += yVel;

            checkCollision();
        }
Ejemplo n.º 4
0
        public void Update(InputClass input)
        {
            if (input.currentKeyboardState.IsKeyDown(Keys.Space) &&
                input.prevKeyboardState.IsKeyUp(Keys.Space) &&
                state != PlayerState.JUMPING && state != PlayerState.FALLING)
            {
                state = PlayerState.JUMPING;
                yVel = -jumpHeight;
            }
            if (input.currentKeyboardState.IsKeyUp(Keys.Space) && state == PlayerState.JUMPING)
            {
                state = PlayerState.FALLING;
                yVel = 0;
            }
            if (yVel >= 0 && state == PlayerState.JUMPING)
            {
                state = PlayerState.FALLING;
            }

            if (input.currentKeyboardState.IsKeyDown(Keys.Right))
            {
                xVel += acceleration;
                if(xVel > maxMoveSpeed)
                    xVel = maxMoveSpeed;
                if (yVel == 0 && state != PlayerState.FALLING)
                    state = PlayerState.MOVING;
            }
            else
                if (xVel > 0)
                {
                    xVel -= acceleration;
                    if (xVel < 0)
                        xVel = 0;
                }
            if (input.currentKeyboardState.IsKeyDown(Keys.Left))
            {
                xVel -= acceleration;
                if (xVel < -maxMoveSpeed)
                    xVel = -maxMoveSpeed;
                if (yVel == 0 && state != PlayerState.FALLING)
                    state = PlayerState.MOVING;
            }
            else
                if (xVel < 0)
                {
                    xVel += acceleration;
                    if (xVel > 0)
                        xVel = 0;
                }

            if (state != PlayerState.IDLE)
            {
                yVel += gravity;
                if (yVel > maxFallSpeed)
                {
                    yVel = maxFallSpeed;
                }
            }

            if (input.currentKeyboardState.IsKeyDown(Keys.LeftShift))
            {
                maxMoveSpeed = 15;
            }
            else
            {
                maxMoveSpeed = 6;
            }

            if (yVel > 0)
            {
                state = PlayerState.FALLING;
            }

            x += xVel;
            y += yVel;

            checkCollision();
        }