|
|
|
|
|
|
|
|
import pygame |
|
|
import pygame |
|
|
# init Spieldaten |
|
|
# init Spieldaten |
|
|
|
|
|
|
|
|
|
|
|
pygame.init() |
|
|
|
|
|
myfont = pygame.font.SysFont('Comic Sans MS', 40) |
|
|
|
|
|
global running |
|
|
speed = 0 |
|
|
speed = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
speed_y *= -1 |
|
|
speed_y *= -1 |
|
|
|
|
|
|
|
|
def show_game_over(): |
|
|
def show_game_over(): |
|
|
global image_g_o |
|
|
|
|
|
screen.blit(image_g_o, (0, 0)) |
|
|
|
|
|
|
|
|
global image_g_o, screen, running |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) |