homework
This commit is contained in:
parent
e45e179e2b
commit
058fd275e4
BIN
color-me-happy-game-over.jpg
Normal file
BIN
color-me-happy-game-over.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
63
pong.py
63
pong.py
@ -3,11 +3,13 @@ import pygame
|
|||||||
|
|
||||||
speed = 0
|
speed = 0
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
global width, height, size
|
global width, height, size, zaehler
|
||||||
global speed_x, speed_y
|
global speed_x, speed_y, image_g_o
|
||||||
speed_x = 1
|
zaehler = 0
|
||||||
speed_y = 1
|
speed_x = -1
|
||||||
|
speed_y = -1
|
||||||
global black, red
|
global black, red
|
||||||
global image, image_rect
|
global image, image_rect
|
||||||
width = 1080
|
width = 1080
|
||||||
@ -16,17 +18,18 @@ def init():
|
|||||||
black = (0, 0, 0)
|
black = (0, 0, 0)
|
||||||
red = (255, 0, 0)
|
red = (255, 0, 0)
|
||||||
image = pygame.image.load("ohm.png")
|
image = pygame.image.load("ohm.png")
|
||||||
|
image_g_o = pygame.image.load("color-me-happy-game-over.jpg")
|
||||||
image_rect = image.get_rect()
|
image_rect = image.get_rect()
|
||||||
image_rect.x = 100
|
image_rect.x = 500
|
||||||
image_rect.y = 50
|
image_rect.y = 350
|
||||||
|
|
||||||
def initRectangle():
|
def initRectangle():
|
||||||
global rect
|
global rect, width_player, height_player, x, y
|
||||||
x = 400
|
x = 0
|
||||||
y = 650
|
y = 650
|
||||||
width = 300
|
width_player = 300
|
||||||
height = 40
|
height_player = 40
|
||||||
rect = pygame.Rect(x, y, width, height)
|
rect = pygame.Rect(x, y, width_player, height_player)
|
||||||
|
|
||||||
def input():
|
def input():
|
||||||
global speed
|
global speed
|
||||||
@ -43,14 +46,48 @@ def input():
|
|||||||
speed = 0
|
speed = 0
|
||||||
if event.key == pygame.K_RIGHT:
|
if event.key == pygame.K_RIGHT:
|
||||||
speed = 0
|
speed = 0
|
||||||
|
if event.type == pygame.KEYDOWN:
|
||||||
|
if event.key == pygame.K_ESCAPE:
|
||||||
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def reflect_x():
|
||||||
|
global speed_x
|
||||||
|
speed_x *= -1
|
||||||
|
|
||||||
|
|
||||||
|
def reflect_y():
|
||||||
|
global speed_y
|
||||||
|
speed_y *= -1
|
||||||
|
|
||||||
|
def game_over():
|
||||||
|
global image_g_o
|
||||||
|
screen.blit(image_g_o, (0, 0))
|
||||||
|
|
||||||
def update():
|
def update():
|
||||||
|
global x, y, width_player, height_player, speed, width, zaehler, height
|
||||||
|
|
||||||
|
if (speed == -1 and rect.x <= 0) or (speed == 1 and rect.x >= (width - width_player)):
|
||||||
|
pass
|
||||||
|
else :
|
||||||
rect.x = rect.x + speed
|
rect.x = rect.x + speed
|
||||||
#if image_rect.x == 0
|
|
||||||
|
if (zaehler%2 == 0) and (image_rect.x <= 0 or image_rect.x >= width) :
|
||||||
|
reflect_x()
|
||||||
|
elif (zaehler%2 == 0) and image_rect.y <= 0 :
|
||||||
|
reflect_y()
|
||||||
|
if (zaehler%2 == 0) and (image_rect.y == (y - height_player) and image_rect.x >= rect.x and image_rect.x <= (rect.x + width_player)) :
|
||||||
|
reflect_y()
|
||||||
|
|
||||||
|
zaehler = zaehler + 1
|
||||||
|
|
||||||
|
if (zaehler%2 == 0):
|
||||||
image_rect.x += speed_x
|
image_rect.x += speed_x
|
||||||
image_rect.y += speed_y
|
image_rect.y += speed_y
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
if image_rect.y == height and (zaehler%2 == 0):
|
||||||
|
game_over()
|
||||||
|
|
||||||
def draw():
|
def draw():
|
||||||
screen.fill(black)
|
screen.fill(black)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user