Time for action – enemy shots versus the rover
To check if the enemy shots as well as rover shots have hit their respective targets, perform the following steps:
1. Add the
CheckEnemyShotHits()
method to theCollision Detection
region of theShotManager
class as follows:public bool CheckEnemyShotHits(BoundingBox target) { foreach (EnemyShot shot in enemyShots) { if (shot.IsActive) { if (target.Intersects(shot.Bounds)) { return true; } } } return false; }
2. Add a new property to the
Rover
class for collision bounds checking:public BoundingBox CollisionBounds { get { BoundingBox baseBounds = Bounds; baseBounds.Min += new Vector3(1, 1, 1); baseBounds.Max += new Vector3(-1, -1, -1); return baseBounds; } }
3. In the
Update()
method of theMarsRunnerGameClass
, just after checking for hits on the alien craft, check for hits on the player as follows:if (shotManager...