Example #1
0
        /// <summary>
        /// Updates all objects in the world, performs collision between them,
        /// and handles the time limit.
        /// </summary>
        public void Update(GameTime gameTime, InputHandler gameInputs)
        {
            //switching characters in the air screws up the physics sometimes
            //This is a work around, but I would like to fix the bug
            if (activeHero.IsOnGround && activeHero.IsAlive)
            {
                SwapHeroes(gameInputs);
            }


            // Pause while the activeHero is dead or time is expired.
            if (!ActiveHero.IsAlive || TimeRemaining == TimeSpan.Zero)
            {
                // Still want to perform physics on the activeHero.
                ActiveHero.PhysicsEngine.ApplyPhysics(gameTime);

                ((Gun)Heroes[0].Weapon).UpdateBullets();
                ((Gun)Heroes[1].Weapon).UpdateBullets();
                ((Gun)Heroes[2].Weapon).UpdateBullets();
            }
            else if (ReachedExit)
            {
                // Animate the time being converted into points.
                int seconds = (int)Math.Round(gameTime.ElapsedGameTime.TotalSeconds * 100.0f);
                seconds        = Math.Min(seconds, (int)Math.Ceiling(TimeRemaining.TotalSeconds));
                timeRemaining -= TimeSpan.FromSeconds(seconds);
            }
            else
            {
                timeRemaining -= gameTime.ElapsedGameTime;
                ActiveHero.Update(gameTime, gameInputs);

                if (ActiveHero is HeroStrength)
                {
                    ((Gun)Heroes[1].Weapon).UpdateBullets();
                    ((Gun)Heroes[2].Weapon).UpdateBullets();
                }
                else if (ActiveHero is HeroSpeed)
                {
                    ((Gun)Heroes[0].Weapon).UpdateBullets();
                    ((Gun)Heroes[2].Weapon).UpdateBullets();
                }
                else
                {
                    ((Gun)Heroes[0].Weapon).UpdateBullets();
                    ((Gun)Heroes[1].Weapon).UpdateBullets();
                }

                UpdateConsumables(gameTime);

                //playersTarget = gameInputs.MouseInput.Position;
                //rayIntersectDistance = Collision.RayCastCollidesWithLevel(ActiveHero.Center, playersTarget);


                if (gameInputs.MouseState.ScrollWheelValue > gameInputs.PreviousMouseState.ScrollWheelValue)
                {
                    Camera.Zoom += 0.1f;
                }
                else if (gameInputs.MouseState.ScrollWheelValue < gameInputs.PreviousMouseState.ScrollWheelValue)
                {
                    Camera.Zoom -= 0.1f;
                }


                //follow the activeHero
                Camera.LookAt(ActiveHero.Position);



                // Falling off the bottom of the level kills the activeHero.
                if (ActiveHero.BoundingRectangle.Top >= Height * map.TileHeight && ActiveHero.IsAlive)
                {
                    OnHeroKilled(null);
                }

                UpdateEnemies(gameTime, gameInputs);


                // The activeHero has reached the exit if they are standing on the ground and
                // his bounding rectangle contains the center of the exit tile. They can only
                // exit when they have collected all of the gems.

                if (ActiveHero.IsAlive &&
                    ActiveHero.IsOnGround &&
                    ActiveHero.BoundingRectangle.Intersects(exitRectangle))
                {
                    OnExitReached();
                }
            }
            // Clamp the time remaining at zero.
            if (timeRemaining < TimeSpan.Zero)
            {
                timeRemaining = TimeSpan.Zero;
            }

            if (gameInputs.KeyboardState.IsKeyDown(Keys.N) && !gameInputs.PreviousKeyboardState.IsKeyDown(Keys.N))
            {
                if (drawNavMesh)
                {
                    drawNavMesh = false;
                }
                else
                {
                    drawNavMesh = true;
                }
            }

            //GOD MODE!!!
            //ActiveHero.Health = ActiveHero.MaxHealth;
        }