private void EnemyShipBorderCollisions(EnemyShip enemyShip) { //Get the specific sprite box of the player ship for collision calculation Rectangle levelBorder = m_level.GetLevelRectangle(); Rectangle enemyShipSpriteBox = enemyShip.GeneralSpriteBox; //Check for Collisions with level border and enemy ship , and calculates re-adjust necessary and passes it to the ship's collision handler to //re-position / other effects if (enemyShipSpriteBox.Left < levelBorder.Left || enemyShipSpriteBox.Right > levelBorder.Right || enemyShipSpriteBox.Top < levelBorder.Top || enemyShipSpriteBox.Bottom >= levelBorder.Bottom) enemyShip.ShipCollisionHandler(1); }
private void EnemyShipAsteroidCollisions( EnemyShip enemyShip) { List<LinkedList<Asteroid>> boundAsteroids = m_level.GetAsteroidPartitionTree().GetPartitionItems(enemyShip.GeneralSpriteBox); if (boundAsteroids.Count > 0) { foreach (LinkedList<Asteroid> asteroids in boundAsteroids) { foreach (Asteroid asteroid in asteroids) { //Check for asteroids within the vicinity of the enemy ship, and check for collisions against these asteroids. //Also, if there is no collision against the enemy ship itself use the evasion prediction box of the enemy ship //to pre-emptively try to avoid collisions //The evasion box is a simple technique used to evade asteroids, however it is not entirely accurate because it uses the //enemyship sprite box to find asteroids within vicinity, this will work for our purposes. However if you want more accurate //prediction, we have to get all asteroids within partitions of the evasion box. if (enemyShip.GeneralSpriteBox.Intersects(asteroid.GeneralSpriteBox)) enemyShip.ShipCollisionHandler(2); else if (enemyShip.GetEvasionRectangle().Intersects(asteroid.GeneralSpriteBox)) enemyShip.ShipCollisionHandler(3); } } } }