import pygame
import math

pygame.init()

screenWidth = 500
screenHeight = 300
screen = pygame.display.set_mode((screenWidth, screenHeight))  # Fenstergrösse

pygame.display.set_caption("Pong")

# Spieler-Rechteck Position
x1 = 40
y1 = 130
x2 = 455
y2 = 130

# Spieler-Rechteck Grösse
width = 5
height = 40

## Eigenschaften des Balls
ballx = 220  # Ball Anfangsposition
bally = 100
dirx = 1. # Ball Bewegungsrichtung entlang x-Koordinate
diry = 1.
speed = 0.7 # Ball Geschwindigkeit

run = True
while run:
    pygame.time.delay(5)  # time delay in milliseconds (kind of the clock delay in the game)

    for event in pygame.event.get():  # loop over all the events that happen in the game (e.g. mouse click or motion)
        if event.type == pygame.QUIT:  # if we find the event of QUIT (user clickt on window exit button)
            run = False

    keys = pygame.key.get_pressed()

    # Todo: Implementiere Steuereingabe, damit sich Spielerrechtecke nach oben und unten bewegen lassen


    # Todo: lass den Ball bewegen


    # Todo: Wenn der Ball die Wand berührt, dann sollte er seine Richtung ändern


    screen.fill((0, 0, 0))  # fill the screen with black in order to overdraw the image of the previous time step

    # Zeichne Spieler-Rechtecke
    pygame.draw.rect(screen, (255, 0, 0), (x1, y1, width, height))  # draw rectangle on the 'win' surface in the color red (RGB: 255,0,0) with my defined size. (in pygame the coordinates are on the top left)
    pygame.draw.rect(screen, (255, 0, 0), (x2, y2, width, height))

    # Zeichne Ball
    pygame.draw.rect(screen, (255, 0, 0), (ballx, bally, width, width))

    pygame.display.update()

pygame.quit()
