flappy bird
To upload files, please first save the app
import streamlit as st
import pygame
import random
import sys
# Initialize Pygame
def main():
# Initialize Pygame
pygame.init()
# Set the dimensions of the game window
width, height = 400, 600
screen = pygame.display.set_mode((width, height))
clock = pygame.time.Clock()
# Colors
white = (255, 255, 255)
black = (0, 0, 0)
green = (0, 255, 0)
# Game variables
bird_y = height // 2
bird_velocity = 0
gravity = 0.5
flap_strength = -10
pipes = []
score = 0
# Main game loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
bird_velocity = flap_strength
# Update the bird
bird_velocity += gravity
bird_y += bird_velocity
# Generate pipes
if len(pipes) == 0 or pipes[-1][0] < width - 200:
pipe_height = random.randint(100, 400)
pipes.append([width, pipe_height])
# Move pipes
for pipe in pipes:
pipe[0] -= 5
# Check for collisions
if bird_y > height or bird_y < 0:
break
for pipe in pipes:
if pipe[0] < 50 and pipe[0] > 30:
if bird_y > pipe[1] and bird_y < pipe[1] + 200:
break
score += 1
# Render
screen.fill(white)
pygame.draw.circle(screen, black, (50, int(bird_y)), 15)
for pipe in pipes:
pygame.draw.rect(screen, green, (pipe[0], 0, 50, pipe[1]))
pygame.draw.rect(screen, green, (pipe[0], pipe[1] + 200, 50, height))
pygame.display.flip()
clock.tick(30)
# Game over
st.write("Game Over! Your score: ", score)
if __name__ == '__main__':
st.title("Flappy Bird Game")
main()
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?