python
import pygame
import random
pygame.init()
# Colors
black = (0, 0, 0)
white = (255, 255, 255)
green = (0, 255, 0)
# Screen dimensions
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Flappy Bird (No Sprites)")
# Game variables
bird_x = 50
bird_y = screen_height / 2
bird_velocity = 0
gravity = 0.5
pipe_gap = 200
pipe_width = 50
pipe_speed = 3
# Game loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Bird movement
bird_velocity += gravity
bird_y += bird_velocity
# Keep bird within screen bounds
if bird_y < 0:
bird_y = 0
elif bird_y > screen_height - 50:
bird_y = screen_height - 50
# Generate new pipes
if pipe_speed < 0:
pipe_speed = 3
else:
pipe_speed += 0.1
# Create pipes
pipes = []
for i in range(5):
pipe_x = random.randint(0, screen_width - pipe_width)
pipe_y = 0
pipe_gap = random.randint(100, 200)
pipes.append((pipe_x, pipe_y, pipe_gap))
# Draw pipes
for pipe in pipes:
pygame.draw.rect(screen, green, (pipe[0], pipe[1], pipe_width, pipe[2]))
# Draw bird
pygame.draw.rect(screen, white, (bird_x, bird_y, 30, 30))
# Update display
pygame.display.flip()
pygame.quit()
This code provides a basic framework for a Flappy Bird game without sprites. You can expand it by adding more features like: