2026. június 29., hétfő

Pattogó labda játék

Pattogó labda játék
------------
import pygame
import sys

# Pygame inicializálása
pygame.init()

# Képernyő beállítások
WIDTH, HEIGHT = 800, 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('Profi Grafika Pythonban')

# Színek
WHITE = (255, 255, 255)
BLUE = (0, 128, 255)
RED = (255, 0, 0)

# Objektum pozíciója és sebessége
x, y = 100, 100
speed_x, speed_y = 5, 5

# Óra a képkockasebesség (FPS) szabályozásához
clock = pygame.time.Clock()

# Fő ciklus
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    # Háttér színezése
    screen.fill(WHITE)

    # Rajzolás
    # Rajzolunk egy árnyékot / statikus alakzatot
    pygame.draw.rect(screen, (200, 200, 200), (300, 200, 200, 150), 3)
    
    # Mozgó kör rajzolása
    pygame.draw.circle(screen, BLUE, (x, y), 40)
    pygame.draw.circle(screen, RED, (x, y), 40, 2)

    # Pozíció frissítése
    x += speed_x
    y += speed_y

    # Pattogás a falakról
    if x - 40 < 0 or x + 40 > WIDTH:
        speed_x = -speed_x
    if y - 40 < 0 or y + 40 > HEIGHT:
        speed_y = -speed_y

    # Képernyő frissítése (60 FPS)
    pygame.display.flip()
    clock.tick(60)
------------


Nincsenek megjegyzések:

Megjegyzés küldése