zweiter tag

This commit is contained in:
Janko Hartwig 2018-10-06 14:34:53 +02:00
parent 40d5c525dc
commit e45e179e2b
2 changed files with 75 additions and 0 deletions

BIN
ohm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

75
pong.py Normal file
View File

@ -0,0 +1,75 @@
import pygame
# init Spieldaten
speed = 0
def init():
global width, height, size
global speed_x, speed_y
speed_x = 1
speed_y = 1
global black, red
global image, image_rect
width = 1080
height = 720
size = (width, height)
black = (0, 0, 0)
red = (255, 0, 0)
image = pygame.image.load("ohm.png")
image_rect = image.get_rect()
image_rect.x = 100
image_rect.y = 50
def initRectangle():
global rect
x = 400
y = 650
width = 300
height = 40
rect = pygame.Rect(x, y, width, height)
def input():
global speed
for event in pygame.event.get():
if event.type == pygame.QUIT:
return False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
speed = -1
if event.key == pygame.K_RIGHT:
speed = 1
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
speed = 0
if event.key == pygame.K_RIGHT:
speed = 0
return True
def update():
rect.x = rect.x + speed
#if image_rect.x == 0
image_rect.x += speed_x
image_rect.y += speed_y
def draw():
screen.fill(black)
screen.blit(image, image_rect)
pygame.draw.rect(screen, red, rect)
pygame.display.flip()
pygame.init()
init()
initRectangle()
screen = pygame.display.set_mode(size)
running = True
while running:
running = input()
update()
draw()