Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b2eb62c102 | ||
|
|
1cd8089d8d |
@@ -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
|
||||||
|
|
||||||
|
|
||||||
@@ -60,9 +62,30 @@ def reflect_y():
|
|||||||
global speed_y
|
global speed_y
|
||||||
speed_y *= -1
|
speed_y *= -1
|
||||||
|
|
||||||
def 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()
|
||||||
|
waiting = True
|
||||||
|
while waiting:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if (event.type == pygame.QUIT):
|
||||||
|
print('quit')
|
||||||
|
waiting = False
|
||||||
|
pygame.quit()
|
||||||
|
running = False
|
||||||
|
if event.type == pygame.KEYDOWN:
|
||||||
|
if event.key == pygame.K_SPACE:
|
||||||
|
print('space')
|
||||||
|
waiting = False
|
||||||
|
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
|
||||||
@@ -86,8 +109,8 @@ def update():
|
|||||||
image_rect.y += speed_y
|
image_rect.y += speed_y
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
if image_rect.y == height and (zaehler%2 == 0):
|
if image_rect.y >= height and (zaehler%2 == 0):
|
||||||
game_over()
|
show_game_over()
|
||||||
|
|
||||||
def draw():
|
def draw():
|
||||||
screen.fill(black)
|
screen.fill(black)
|
||||||
@@ -95,16 +118,19 @@ def draw():
|
|||||||
pygame.draw.rect(screen, red, rect)
|
pygame.draw.rect(screen, red, rect)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
||||||
|
def init_game():
|
||||||
pygame.init()
|
global screen
|
||||||
init()
|
init()
|
||||||
initRectangle()
|
initRectangle()
|
||||||
screen = pygame.display.set_mode(size)
|
screen = pygame.display.set_mode(size)
|
||||||
|
|
||||||
|
init_game()
|
||||||
running = True
|
running = True
|
||||||
|
game_over = False
|
||||||
|
|
||||||
while running:
|
while running:
|
||||||
|
if game_over:
|
||||||
|
show_game_over()
|
||||||
running = input()
|
running = input()
|
||||||
update()
|
update()
|
||||||
draw()
|
draw()
|
||||||
|
|||||||
Reference in New Issue
Block a user