Comp 151 Project 8


Due: Fri Dec 11th  at 11:59pm

Summary: You will have the chance cap your semester with a fun final project. Most of our projects have been smaller projects. Now, with the last project of the semester, we will begin a larger project, more akin to what we might do in a comp152 class.


Description


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

My sample implementation of project 5


It took me about 2 1/2 hours to put my solution to this project together. You have just over 3 weeks to do this project. I expect this will take most of you somewhere between 10 and 16 hours to complete. Please start early. You will have to work on this some time and then put this one away for a while and come back to it. You will not be able to put in an allnighter and finish this one.

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), 'horseman-n-attack4.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), 'ogre-attack1.gif')
bgList.append(bg)
bg.draw(window)
return bgList

def move_stuff(badGuys):
bgVel = 5
currNumBadGuys = NUM_BAD_GUYS
while True:
#first check if the bad guys are leaving the screen
if badGuys[0].getAnchor().getX()-(badGuys[0].getWidth()/2)<=0 or \
badGuys[currNumBadGuys-1].getAnchor().getX()+(badGuys[currNumBadGuys-1].getWidth()/2)>=WINDOW_WIDTH:
bgVel = -bgVel
for bg in badGuys:
bg.move(bgVel,0)
time.sleep(0.05)

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



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 blackboard as usual. Don't forget to make sure your file has you name in the file name.