Comp151-H Computer Project 3

Due: March 28th  at 11:59pm (Now due March 30th at 1:50pm due to closed campus on 3/21)

Summary:  Once upon a time centipede was a big deal in video games. Then it was on watches and calculators - then it was a capstone project for CS1, now with python it is just another project. We'll do a speed version though because I need to grade them in a reasonable amount of time.


Write a centipede type game with the following requirements

In order to check for a collision between the first centipede segment and later segments you will need to check to see if the rectangle for the first segment overlaps the rectangle for the remaining segments. I suggest looking at this site here. In particular I suggest that you pilfer this slight modification of their function :

def overlap(r1,r2):
    '''Overlapping rectangles overlap both horizontally & vertically
edited from the original to work with the rect class below '''
hoverlaps = True voverlaps = True if (r1.left() > r2.right()) or (r1.right() < r2.left()): hoverlaps = False if ( > r2.bottom()) or (r1.bottom() < voverlaps = False return hoverlaps and voverlaps

To use the function above, you will need this code for your class too. Just copy this into your file
class rect:
    def __init__ (self, pict):
        pict should be a zelle graphics.image file
        self.pict = pict

    def right(self):
        return self.pict.getAnchor().getX() + self.pict.getWidth()/2
    def left(self):
        return self.pict.getAnchor().getX() - self.pict.getWidth()/2
    def top(self):
        return self.pict.getAnchor().getY() - self.pict.getHeight()/2
    def bottom(self):
        return self.pict.getAnchor().getY() + self.pict.getHeight()/2

once you have these two items, create a rectangle from a graphics.Image object

firstSegmentBounds = rect(firstImage)

laterSegementBounds = rect(laterImage)

if overlap(firstSegmentBounds, laterSegmentBounds):

    #do whatever you need to for the player losing


Put a readme.txt file into the project directory with:

Zip up your entire project directory and submit the zip file on blackboard.