예제 #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>
 ///
 private void CheckCollisions()
 {
     foreach (Enemy e in enemies)
     {
         if (IsColliding(player.Bounds, e.Bounds) == true)
         {
             if (player.Velocity.Y > 0)
             {
                 player.JumpOnCollision();
                 enemies.Remove(e);
                 score++;
                 break;
             }
             else
             {
                 if (lives > 1)
                 {
                     player.Death();
                     Start();
                     lives--;
                 }
                 else
                 {
                     MediaPlayer.Stop();
                     MediaPlayer.IsRepeating = false;
                     MediaPlayer.Play(gameoverSound);
                     gameState = GAME_STATE_GAMEOVER;
                 }
                 break;
                 // player just died
             }
         }
     }
     if (IsColliding(player.Bounds, goal.Bounds) == true)
     {
         MediaPlayer.Stop();
         MediaPlayer.IsRepeating = false;
         MediaPlayer.Play(winSound);
         gameState = GAME_STATE_WIN;
     }
 }