Esempio n. 1
0
        public void Update(GameTime gameTime)
        {
            fadeInOutTimer.Update(gameTime.TotalGameTime);
            changeLineTimer.Update(gameTime.TotalGameTime);

            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                screenController.GoToProgress();
            }
        }
Esempio n. 2
0
        public void Update(GameTime gameTime)
        {
            if (Math.Abs(velocity.X) < 0.1)
            {
                velocity.X = 0.0f;
            }

            if (Math.Abs(velocity.Y) < 0.1)
            {
                velocity.Y = 0.0f;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Space) && !jumping && !falling)
            {
                // Start a jump if one hasn't already been done
                jumping = true;

                // Y works negatively...
                targetJumpHeight = position.Y - MaxJumpHeight;
                velocity.Y       = -4;

                // If close to top speed then enable jump speed boost...
                if (velocity.X > TopSpeed - 0.001)
                {
                    velocity.X *= 1.1f;
                }
            }
            else if (jumping)
            {
                // velocity.Y = velocity.Y * JumpAcceleration;
                if (position.Y < targetJumpHeight)
                {
                    jumping    = false;
                    falling    = true;
                    velocity.Y = 1f;
                }
                else
                {
                    velocity.Y = velocity.Y * Gravity;
                }
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Left) && !jumping && !falling)
            {
                if (velocity.X > 0)
                {
                    velocity.X = 0;
                }

                if (Math.Abs(velocity.X) < 0.001)
                {
                    velocity.X = -1;
                }

                velocity.X *= Acceleration;
                if (Math.Abs(velocity.X) > TopSpeed)
                {
                    velocity.X = Math.Sign(velocity.X) * TopSpeed;
                }

                direction = Direction.Left;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Right) && !jumping && !falling)
            {
                if (direction == Direction.Left)
                {
                    velocity.X = 0;
                }

                if (Math.Abs(velocity.X) < 0.001)
                {
                    velocity.X = 1;
                }

                velocity.X *= Acceleration;
                if (Math.Abs(velocity.X) > TopSpeed)
                {
                    velocity.X = Math.Sign(velocity.X) * TopSpeed;
                }

                direction = Direction.Right;
            }
            else if (!jumping && !falling)
            {
                velocity.X = velocity.X * Deccelleration;
            }

            if (falling)
            {
                velocity.Y *= Gravity;

                if (velocity.Y > TerminalVelocity)
                {
                    velocity.Y = TerminalVelocity;
                }
            }


            var collisionChecks =
                level.CheckCollision(ProjectedBounds);

            if (velocity.X < 0 && collisionChecks.Left ||
                velocity.X > 0 && collisionChecks.Right)
            {
                velocity.X = 0;
            }
            else
            {
                position.X = position.X + velocity.X;
            }

            if (collisionChecks.Top && !collisionChecks.Bottom)
            {
                jumping    = false;
                falling    = true;
                velocity.Y = 2.0f;
                position.Y = ((int)(position.Y + velocity.Y) / 16) * 16;
            }
            else if (!collisionChecks.Bottom)
            {
                if (!jumping && !falling)
                {
                    velocity.X = velocity.X * 0.2f;

                    falling    = true;
                    velocity.Y = 2.0f;
                }

                position.Y = position.Y + velocity.Y;
            }
            else
            {
                falling    = false;
                jumping    = false;
                velocity.Y = 0;
            }

            if (!screenSpace.IsOutOfBounds(Bounds))
            {
                gameState.LivesRemaining--;
                screenController.GoToRetryLevel();
                return;
            }

            if (state.Evidence.Collides(Bounds))
            {
                state.EvidenceRetrieved = true;
            }

            foreach (var enemy in state.Enemies)
            {
                if (enemy.Collides(Bounds))
                {
                    gameState.LivesRemaining--;
                    screenController.GoToRetryLevel();
                    return;
                }
            }

            if (state.EvidenceRetrieved && state.Door.Collides(Bounds))
            {
                gameState.CurrentLevel++;
                screenController.GoToProgress();
                return;
            }
        }