import pgzrun
from random import randint

# Start programu
WIDTH = 1000
HEIGHT = 676
TITLE = "PONG - najlepsza gra na świecie ;-)"

# definicja sprita
sprite = Actor("ball.png")
ship = Actor("ship.png")
sprite.x = WIDTH//2
sprite.y = HEIGHT//2
ship.x = randint(20,WIDTH-20)
ship.y = randint(20,HEIGHT-20)



def napis(odleglosc):
    winner_txt = f"Odległość: {odleglosc} w pixelach"
    screen.draw.text(
        winner_txt, (5, 20), color="red", fontsize=60
    )
# Najważniejsze funkcje sterujące
def update():
    if keyboard.d:
        sprite.x += 5
    if keyboard.a:
        sprite.x -= 5
    if keyboard.w:
        sprite.y -= 5
    if keyboard.s:
        sprite.y += 5

    if sprite.y > HEIGHT:
        sprite.y = 0
    elif sprite.y < 0:
        sprite.y = HEIGHT
    elif sprite.x < 0:
        sprite.x = WIDTH
    elif sprite.x > WIDTH:
        sprite.x = 0


def draw():
    screen.blit("tomulus64.jpg", (0,0) )
    ship.draw()
    sprite.draw()
    odl = round(ship.distance_to(sprite), 1)
    napis(odl)

pgzrun.go()