Пример #1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (!world.GameComplete)
            {
                timer += gameTime.ElapsedGameTime.Milliseconds;
            }

            if (!songPlaying)
            {
                MediaPlayer.Play(song);
                songPlaying = true;
            }

            world.Update(gameTime);
            camera.Position = new Vector2(player.X, player.Y - player.Height - 10);

            if (Keyboard.GetState().IsKeyDown(Keys.R))
            {
                timer = 0;
                player.SetX((world.Bounds.Width / 2) - 200);
                player.SetY(world.Bounds.Height - 110);
                world.GameComplete = false;
                world.FlagManager.ResetFlags();
                player.State = player.States.falling;
            }


            base.Update(gameTime);
        }
Пример #2
0
        public void Update(GameTime gameTime)
        {
            Player.Update(gameTime);

            FlagManager.Update(gameTime);

            if (FlagManager.CompletedCount >= FlagManager.FlagCount)
            {
                GameComplete = true;
            }

            // Platform collision logic
            Tuple <bool, Platform, bool> platformResults = PlatformManager.PlayerOnPlatform();

            if (platformResults.Item1 && (Player.State == Player.States.running || Player.State == Player.States.standing))
            {
                if (platformResults.Item2.Bounds.X < Player.X)
                {
                    Player.SetX(platformResults.Item2.Bounds.X + platformResults.Item2.Bounds.Width - 5);
                }
                else
                {
                    Player.SetX(platformResults.Item2.Bounds.X - Player.CollisionBox.Width - 1);
                }
            }

            if (platformResults.Item1 && Player.State == Player.States.jumping)
            {
                if (platformResults.Item2.Bounds.Y < Player.CollisionBox.Y)
                {
                    Player.VerticalSpeed = 0;
                    Player.SetY(platformResults.Item2.Bounds.Y + platformResults.Item2.Bounds.Height);
                }
            }

            if (platformResults.Item1 && (Player.State == Player.States.falling || Player.State == Player.States.jumping))
            {
                if (platformResults.Item2.Bounds.Y - (Player.Y + Player.Height) > -27)
                {
                    Player.State = Player.States.standing;
                    Player.SetY(platformResults.Item2.Bounds.Y - Player.Height - 1);
                }
                else if (platformResults.Item2.Bounds.Y + platformResults.Item2.Bounds.Height > Player.Y)
                {
                    if (platformResults.Item2.Bounds.X < Player.X)
                    {
                        Player.SetX(platformResults.Item2.Bounds.X + platformResults.Item2.Bounds.Width);
                    }
                    else
                    {
                        Player.SetX(platformResults.Item2.Bounds.X - Player.CollisionBox.Width - 1);
                    }
                }
            }
            else if (Player.State != Player.States.jumping && platformResults.Item3 == false)
            {
                Player.State = Player.States.falling;
            }

            Player.UpdateAnimation(gameTime);
        }