class Face: def __init__(self, window, center, size): eyeSize = 0.15 * size eyeOff = size / 3.0 mouthSize = 0.8 * size mouthOff = size / 2.0 self.head = Circle(center, size) self.head.draw(window) self.leftEye = Circle(center, eyeSize) self.leftEye.move(-eyeOff, -eyeOff) self.rightEye = Circle(center, eyeSize) self.rightEye.move(eyeOff, -eyeOff) self.leftEye.draw(window) self.rightEye.draw(window) p1 = center.clone() p1.move(-mouthSize / 2, mouthOff) p2 = center.clone() p2.move(mouthSize / 2, mouthOff) self.mouth = Line(p1, p2) self.mouth.draw(window) def Move(self, dx, dy): for p in self.points: p.Move(dx, dy) def Flinch(self, center, size, window): eyesize = 0.15 * size eyeOff = size / 3.0 self.leftEye = Line(Point(center.x + eyesize / 2, center.y), Point(center.x - eyesize / 2, center.y)) self.leftEye.move(-eyeOff, -eyeOff) self.rightEye = Circle(center, eyesize) self.rightEye.move(eyeOff, -eyeOff) self.leftEye.draw(window) self.rightEye.draw(window)
def endGame(field, game_panel, player_name, score): # Let the user know the game is finished end_game_text = Text(Point(200, 200), "Finished! Click to close") end_game_text.draw(field) # Draw graphic objects at different places that represent balloons with a # string connected to it. balloon_1 = Circle(Point(145, 110), 18) balloon_1.setFill("red") balloon_1.setOutline("red") balloon_1.draw(field) triangle_1 = Polygon(Point(137, 135), Point(145, 128), Point(153, 135)) triangle_1.setFill("red") triangle_1.setOutline('red') triangle_1.draw(field) string_1 = Line(Point(145, 135), Point(145, 180)) string_1.draw(field) balloon_2 = Circle(Point(340, 300), 18) balloon_2.setFill("red") balloon_2.setOutline("red") balloon_2.draw(field) triangle_2 = Polygon(Point(332, 325), Point(340, 318), Point(348, 325)) triangle_2.setFill("red") triangle_2.setOutline('red') triangle_2.draw(field) string_2 = Line(Point(340, 325), Point(340, 370)) string_2.draw(field) balloon_3 = Circle(Point(75, 275), 18) balloon_3.setFill("red") balloon_3.setOutline("red") balloon_3.draw(field) triangle_3 = Polygon(Point(67, 300), Point(75, 293), Point(83, 300)) triangle_3.setFill("red") triangle_3.setOutline('red') triangle_3.draw(field) string_3 = Line(Point(75, 300), Point(75, 345)) string_3.draw(field) # Create a while loop that moves the objets every 0.05 seconds upwards to # make it appear as if they are floating while True: sleep(0.05) balloon_1.move(0, -10) triangle_1.move(0, -10) string_1.move(0, -10) balloon_2.move(0, -10) triangle_2.move(0, -10) string_2.move(0, -10) balloon_3.move(0, -10) triangle_3.move(0, -10) string_3.move(0, -10) # If a click is detetced in the field, the window will close even if the # balloons are still moving in the while loop click = field.checkMouse() if click != None: break # Add player score to top_scores.txt writeScores(player_name, score) # Set close condition to True close = True # Return close condition return close