Time for action – using the CollisionManager class

  1. Add the CheckCollisions() method to the CollisionManager class:
    public void CheckCollisions()
    {
        checkShotToEnemyCollisions();
        checkShotToAsteroidCollisions();
        if (!playerManager.Destroyed)
        {
            checkShotToPlayerCollisions();
            checkEnemyToPlayerCollisions();
            checkAsteroidToPlayerCollisions();
        }
    }
  2. Add a declaration for the CollisionManager to the Game1 declarations area:
    CollisionManager collisionManager;
  3. Initialize the CollisionManager in the LoadContent() method of the Game1 class, after the ExplosionManager has been initialized:
    collisionManager = new CollisionManager(
        asteroidManager,
        playerManager,
        enemyManager,
        explosionManager);
  4. In the Game1 class' Update() method, in the GameStates.Playing section, ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.