'''pacman2.py Jed Yang and friends, 2016-10-14 What we got in class. ''' from graphics import * class Pacman: def __init__(self, x, y, radius, color, velocity): self.color = color self.velocity = velocity self.radius = radius self.eye = None self.mouth = None self.head = None self.x = x self.y = y self.makeParts() def makeParts(self): '''Create the parts.''' # Head self.head=Circle((Point(100,100)),70) self.head.setFill('yellow') self.head.setOutline('yellow') #head.draw(win) # Eye self.eye=Circle((Point(100,60)),15) self.eye.setFill('black') #eye.draw(win) # Mouth self.mouth=Polygon((Point(100,100)),(Point(20,70)),(Point(20,130))) self.mouth.setFill('white') self.mouth.setOutline('white') #mouth.draw(win) pass def draw(self, window): self.head.draw(window) self.mouth.draw(window) self.eye.draw(window) pass def move(self, dx, dy): '''Move the parts.''' self.x = self.x + dx self.y = self.y + dy self.eye.move(dx,dy) self.mouth.move(dx,dy) self.head.move(dx,dy) def step(self): self.move(self.velocity, 0) pass def testModule(): import time winHeight = 300 winWidth = 500 win = GraphWin('Pacman Module Test', winWidth, winHeight) win.setBackground(color_rgb(0,0,0)) # make a Pacman and draw it in the window pac = Pacman(0,0,0,0,10) pac.draw(win) print('Pacman test. Click the window to quit.') while True: # animate the Pacman pac.step() if win.checkMouse(): # Why do I use checkMouse() instead of getMouse()? break time.sleep(0.02) if __name__ == '__main__': testModule()