flappy bird
To upload files, please first save the app
import streamlit as st
import pygame
import random
import sys
# Set Constants
SCREEN_WIDTH, SCREEN_HEIGHT = 400, 600
BIRD_WIDTH, BIRD_HEIGHT = 34, 24
PIPE_WIDTH, PIPE_HEIGHT = 52, 320
# Initialize pygame
pygame.init()
# Set up the display
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption('Flappy Bird')
def game_loop():
bird_y = SCREEN_HEIGHT // 2
bird_x = SCREEN_WIDTH // 4
gravity = 0.5
velocity = 0
score = 0
pipes = []
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
velocity = -10
# Bird physics
velocity += gravity
bird_y += velocity
# Create new pipes
if random.randint(0, 100) < 2:
pipe_y = random.randint(50, SCREEN_HEIGHT - 100)
pipes.append((SCREEN_WIDTH, pipe_y))
# Move pipes
pipes = [(x - 5, y) for x, y in pipes if x > -PIPE_WIDTH]
# Draw everything
screen.fill((135, 206, 235)) # Sky blue
pygame.draw.rect(screen, (255, 0, 0), (bird_x, bird_y, BIRD_WIDTH, BIRD_HEIGHT)) # Bird
for x, y in pipes:
pygame.draw.rect(screen, (0, 255, 0), (x, y, PIPE_WIDTH, PIPE_HEIGHT))
pygame.draw.rect(screen, (0, 255, 0), (x, y - 150, PIPE_WIDTH, PIPE_HEIGHT)) # Upper Pipe
# Update display
pygame.display.flip()
# Frame Per Second
clock.tick(30)
st.title('Flappy Bird in Streamlit')
if st.button('Start Game'):
game_loop()
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?