22b. Bubble Wrap

Random size circles all around the screen. Circles disappear when you click on them.
  • A bunch of circles of random size and color are placed around the screen.
  • When you click on a circle, it disappears.
  • Only the top circle should disappear if multiple circles are stacked.

Model

First, think about one bubble. How will you represent that? You need to keep track of at least:

  • center
  • radius
  • color

Next, think about all of the bubbles. How will you represent a bunch of bubbles?

Drawing

It is good to get your draw handler written early, so you can see what is going on. I recommend that you write one function to draw a single bubble on a background, and another function to draw all of the bubbles.

Logic

You need to remove the bubble you click on from the game. I think that is best done in two steps:

  • clicked-on-bubble?: bubble posn(click) -> boolean. True if the click is inside the given bubble.
  • remove-clicked: list of bubbles posn(click) -> list of bubbles

Final Check

Make sure that only the top circle disappears when you click on an point that is contained in multiple circles. Write a check-expect to show that this happens!

Last modified August 18, 2023: 2022-2023 End State (7352e87)