Browse Source

homework

pong
Janko Hartwig 5 years ago
parent
commit
058fd275e4
2 changed files with 53 additions and 16 deletions
  1. BIN
      color-me-happy-game-over.jpg
  2. 53
    16
      pong.py

BIN
color-me-happy-game-over.jpg View File


+ 53
- 16
pong.py View File

@@ -3,11 +3,13 @@ import pygame

speed = 0


def init():
global width, height, size
global speed_x, speed_y
speed_x = 1
speed_y = 1
global width, height, size, zaehler
global speed_x, speed_y, image_g_o
zaehler = 0
speed_x = -1
speed_y = -1
global black, red
global image, image_rect
width = 1080
@@ -16,17 +18,18 @@ def init():
black = (0, 0, 0)
red = (255, 0, 0)
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.x = 100
image_rect.y = 50
image_rect.x = 500
image_rect.y = 350

def initRectangle():
global rect
x = 400
global rect, width_player, height_player, x, y
x = 0
y = 650
width = 300
height = 40
rect = pygame.Rect(x, y, width, height)
width_player = 300
height_player = 40
rect = pygame.Rect(x, y, width_player, height_player)

def input():
global speed
@@ -43,14 +46,48 @@ def input():
speed = 0
if event.key == pygame.K_RIGHT:
speed = 0

if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
return False
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():
rect.x = rect.x + speed
#if image_rect.x == 0
image_rect.x += speed_x
image_rect.y += speed_y
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

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.y += speed_y
else:
pass
if image_rect.y == height and (zaehler%2 == 0):
game_over()

def draw():
screen.fill(black)

Loading…
Cancel
Save