Qwen3-235B-A22B-Instruct-2507-gguf-q4km-AutoRound
765
7
235.0B
Q4
license:apache-2.0
by
Intel
Other
OTHER
235B params
New
765 downloads
Early-stage
Edge AI:
Mobile
Laptop
Server
526GB+ RAM
Mobile
Laptop
Server
Quick Summary
This model is gguf:q4km model of Qwen/Qwen3-235B-A22B-Instruct-2507 generated by intel/auto-round algorithm.
Device Compatibility
Mobile
4-6GB RAM
Laptop
16GB RAM
Server
GPU
Minimum Recommended
219GB+ RAM
Code Examples
✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementsbash
pip install pygame✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()✅ Requirementspython
import pygame
import random
import sys
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH = 400
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Flappy Bird")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
SKY_BLUE = (135, 206, 235)
# Game settings
GRAVITY = 0.5
FLAP_STRENGTH = -10
PIPE_SPEED = 3
PIPE_GAP = 150
PIPE_FREQUENCY = 1500 # milliseconds
# Bird settings
bird_x = 100
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
bird_width = 40
bird_height = 30
# Pipe list
pipes = []
last_pipe_time = 0
# Score
score = 0
font = pygame.font.SysFont('Arial', 26)
# Clock
clock = pygame.time.Clock()
# Game loop
running = True
game_active = True
def draw_bird(x, y):
pygame.draw.rect(screen, BLUE, (x, y, bird_width, bird_height), border_radius=10)
def create_pipe():
height = random.randint(100, SCREEN_HEIGHT - PIPE_GAP - 100)
top_pipe = pygame.Rect(SCREEN_WIDTH, 0, 60, height)
bottom_pipe = pygame.Rect(SCREEN_WIDTH, height + PIPE_GAP, 60, SCREEN_HEIGHT)
return {"top": top_pipe, "bottom": bottom_pipe, "passed": False}
def draw_pipes(pipes):
for pipe in pipes:
pygame.draw.rect(screen, GREEN, pipe["top"])
pygame.draw.rect(screen, GREEN, pipe["bottom"])
def move_pipes(pipes):
for pipe in pipes:
pipe["top"].x -= PIPE_SPEED
pipe["bottom"].x -= PIPE_SPEED
def remove_offscreen_pipes(pipes):
return [pipe for pipe in pipes if pipe["top"].right > 0]
def check_collision(pipes, bird_y):
# Check ceiling or floor
if bird_y < 0 or bird_y + bird_height > SCREEN_HEIGHT:
return True
# Check pipes
bird_rect = pygame.Rect(bird_x, bird_y, bird_width, bird_height)
for pipe in pipes:
if bird_rect.colliderect(pipe["top"]) or bird_rect.colliderect(pipe["bottom"]):
return True
return False
def draw_score():
score_text = font.render(f"Score: {score}", True, BLACK)
screen.blit(score_text, (10, 10))
# Main game loop
while running:
current_time = pygame.time.get_ticks()
screen.fill(SKY_BLUE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and game_active:
bird_velocity = FLAP_STRENGTH
if event.key == pygame.K_r and not game_active:
# Restart game
bird_y = SCREEN_HEIGHT // 2
bird_velocity = 0
pipes = []
score = 0
game_active = True
if event.type == pygame.MOUSEBUTTONDOWN and game_active:
bird_velocity = FLAP_STRENGTH
if game_active:
# Bird physics
bird_velocity += GRAVITY
bird_y += bird_velocity
# Generate pipes
if current_time - last_pipe_time > PIPE_FREQUENCY:
pipes.append(create_pipe())
last_pipe_time = current_time
# Move and draw pipes
move_pipes(pipes)
pipes = remove_offscreen_pipes(pipes)
draw_pipes(pipes)
# Check for scoring
for pipe in pipes:
if pipe["top"].right < bird_x and not pipe["passed"]:
score += 1
pipe["passed"] = True
# Collision check
if check_collision(pipes, bird_y):
game_active = False
# Draw bird and score
draw_bird(bird_x, bird_y)
draw_score()
# Game over screen
if not game_active:
game_over = font.render("Game Over! Press 'R' to Restart", True, BLACK)
screen.blit(game_over, (SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()Deploy This Model
Production-ready deployment in minutes
Together.ai
Instant API access to this model
Production-ready inference API. Start free, scale to millions.
Try Free APIReplicate
One-click model deployment
Run models in the cloud with simple API. No DevOps required.
Deploy NowDisclosure: We may earn a commission from these partners. This helps keep LLMYourWay free.