flappy bird
To upload files, please first save the app
import streamlit as st
import numpy as np
st.title('Flappy Bird Clone')
st.write('This is a simple clone of the classic Flappy Bird game built with Streamlit!')
st.write('Instructions: Click to flap and avoid the pipes!')
# Game Variables
game_over = False
score = 0
bird_y = 200
bird_x = 50
pipe_x = 400
pipe_height = np.random.randint(150, 350)
# Draw Bird
def draw_bird(y):
st.markdown(f'<div style="position: absolute; left: {bird_x}px; top: {y}px; width: 20px; height: 20px; background-color: yellow;"></div>', unsafe_allow_html=True)
# Draw Pipes
def draw_pipes(x, height):
st.markdown(f'<div style="position: absolute; left: {x}px; top: 0px; width: 50px; height: {height}px; background-color: green;"></div>', unsafe_allow_html=True)
st.markdown(f'<div style="position: absolute; left: {x}px; top: {height + 100}px; width: 50px; height: {600 - height - 100}px; background-color: green;"></div>', unsafe_allow_html=True)
while not game_over:
st.empty()
if st.button('Flap'):
bird_y -= 30 # Move the bird up for flap
else:
bird_y += 5 # Gravity effect
draw_bird(bird_y)
draw_pipes(pipe_x, pipe_height)
pipe_x -= 5 # Move pipe to the left
if pipe_x < 0:
pipe_x = 400
pipe_height = np.random.randint(150, 350) # New pipe height
if bird_y >= 600 or bird_y <= 0: # Collision detection with ground or ceiling
game_over = True
st.write('Game Over! Your score is', score)
st.session_state.sleep(0.1)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?