Part 14: Collision of cannons and rockets


We shall detect the collision of the cannons (circle sprites) with the rocket sprite and detect a problem that we would face.

Adding on to Part 13, we shall add the code for collision as in Part 11

This must be done before the display update.

    #sprite collide is for sprites in a group
    for circle in wall_group:
            print("collision  :  " + str(id(circle)))

If you run this code, the rocket shows collision nowhere near the cannon, the rectangle we got from the circles is huge, that is why.

I tried to get this to work, but failed.
The other methods:

  • The cannons need not be sprites but normal python objects
  • Secondly, use images for cannons instead of drawing circles in the sprite

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s