PyPong, but koty grają cebulą a dźwięki to lasery - Eliza J.

PyPong, but koty grają cebulą a dźwięki to lasery - Eliza J.
from pgzero_api_stub import *
from pgzero.builtins import *
import pgzrun


class Paletka(Actor):
    def __init__ (self, obrazek: str, polozenie):
        Actor.__init__(self, obrazek, polozenie)
        self.obrazek = obrazek
        self.polozenie = polozenie 

    def gora(self):
        if self.top > 5:
            self.y -= 8

    def dol(self):
        if self.bottom < HEIGHT - 5:
            self.y += 8


class Pilka(Actor):
    def __init__(self, obrazek, polozenie) -> None:
        Actor.__init__(self, obrazek, polozenie)
        self.velx = 5
        self.vely = 5

    def ruch(self):
        self.x += self.velx
        self.y += self.vely

        if self.x > WIDTH:
            self.x=380
            self.y=380
        if self.x < 0:
            self.x=380
            self.y=380
        if self.y > HEIGHT:
            self.vely *= -1
        if self.y < 0:
            self.vely *= -1
        if pilka.colliderect(paletka_gracz1) or pilka.colliderect(paletka_gracz2):
            self.velx *= -1



class TablicaPunktow:
    def __init__(self) -> None:
        self.gracz1_pkt = 0
        self.gracz2_pkt = 0

    def dodaj_punkty(self):
        if pilka.x < 0.5:
            self.gracz2_pkt += 1
        if pilka.x > WIDTH-0.5:
            self.gracz1_pkt += 1
    
        screen.draw.text((f"{self.gracz1_pkt} | {self.gracz2_pkt}"), (380,10), color=(250, 180, 120), fontsize=50, owidth=0.5, ocolor=(250, 100, 105))

def dzwieki():
    # pass
    if pilka.colliderect(paletka_gracz1) or pilka.colliderect(paletka_gracz2):
        sounds.laser_paletka.play()
    if pilka.x < 0:
        sounds.laser_sciana.play()
    if pilka.x > WIDTH:
        sounds.laser_sciana.play()
    if pilka.y < 0:
        sounds.laser_sciana.play()
    if pilka.y > HEIGHT:
        sounds.laser_sciana.play()


def sterowanie():
    if keyboard.w:
        paletka_gracz1.gora()
    if keyboard.s:
        paletka_gracz1.dol()
    if keyboard.UP:
        paletka_gracz2.gora()
    if keyboard.DOWN:
        paletka_gracz2.dol()


# stworzenie zmiennych i obiektów

WIDTH = 800
HEIGHT = 600
paletka_gracz1 = Paletka("kotek1", (70, HEIGHT / 2))
paletka_gracz2 = Paletka("kotek2", (WIDTH - 95, HEIGHT / 2))
pilka = Pilka("picebulka", (WIDTH / 2, HEIGHT / 2))
tablica = TablicaPunktow()
velx = 5
vely = 5


def draw():
    screen.fill((0, 0, 0))
    paletka_gracz1.draw()
    paletka_gracz2.draw()
    tablica.dodaj_punkty()
    pilka.draw()


def update():
    sterowanie()
    dzwieki()
    pilka.ruch()


pgzrun.go()