Week 8 - Sets and animation#

Goals#

  • Learn about sets in Python

  • Compute collisions between sprites

  • Animate sprites

Week 8a - Groups of Sprites#

Sets#

  1. Which data structures have we seen until set?

  2. You can also create a set by using curly braces, e.g.: s = {1, 2}

  3. You try to add an item to a set using .append() but it does not work. It seems like you forgot the name of the method. How can you remember the method’s name without using internet search and documentation?

  4. Instead of a.difference_update(b) you can also use: a -= b

Collisions for Sprites#

  1. For simplicity we assume that everything has a circle shape.

  2. For which collisions do we want to check?

Week 8b - Animation#

Sprite Animation#

  1. (Video 5:55) Note that current_rock_index = (time % ROCK_DIM) // 1 won’t return an int in Python3 if time is a float. You can use current_rock_index = int(time % ROCK_DIM) instead.

Programming Tips - 8#

  1. type({}) is a dict, but type({1}) is a set. How would you initialize an empty dict?

  2. Instead of a.intersection(b) and a.intersection_update(b) you can use a & b and a &= b.

Mini Project #8 - RiceRocks (Asteroids)#