Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.0 kB
2
Indexable
import pygame
import sys

# Initialize Pygame
pygame.init()

# Constants
WIDTH, HEIGHT = 400, 600
BACKGROUND_COLOR = (135, 206, 235)
BIRD_COLOR = (255, 255, 0)
GRAVITY = 0.25
BIRD_JUMP = -5

# Create the game window
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Flappy Bird")

# Bird properties
bird = pygame.Rect(100, 300, 30, 30)
bird_y_speed = 0

# Main game loop
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
            bird_y_speed = BIRD_JUMP

    bird_y_speed += GRAVITY
    bird.y += bird_y_speed

    # Check for collisions or boundaries
    if bird.top <= 0 or bird.bottom >= HEIGHT:
        running = False

    # Clear the screen
    screen.fill(BACKGROUND_COLOR)

    # Draw the bird
    pygame.draw.rect(screen, BIRD_COLOR, bird)

    pygame.display.update()

# Quit Pygame
pygame.quit()
sys.exit()