Код IT
← Каталог

Python — Ping Pong — Этап 5 — мяч в центре (без движения)

Фрагмент из «Python — Ping Pong»: Этап 5 — мяч в центре (без движения).

python spinoffencyclopedia9-04-razrabotka-igr-praktikum-razrabotki-igr-3 embed URL статья в энциклопедии
Python main.py
class Ball:
    def __init__(self):
        cx = S.MARGIN + S.FIELD_W // 2
        cy = S.MARGIN + S.FIELD_H // 2
        self.rect = pygame.Rect(0, 0, S.BALL_SIZE, S.BALL_SIZE)
        self.rect.center = (cx, cy)
        self.vx = 0.0
        self.vy = 0.0
        self.color = S.COLOR_BALL

    def draw(self, surface):
        pygame.draw.rect(surface, self.color, self.rect, border_radius=2)


ball = Ball()
class Ball:
    def __init__(self):
        cx = S.MARGIN + S.FIELD_W // 2
        cy = S.MARGIN + S.FIELD_H // 2
        self.rect = pygame.Rect(0, 0, S.BALL_SIZE, S.BALL_SIZE)
        self.rect.center = (cx, cy)
        self.vx = 0.0
        self.vy = 0.0
        self.color = S.COLOR_BALL

    def draw(self, surface):
        pygame.draw.rect(surface, self.color, self.rect, border_radius=2)


ball = Ball()