Comp 151 Project 8


Due: Sun Dec 14th  at 11:55pm

Summary: You will have the chance cap your semester with a fun final project.

Description




Take your solution to project 5 and lets add a few things to it.

My sample implementation of project 5


In order to check for a collision between the shot and the enemy ships you will need to check to see if the rectangle for the shot overlaps the rectangle for the enemy ship. 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




For those of you who had trouble with project 5, here is my code for project 5. It assumes that you have the images in the same folder as the code.

__author__ = 'jsantore'

import graphics
import time


WINDOW_WIDTH = 700
NUM_BAD_GUYS = 8

def loadGoodGuys(window):
    hero = graphics.Image(graphics.Point(200, 450), 'ship2.gif')
    hero.draw(window)
    return hero

def loadBadGuys(window):
    bgList = []
    for i in range (NUM_BAD_GUYS):
        bg = graphics.Image(graphics.Point(i*70+50, 70), 'Bug1.gif')
        bgList.append(bg)
        bg.draw(window)
    return bgList



def main():
    win = graphics.GraphWin("Project 8 Start", WINDOW_WIDTH, 500)
    hero = loadGoodGuys(win)
    bgList = loadBadGuys(win)

    win.getMouse() #wait to quit


main()

Additional Requirements:


Your functions must contain all of your code except the one line invoking the  main function

To help me identify your work, make the name of your program file

yourFirstInitialLastNameLab8.py

(so mine would be JSantoreLab8.py) 

Comment your code. include the usual
 put the following at the beginning of the program as a comment:

Submission:

zip the entire folder up again this time - there will be images as well as python code.

Submit the zip file of the lab via moodle as usual. Don't forget to make sure your file has you name in the file name.