Time for action – using the CollisionManager class
Add the
CheckCollisions()
method to the CollisionManager class:public void CheckCollisions() { checkShotToEnemyCollisions(); checkShotToAsteroidCollisions(); if (!playerManager.Destroyed) { checkShotToPlayerCollisions(); checkEnemyToPlayerCollisions(); checkAsteroidToPlayerCollisions(); } }
Add a declaration for the CollisionManager to the Game1 declarations area:
CollisionManager collisionManager;
Initialize the CollisionManager in the
LoadContent()
method of the Game1 class, after the ExplosionManager has been initialized:collisionManager = new CollisionManager( asteroidManager, playerManager, enemyManager, explosionManager);
In the Game1 class'
Update()
method, in theGameStates.Playing
section, add the following after the ExplosionManager is updated:collisionManager.CheckCollisions();
Launch the game to view collision detection and explosion effects. After your ship has been destroyed...