Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ from PIL import Image, ImageDraw
|
|
4 |
# Streamlit setup
|
5 |
st.set_page_config(page_title="Breakout Game", layout="centered")
|
6 |
st.title("🎮 Breakout Game - Hugging Face Version")
|
7 |
-
st.write("
|
8 |
|
9 |
# Initialize game parameters
|
10 |
WIDTH, HEIGHT = 800, 600
|
@@ -31,6 +31,8 @@ if "score" not in st.session_state:
|
|
31 |
st.session_state.score = 0
|
32 |
if "lives" not in st.session_state:
|
33 |
st.session_state.lives = 3
|
|
|
|
|
34 |
|
35 |
|
36 |
# Draw the game screen
|
@@ -71,12 +73,13 @@ def draw_game():
|
|
71 |
|
72 |
|
73 |
# Update game state
|
74 |
-
def update_game(
|
75 |
-
# Move paddle
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
80 |
|
81 |
# Move ball
|
82 |
ball_x, ball_y = st.session_state.ball_pos
|
@@ -137,14 +140,18 @@ st.write(f"**Lives**: {st.session_state.lives}")
|
|
137 |
if st.session_state.lives <= 0:
|
138 |
st.write("**Game Over! Refresh the page to restart.**")
|
139 |
else:
|
140 |
-
#
|
141 |
col1, col2, col3 = st.columns(3)
|
142 |
with col1:
|
143 |
if st.button("⬅️ Move Left"):
|
144 |
-
|
145 |
with col2:
|
146 |
-
if st.button("🔄
|
147 |
-
|
148 |
with col3:
|
149 |
if st.button("➡️ Move Right"):
|
150 |
-
|
|
|
|
|
|
|
|
|
|
4 |
# Streamlit setup
|
5 |
st.set_page_config(page_title="Breakout Game", layout="centered")
|
6 |
st.title("🎮 Breakout Game - Hugging Face Version")
|
7 |
+
st.write("Control the paddle with your mouse or left/right arrow keys.")
|
8 |
|
9 |
# Initialize game parameters
|
10 |
WIDTH, HEIGHT = 800, 600
|
|
|
31 |
st.session_state.score = 0
|
32 |
if "lives" not in st.session_state:
|
33 |
st.session_state.lives = 3
|
34 |
+
if "paddle_speed" not in st.session_state:
|
35 |
+
st.session_state.paddle_speed = 0
|
36 |
|
37 |
|
38 |
# Draw the game screen
|
|
|
73 |
|
74 |
|
75 |
# Update game state
|
76 |
+
def update_game():
|
77 |
+
# Move paddle continuously
|
78 |
+
st.session_state.paddle_x += st.session_state.paddle_speed
|
79 |
+
if st.session_state.paddle_x < 0:
|
80 |
+
st.session_state.paddle_x = 0
|
81 |
+
if st.session_state.paddle_x > WIDTH - PADDLE_WIDTH:
|
82 |
+
st.session_state.paddle_x = WIDTH - PADDLE_WIDTH
|
83 |
|
84 |
# Move ball
|
85 |
ball_x, ball_y = st.session_state.ball_pos
|
|
|
140 |
if st.session_state.lives <= 0:
|
141 |
st.write("**Game Over! Refresh the page to restart.**")
|
142 |
else:
|
143 |
+
# Handle user input
|
144 |
col1, col2, col3 = st.columns(3)
|
145 |
with col1:
|
146 |
if st.button("⬅️ Move Left"):
|
147 |
+
st.session_state.paddle_speed = -10
|
148 |
with col2:
|
149 |
+
if st.button("🔄 Stop Paddle"):
|
150 |
+
st.session_state.paddle_speed = 0
|
151 |
with col3:
|
152 |
if st.button("➡️ Move Right"):
|
153 |
+
st.session_state.paddle_speed = 10
|
154 |
+
|
155 |
+
# Auto-update game state
|
156 |
+
update_game()
|
157 |
+
st.experimental_rerun()
|