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, ...
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.