Untitled

 avatar
unknown
plain_text
a year ago
1.0 kB
1
Indexable
import pygame
import sys

# Initialize Pygame
pygame.init()

# Set up the screen
screen_width = 600
screen_height = 400
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Flappy Bird")

# Colors
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)

# Game variables
bird_x = 50
bird_y = screen_height // 2
bird_velocity = 0
gravity = 0.25
jump_strength = -5
bird_radius = 10

# Main game loop
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                bird_velocity = jump_strength

    # Update bird position
    bird_velocity += gravity
    bird_y += bird_velocity

    # Clear the screen
    screen.fill(WHITE)

    # Draw bird
    pygame.draw.circle(screen, BLUE, (bird_x, int(bird_y)), bird_radius)

    # Update display
    pygame.display.flip()

    # Cap the frame rate
    pygame.time.Clock().tick(60)
Editor is loading...
Leave a Comment