Exemplo n.º 1
0
 /// <summary>
 /// Called when the player is killed.
 /// </summary>
 /// <param name="killedBy">
 /// The enemy who killed the player. This is null if the player was not killed by an
 /// enemy, such as when a player falls into a hole.
 /// </param>
 private void OnPlayerKilled(Enemy killedBy)
 {
     Player.OnKilled(killedBy);
     Player2.OnKilled(killedBy);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Updates all objects in the world, performs collision between them,
        /// and handles the time limit with scoring.
        /// </summary>
        public void Update(
            GameTime gameTime,
            KeyboardState keyboardState,
            KeyboardState previousKeyboardState,
            GamePadState gamePadState,
            GamePadState gamePadState2,
            DisplayOrientation orientation)
        {
            // Pause while the player is dead or time is expired.
            if (!Player.IsAlive || TimeRemaining == TimeSpan.Zero || !Player2.IsAlive)
            {
                // Still want to perform physics on the player.
                Player.ApplyPhysics(gameTime);
                Player2.ApplyPhysics(gameTime);
            }
            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);
                //score += seconds * PointsPerSecond;
            }
            else
            {
                timeRemaining -= gameTime.ElapsedGameTime;
                Player.Update(gameTime, keyboardState, gamePadState, orientation);
                Player2.Update(gameTime, keyboardState, gamePadState2, orientation);
                UpdateGems(gameTime);

                // Falling off the bottom of the level kills the player.
                if (Player.BoundingRectangle.Top >= Height * Tile.Height || Player2.BoundingRectangle.Top >= Height * Tile.Height)
                {
                    OnPlayerKilled(null);
                }
                UpdateCollision();
                UpdateProjectiles();
                UpdateProjectiles2();
                UpdateEnemies(gameTime);

                // The player 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 (Player.IsAlive &&
                    Player.IsOnGround &&
                    Player.BoundingRectangle.Contains(exit))
                {
                    OnExitReached();
                    score += 10;
                }

                if (Player2.IsAlive &&
                    Player2.IsOnGround &&
                    Player2.BoundingRectangle.Contains(exit))
                {
                    OnExitReached();
                    score2 += 10;
                }
            }

            // Clamp the time remaining at zero.
            if (timeRemaining < TimeSpan.Zero)
            {
                timeRemaining = TimeSpan.Zero;
            }



            if (keyboardState.IsKeyDown(Keys.RightShift) && player1Ammo != 0)
            {
                if (previousKeyboardState.IsKeyDown(Keys.RightShift) && timeRemaining.Milliseconds % 2 == 1 && timeRemaining.Milliseconds % 3 == 1)
                {
                    AddProjectile(player.Position + new Vector2(player.Width / 2, 0));
                    UpdateProjectiles();
                    player1Ammo--;
                }
            }

            if (keyboardState.IsKeyDown(Keys.NumPad0) && player1Ammo != 0)
            {
                AddProjectile(player.Position + new Vector2(player.Width / 2, 0));
                UpdateProjectiles();
                player1Ammo--;
            }



            if (keyboardState.IsKeyDown(Keys.LeftShift) && player2Ammo != 0)
            {
                if (previousKeyboardState.IsKeyDown(Keys.LeftShift) && timeRemaining.Milliseconds % 2 == 1 && timeRemaining.Milliseconds % 3 == 1)
                {
                    AddProjectile2(player2.Position + new Vector2(player2.Width / 2, 0));
                    UpdateProjectiles2();
                    player2Ammo--;
                }
            }

            if (keyboardState.IsKeyDown(Keys.F) && player2Ammo != 0)
            {
                AddProjectile2(player2.Position + new Vector2(player2.Width / 2, 0));
                UpdateProjectiles2();
                player2Ammo--;
            }
        }