private void BulletBorderCollisions( Bullet bullet ) { Rectangle levelBorder = m_level.GetLevelRectangle(); Rectangle bulletSpriteBox = bullet.GeneralSpriteBox; if (bulletSpriteBox.Left <= levelBorder.Left || bulletSpriteBox.Right >= levelBorder.Right || bulletSpriteBox.Top <= levelBorder.Top || bulletSpriteBox.Bottom >= levelBorder.Bottom) bullet.Alive = false; }
//Find the objects that are within the bullets partition space and intersecting the partition space //Go through all these objects, if a collision is found then set the bullet to no longer be alive so it is removed from //the ships list of alive bullets private void BulletAsteroidCollisions(Bullet bullet) { List<LinkedList<Asteroid>> boundAsteroids = m_level.GetAsteroidPartitionTree().GetPartitionItems(bullet.GeneralSpriteBox); if (boundAsteroids.Count > 0) { foreach (LinkedList<Asteroid> asteroids in boundAsteroids) { foreach (Asteroid asteroid in asteroids) { if (bullet.GeneralSpriteBox.Intersects(asteroid.GeneralSpriteBox)) bullet.Alive = false; } } } }
private void BulletPlayerCollision(Bullet bullet) { if (bullet.GeneralSpriteBox.Intersects(m_player.GeneralSpriteBox)) { bullet.Alive = false; //Currently Main is the temporary Screen handler that will handle //Game over, Level restart etc... In the future we should use an actual screen handler m_gameManager.GameOver(); } }
private void BulletEnemyCollisions( Bullet bullet ) { LinkedList<EnemyShip> enemyShips = m_level.GetEnemyShipList(); foreach (EnemyShip enemyShip in enemyShips) { if (bullet.GeneralSpriteBox.Intersects(enemyShip.GeneralSpriteBox) && bullet.Alive) { if (PixelIntersects(bullet, enemyShip)) { bullet.Alive = false; enemyShip.IsAlive = false; } } } }