pong ready

This commit is contained in:
Janko Hartwig 2018-11-23 14:32:38 +01:00
parent 1cd8089d8d
commit b2eb62c102

21
pong.py
View File

@ -1,6 +1,8 @@
import pygame import pygame
# init Spieldaten # init Spieldaten
pygame.init()
myfont = pygame.font.SysFont('Comic Sans MS', 40)
global running
speed = 0 speed = 0
@ -61,23 +63,29 @@ def reflect_y():
speed_y *= -1 speed_y *= -1
def show_game_over(): def show_game_over():
global image_g_o global image_g_o, screen, running
screen.blit(image_g_o, (0, 0)) screen.blit(image_g_o, (300, 100))
textsurface = myfont.render('PONG', True, (0, 50, 200))
screen.blit(textsurface, (500,80))
textsurface = myfont.render('Press Space to restart - Escape to exit', True, (0, 50, 200))
screen.blit(textsurface, (200, 500))
pygame.display.flip() pygame.display.flip()
waiting = True waiting = True
while waiting: while waiting:
for event in pygame.event.get(): for event in pygame.event.get():
if (event.type == pygame.QUIT or event.key == pygame.K_ESCAPE): if (event.type == pygame.QUIT):
print('quit') print('quit')
waiting = False waiting = False
pygame.quit() pygame.quit()
#self.running = False running = False
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE: if event.key == pygame.K_SPACE:
print('space') print('space')
waiting = False waiting = False
init_game() init_game()
if event.key == pygame.K_ESCAPE:
running = False
pygame.quit()
def update(): def update():
global x, y, width_player, height_player, speed, width, zaehler, height global x, y, width_player, height_player, speed, width, zaehler, height
@ -112,7 +120,6 @@ def draw():
def init_game(): def init_game():
global screen global screen
pygame.init()
init() init()
initRectangle() initRectangle()
screen = pygame.display.set_mode(size) screen = pygame.display.set_mode(size)