Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -149,6 +149,9 @@ class ScottPilgrimGame:
|
|
149 |
"run": ["characters/Scott_angry.webp"]
|
150 |
}
|
151 |
self.player_image_path = self.image_assets["idle"][0]
|
|
|
|
|
|
|
152 |
elif character_choice == "Play as Ramona Flowers":
|
153 |
self.player = RamonaFlowers()
|
154 |
self.current_ex_list = list(self.ramona_exes) # Use a copy of the list
|
@@ -160,6 +163,9 @@ class ScottPilgrimGame:
|
|
160 |
"run": ["characters/Ramona_attack2.webp"]
|
161 |
}
|
162 |
self.player_image_path = self.image_assets["idle"][0]
|
|
|
|
|
|
|
163 |
else:
|
164 |
self.add_message("Invalid character choice. Please select Scott or Ramona.")
|
165 |
return
|
@@ -335,6 +341,12 @@ class ScottPilgrimGame:
|
|
335 |
choices = self.image_assets[action]
|
336 |
self.player_image_path = random.choice(choices)
|
337 |
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
# --- Gradio Interface Logic ---
|
339 |
|
340 |
# Create a single game instance to be managed by gr.State
|
@@ -407,6 +419,9 @@ def update_ui(game_state):
|
|
407 |
elif phase == "win":
|
408 |
game_state.message_log.append("\nYOU WON! Thanks for playing!")
|
409 |
|
|
|
|
|
|
|
410 |
log_html = _format_log_html(game_state)
|
411 |
status_html = _format_status_html(game_state)
|
412 |
hero_img_path = game_state.get_player_image()
|
|
|
149 |
"run": ["characters/Scott_angry.webp"]
|
150 |
}
|
151 |
self.player_image_path = self.image_assets["idle"][0]
|
152 |
+
# Prepare cycling list
|
153 |
+
self.image_cycle = self.image_assets["idle"] + self.image_assets["attack"] + self.image_assets["run"]
|
154 |
+
self.image_cycle_index = 0
|
155 |
elif character_choice == "Play as Ramona Flowers":
|
156 |
self.player = RamonaFlowers()
|
157 |
self.current_ex_list = list(self.ramona_exes) # Use a copy of the list
|
|
|
163 |
"run": ["characters/Ramona_attack2.webp"]
|
164 |
}
|
165 |
self.player_image_path = self.image_assets["idle"][0]
|
166 |
+
# Prepare cycling list
|
167 |
+
self.image_cycle = self.image_assets["idle"] + self.image_assets["attack"] + self.image_assets["run"]
|
168 |
+
self.image_cycle_index = 0
|
169 |
else:
|
170 |
self.add_message("Invalid character choice. Please select Scott or Ramona.")
|
171 |
return
|
|
|
341 |
choices = self.image_assets[action]
|
342 |
self.player_image_path = random.choice(choices)
|
343 |
|
344 |
+
def advance_player_image(self):
|
345 |
+
"""Cycle through all available images sequentially."""
|
346 |
+
if hasattr(self, "image_cycle") and self.image_cycle:
|
347 |
+
self.image_cycle_index = (self.image_cycle_index + 1) % len(self.image_cycle)
|
348 |
+
self.player_image_path = self.image_cycle[self.image_cycle_index]
|
349 |
+
|
350 |
# --- Gradio Interface Logic ---
|
351 |
|
352 |
# Create a single game instance to be managed by gr.State
|
|
|
419 |
elif phase == "win":
|
420 |
game_state.message_log.append("\nYOU WON! Thanks for playing!")
|
421 |
|
422 |
+
# Cycle hero image each UI update
|
423 |
+
game_state.advance_player_image()
|
424 |
+
|
425 |
log_html = _format_log_html(game_state)
|
426 |
status_html = _format_status_html(game_state)
|
427 |
hero_img_path = game_state.get_player_image()
|