Jul 6 at 12am - Jul 17 at 11:59pm
This assignment was locked Jul 17 at 11:59pm.
THIS LAB IS OPTIONAL (0 Points of your grade) - BUT - IT IS WORTH 5 POINTS OF EXTRA CREDIT
In this lab, you will build on what you created in lab 5.1 to enable better management of the number of sprites in the program.
Part 1 - Getting Out of Hand
Open up your SNAP program from Lab 5.1. Modify your program so that, when the 'd' key is pressed, all visible bouncing balls are deleted (so, all the clones - not the 'master;). DO NOT delete the prototype -- you should be able to create new bouncing balls after you have removed the old clones. Use the block and a message.
What if you wanted to remove only a few clones? Or only specific clones?
Part 2 - Better Control
Add a global variable to your program called Next Ball ID# and give it a value of 1 when the green flag is clicked.
In your master ball sprite, create a sprite variable called Ball ID#. Modify your program so that each time a new clone is created, the clone's Ball ID# variable gets the value currently in Next Ball ID# and then have Next Ball ID# go up by 1. In this way, you are using your two variable to keep track of the clones and what the next clone will be. Sure, you could do that with one variable... but by using two, it makes this next part much easier.
Change your program so that when the 'd' key is pressed, the newest bouncing ball gets deleted. Think about the right way to use the variables you created in the previous steps to know which sprite to delete. (Hint: in order for this to work right, you should reuse old Ball ID #s once the clones are deleted. So, for example, if the most recently created clone was number 6, and you hit 'd', clone number 6 should be deleted. Then, if a new clone is created, it should be a new clone number 6.) Try to do this without requiring a lot of special cases in your code-- every clone should operate in the same way to determine if it should be deleted.
OPTIONAL-SUPER-BONUS-CHALLENGE (You don't have to do this to get the Extra Credit) : Add code so that if the 'x' key is pressed the program asks for a Ball ID# and deletes that numbered clone. All clones with higher numbers should be renumbered so that Ball ID# remain contiguous. (For instance, if clone number 5 is deleted, then clone numbers 6, 7, and 8 should be renumbered as clone numbers 5, 6, and 7 respectively. Then, the next clone created should be a new clone number 8.) This is tricky and will require you to think very carefully about how to use the variables.
Can't change a rubric once you've started using it.