Académique Documents
Professionnel Documents
Culture Documents
#
#
#
Crazy Breakout
Defeat the blocks! Where is the ball going to go? No one knows!
Scott Warnert
12/16/14
self.dy = -self.dy
self.dx = random.random() * 8 - 4
def handle_block_collision(self):
self.dy = random.random() * 8 - 4
self.dx = random.random() * 8 - 4
def end_game(self):
""" End the game"""
games.music.stop()
high_score = open("high_score.text", "r")
high_score.readline()
recordedScore = int(high_score.readline())
high_score.close()
if Paddle.score.value > recordedScore:
root = Tk()
root.title("Enter your name")
root.geometry("300x100")
app = Application(root)
root.mainloop()
end_message = games.Message(value = "Game Over",
size = 90,
color = color.white,
x = games.screen.width/2,
y = games.screen.height/2,
lifetime = 5 * games.screen.fps,
after_death = games.screen.quit())
games.screen.add(end_message)
class Paddle(games.Sprite):
""" A paddle controlled by the mouse. """
image = games.load_image("pongpaddle.bmp")
score = games.Text(value = 0,
size = 25,
color = color.white,
top = 5,
right = games.screen.width - 10)
def __init__(self):
"""Initialize Paddle Object and create Text Object for score"""
super(Paddle, self).__init__(image = Paddle.image,
x = games.mouse.x,
y = games.screen.height - 20)
games.screen.add(Paddle.score)
def update(self):
""" Move to mouse x-coordinate and check for collision. """
self.x = games.mouse.x
self.check_collide()
def check_collide(self):
""" Check for collision with ball. """
for ball in self.overlapping_sprites:
ball.handle_paddle_collide()
class Block(games.Sprite):