flappy.py game code
flappy.py game code
import sys
# Game constants
SCREEN_WIDTH = 640
SCREEN_HEIGHT = 480
PIPE_WIDTH = 80
PIPE_HEIGHT = 600
BIRD_WIDTH = 60
BIRD_HEIGHT = 60
GRAVITY = 0.5
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
# Initialize Pygame
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
clock = pygame.time.Clock()
# Load images
bird_image = pygame.image.load('bird.png')
pipe_image = pygame.image.load('pipe.png')
# Game variables
bird_x = SCREEN_WIDTH / 2
bird_y = SCREEN_HEIGHT / 2
bird_velocity = 0
pipe_x = SCREEN_WIDTH + PIPE_WIDTH
pipe_y = SCREEN_HEIGHT / 2
score = 0
# Game loop
while True:
# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
bird_velocity = -10
# Move bird
bird_velocity += GRAVITY
bird_y += bird_velocity
# Move pipe
pipe_x -= 5
# Check collision
if bird_y + BIRD_HEIGHT > SCREEN_HEIGHT or bird_y < 0:
print("Game Over!")
break
elif pipe_x + PIPE_WIDTH > bird_x and pipe_x < bird_x + BIRD_WIDTH:
if bird_y + BIRD_HEIGHT > pipe_y and bird_y < pipe_y + PIPE_HEIGHT:
print("Game Over!")
break
# Draw everything
screen.fill(WHITE)
screen.blit(bird_image, (bird_x, bird_y))
screen.blit(pipe_image, (pipe_x, pipe_y))
pygame.display.flip()
# Cap framerate
clock.tick(60)
# Update score
score += 1
print(f"Score: {score}")
import random
import sys
import py.game
from pygame.locals import
fps= 32
screenwidth=289
screenhight=511
screen= pygame.display.set.mode
groundly=screenheight*0.8
game_spirit=