public bool AstroidBulletCollisionDetection(Bullet bullet, Astroid astroid) { float bulletMinY = bullet.position.Y; float bulletMaxY = (bullet.position.Y + bullet.texture.Bounds.Height); float bulletMinX = bullet.position.X; float bulletMaxX = (bullet.position.X + bullet.texture.Bounds.Width); float astroidMinX = astroid.position.X; float astroidMaxX = (astroid.position.X + astroid.texture.Bounds.Width); float astroidMinY = astroid.position.Y; float astroidMaxY = (astroid.position.Y + astroid.texture.Bounds.Height); if (astroidMinX < bulletMinX && astroidMaxX > bulletMinX && astroidMinX < bulletMaxX && astroidMaxX > bulletMaxX) { if (astroidMinY < bulletMinY && astroidMaxY > bulletMinY && astroidMinY < bulletMaxY && astroidMaxY > bulletMaxY) { astroid.health--; if (astroid.health < 1) bullet.shotBy.score += 500; return true; } } return false; }
public bool AstroidPlayerCollisionDetection(Astroid astroid) { foreach (Player player in Players) { float playerMinX = player.position.X; float playerMaxX = (player.position.X + player.texture.Bounds.Width); float playerMinY = player.position.Y; float playerMaxY = (player.position.Y + player.texture.Bounds.Height); float astroidMinX = astroid.position.X; float astroidMaxX = (astroid.position.X + astroid.texture.Bounds.Width); float astroidMinY = astroid.position.Y; float astroidMaxY = (astroid.position.Y + astroid.texture.Bounds.Height); float middroidX = (astroidMinX + ((astroidMaxX - astroidMinX) / 2)); float middroidY = (astroidMinY + ((astroidMaxY - astroidMinY) / 2)); if (middroidX > playerMinX && middroidX < playerMaxX) { if (middroidY > playerMinY && middroidY < playerMaxY) { player.health.amount--; astroid.health = 0; return true; } } } return false; }