Week 8 - Sets and animation#
Goals#
Learn about sets in Python
Compute collisions between sprites
Animate sprites
Week 8a - Groups of Sprites#
Sets#
Which data structures have we seen until
set?You can also create a set by using curly braces, e.g.:
s = {1, 2}You try to add an item to a
setusing.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?Instead of
a.difference_update(b)you can also use:a -= b
Collisions for Sprites#
For simplicity we assume that everything has a circle shape.
For which collisions do we want to check?
Week 8b - Animation#
Sprite Animation#
(Video 5:55) Note that
current_rock_index = (time % ROCK_DIM) // 1won’t return anintin Python3 iftimeis afloat. You can usecurrent_rock_index = int(time % ROCK_DIM)instead.
Programming Tips - 8#
type({})is adict, buttype({1})is aset. How would you initialize an emptydict?Instead of
a.intersection(b)anda.intersection_update(b)you can usea & banda &= b.