An Introduction to Interactive Programming in Python
Mini-project description - RiceRocks (Asteroids)
For our last mini-project, we will complete the implementation of RiceRocks , an updated version of Asteroids , that we began last week. You may start with either your code or the program template which includes a full implementaiton of Spaceship and will be released immediately after the deadline for the Spaceship mini-project (by making the preceding link live). If you start with your own code, you should add the splash screen image that you dismiss with a mouse click before starting this mini-project. We strongly recommend using Chrome for this mini-project since Chrome's superior performance will become apparent when you program attempts to draw dozens of sprites.Mini-project development process
At the end of this project, your game will have multiple rocks and multiple missiles. You will lose a life if your ship collides with a rock and you will score points if your missile collides with a rock. You will keep track of the score and lives remaining and end the game at the proper time. You may optionally add animated explosions when there is a collision.Phase one - Multiple rocks
For this phase, you will keep a set of rocks and spawn new rocks into this set. This requires the following steps:
- Remove
a_rock
and replace it withrock_group
. Initialize the rock group to an empty set. Modify your rock spawner to create a new rock (an instance of a Sprite object) and add it torock_group
. - Modify your rock spawner to limit the total number of rocks in the game at any one time. We suggest you limit it to 12. With too many rocks the game becomes less fun and the animation slows down significantly.
- Create a helper function
process_sprite_group
. This function should take a set and a canvas and call the update and draw methods for each sprite in the group. - Call the
process_sprite_group
function onrock_group
in the draw handler.
For this phase, you will detect collisions between the ship and a rock. Upon a collision, the rock should be destroyed and the player should lose a life. To implement ship-rock collisions, you need to do the following:
- Add a
collide
method to the Sprite class. This should take another_object
as an argument and returnTrue
if there is a collision orFalse
otherwise. For now, this other object will always be your ship, but we want to be able to use this collide method to detect collisions with missiles later, as well. Collisions can be detected using the radius of the two objects. This requires you to implement methodsget_position
andget_radius
on both the Sprite and Ship classes. - Implement a
group_collide
helper function. This function should take a setgroup
and an a spriteother_object
and check for collisions between