From 1cd8089d8db6c4a74f498f1d8d432d73b3e4376f Mon Sep 17 00:00:00 2001 From: jango Date: Fri, 23 Nov 2018 10:29:14 +0100 Subject: [PATCH] pong --- pong.py | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/pong.py b/pong.py index 35cd485..56e0e18 100644 --- a/pong.py +++ b/pong.py @@ -60,9 +60,24 @@ def reflect_y(): global speed_y speed_y *= -1 -def game_over(): +def show_game_over(): global image_g_o screen.blit(image_g_o, (0, 0)) + pygame.display.flip() + waiting = True + while waiting: + for event in pygame.event.get(): + if (event.type == pygame.QUIT or event.key == pygame.K_ESCAPE): + print('quit') + waiting = False + pygame.quit() + #self.running = False + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_SPACE: + print('space') + waiting = False + init_game() + def update(): global x, y, width_player, height_player, speed, width, zaehler, height @@ -86,8 +101,8 @@ def update(): image_rect.y += speed_y else: pass - if image_rect.y == height and (zaehler%2 == 0): - game_over() + if image_rect.y >= height and (zaehler%2 == 0): + show_game_over() def draw(): screen.fill(black) @@ -95,16 +110,20 @@ def draw(): pygame.draw.rect(screen, red, rect) pygame.display.flip() +def init_game(): + global screen + pygame.init() + init() + initRectangle() + screen = pygame.display.set_mode(size) -pygame.init() -init() -initRectangle() -screen = pygame.display.set_mode(size) - +init_game() running = True - +game_over = False while running: + if game_over: + show_game_over() running = input() update() draw()