CS414 Lab 8: Asteroids

For this lab, you will prepare a single file, called asteroids.py. I've prepared a starter file for you, available here on the course webpage.

Turning in your work

Be sure to turn in whatever you have finished, at the end of the lab session. You may continue to work until midnight, and submit your work again.

Late penalties: 1 day late: -5%, 2 days: -10%, -3 days: -20%.

To turn your work in, go to mycourses.unh.edu, find CS414, open the syllabus, and click on Lab 8. Then click Submit Assignment, click Choose file, and find asteroids.py.

Your task:

Run Idle, and then open the file asteroids.py. Choose "Run -> Run Module" to see the program in action. You may have to move your code windows to the right, to see the turtle window.

Also, this lab now uses the keyboard. When you run the program, remember to click INSIDE the turtle window. Otherwise your program won't respond to keyboard events.

Then, complete these steps:

  1. Look at random_motion(): all the rocks have size 20 (the last value in the returned list). Change that value to be a random number between 20 and 60.

  2. Look at make_rocks(): there is only one rock being appended to the list rocks. Replace the last line with a for-loop, which repeats 5 times, and appends a random motion each time.

  3. The game needs some bullets. Follow these steps:
  4. There are too many bullets; the game will be too easy. Make two changes:

  5. Implement check_rock_bullet_hit(): if some bullet hits some rock, remove the rock. To do this, you will need two for-loops: a loop that visits the rocks list, and inside it a loop that visits the bullets list. Call collided(rock, bullet), and, if it is True, remove the rock from the list.

  6. Let the user turn the ship. Follow these steps:

  7. If there are no more rocks, restart the game: add some lines in update_scene() so that, if the rocks list is empty (it has length 0), make_rocks() is called.