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.

Details:

Write a centipede type game with the following requirements

• Start your "centipede" with 4 segments. use images for the segments. Your centipede can be an old fashioned centipede, or a train (an approach popular in children's games these days.) Or a conga line or anything (appropriate) that you want.
• Start with 4 randomly places "power ups" on the board. Each time the 'centipede' goes over a powerup half of the segments disappear from the back of the centipede.
• The centipede should be controlled by the keyboard. It should be able to move up down left or right.
• when the player changes direction, each segment must continue to move in the previous direction till they reach the point that the user changed direction - at that point the segment changes directions.
• Every 4 seconds a new segment should appear at the back of the centipede.
• If the first segment of the centipede ever hits a wall or any other segment, the player should lose. Put up a message to the user telling them.
• If the player survives a minute, they win - put up a message telling them that.

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 (r1.top() > r2.bottom()) or (r1.bottom() < r2.top()):
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         pass     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

Submission:

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