private bool IsTouchingEnclosure(ISprite sprite, Rectangle bounds) { // cannot use Rectangle.contains, it misses the case where the we are just touching, i.e. x = 0 etc. if (sprite.BoundingBox.Left <= bounds.Left || sprite.BoundingBox.Right >= bounds.Right || sprite.BoundingBox.Bottom >= bounds.Bottom || sprite.BoundingBox.Top <= bounds.Top) { soundManager.Play(Sound.Bounce); var ball = sprite as Ball; if (ball != null) { ball.HasHitWall = true; } var bubble = sprite as Bubble; //if (bubble != null && !bubble.HasHitWall) if (bubble != null) { // if a bubble hits the wall, make another one var newBubble = bubbleManager.MakeBubble(bubble.Color); // the bubble manager can choose to not add another bubble, so the null guard if (newBubble != null) { sprites.Add(newBubble); } } return(true); } return(false); }