Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,79 +1,109 @@
|
|
| 1 |
-
# app.py
|
| 2 |
import gradio as gr
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
from
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
|
|
|
| 8 |
def __init__(self):
|
| 9 |
-
|
| 10 |
-
self.
|
| 11 |
-
self.
|
| 12 |
-
self.
|
|
|
|
| 13 |
|
| 14 |
-
def
|
| 15 |
-
|
| 16 |
-
self.sprite_atlas = self.optimizer.generate_sprite_atlas([
|
| 17 |
-
'assets/gaucho_base.webp',
|
| 18 |
-
'assets/enemy_alien.webp',
|
| 19 |
-
'assets/cristal_icon.webp'
|
| 20 |
-
])
|
| 21 |
|
| 22 |
-
def
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
# Lógica de renderizado usando el atlas de sprites
|
| 27 |
-
# (Implementación detallada requeriría sistema de coordenadas)
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
def
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
def
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
return {
|
| 44 |
-
game_display: self.render_frame(),
|
| 45 |
-
debug_panel: debug_info,
|
| 46 |
-
dialog_display: dialog_text
|
| 47 |
-
}
|
| 48 |
|
| 49 |
-
def
|
| 50 |
game = EnhancedCosmicGaucho()
|
| 51 |
|
| 52 |
-
with gr.Blocks(title="El Gaucho Cósmico
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
with gr.Row():
|
| 54 |
-
|
| 55 |
-
game_display = gr.Image(label="Pampa Cósmica", interactive=False, streaming=True)
|
| 56 |
-
dialog_display = gr.Textbox(label="Diálogo Cultural", interactive=False)
|
| 57 |
-
gr.Button("Continuar", variant="primary").click(
|
| 58 |
-
fn=lambda: game.update_interface(),
|
| 59 |
-
outputs=[game_display, dialog_display]
|
| 60 |
-
)
|
| 61 |
|
| 62 |
-
with gr.Column(
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
|
|
|
| 67 |
debug_panel = gr.DataFrame(
|
| 68 |
headers=["Atributo", "Valor"],
|
| 69 |
-
datatype=["str", "
|
| 70 |
interactive=False
|
| 71 |
)
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
interface.load(
|
| 74 |
-
fn=
|
| 75 |
-
outputs=game_display,
|
| 76 |
every=0.033
|
| 77 |
)
|
| 78 |
|
| 79 |
return interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py - Versión corregida y optimizada
|
| 2 |
import gradio as gr
|
| 3 |
+
import time
|
| 4 |
+
import math
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import io
|
| 7 |
+
from game_engine import GauchoCharacter, PhysicsEngine, WorldGenerator, Vector2D
|
| 8 |
|
| 9 |
+
# Clase base del juego
|
| 10 |
+
class CosmicGauchoGame:
|
| 11 |
def __init__(self):
|
| 12 |
+
self.player = GauchoCharacter()
|
| 13 |
+
self.physics = PhysicsEngine()
|
| 14 |
+
self.world = WorldGenerator()
|
| 15 |
+
self.current_chunk = None
|
| 16 |
+
self.load_initial_world()
|
| 17 |
|
| 18 |
+
def load_initial_world(self):
|
| 19 |
+
self.current_chunk = self.world.generate_chunk('pampa', 16)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
def update_game_state(self, user_input: dict):
|
| 22 |
+
# Implementación básica de movimiento
|
| 23 |
+
acceleration = Vector2D(0, 0)
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
if user_input.get('left'):
|
| 26 |
+
acceleration.x = -5
|
| 27 |
+
if user_input.get('right'):
|
| 28 |
+
acceleration.x = 5
|
| 29 |
+
if user_input.get('up'):
|
| 30 |
+
acceleration.y = -5
|
| 31 |
+
if user_input.get('down'):
|
| 32 |
+
acceleration.y = 5
|
| 33 |
+
|
| 34 |
+
self.player.velocity = self.physics.apply_momentum(
|
| 35 |
+
self.player.velocity,
|
| 36 |
+
acceleration,
|
| 37 |
+
dt=0.033
|
| 38 |
+
)
|
| 39 |
+
self.player.position += self.player.velocity * 0.033
|
| 40 |
|
| 41 |
+
def render_frame(self) -> Image.Image:
|
| 42 |
+
img = Image.new('RGB', (800, 600), (30, 30, 30))
|
| 43 |
+
return img
|
| 44 |
+
|
| 45 |
+
# Clase mejorada con optimizaciones
|
| 46 |
+
class EnhancedCosmicGaucho(CosmicGauchoGame):
|
| 47 |
+
def __init__(self):
|
| 48 |
+
super().__init__()
|
| 49 |
+
self.last_frame_time = time.time()
|
| 50 |
|
| 51 |
+
def optimized_render(self) -> Image.Image:
|
| 52 |
+
current_time = time.time()
|
| 53 |
+
delta_time = current_time - self.last_frame_time
|
| 54 |
+
self.last_frame_time = current_time
|
| 55 |
+
|
| 56 |
+
frame = self.render_frame()
|
| 57 |
+
return frame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
def create_game_interface():
|
| 60 |
game = EnhancedCosmicGaucho()
|
| 61 |
|
| 62 |
+
with gr.Blocks(title="El Gaucho Cósmico", theme=gr.themes.Base(
|
| 63 |
+
primary_hue="blue",
|
| 64 |
+
secondary_hue="teal",
|
| 65 |
+
font=["Helvetica", "Arial", "sans-serif"]
|
| 66 |
+
)) as interface:
|
| 67 |
+
|
| 68 |
with gr.Row():
|
| 69 |
+
game_display = gr.Image(label="Pampa Cósmica", shape=(800, 600), interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
with gr.Column():
|
| 72 |
+
gr.Markdown("## Controles Gaucho-Hacker")
|
| 73 |
+
with gr.Row():
|
| 74 |
+
left_btn = gr.Button("←", variant="secondary")
|
| 75 |
+
right_btn = gr.Button("→", variant="secondary")
|
| 76 |
+
with gr.Row():
|
| 77 |
+
up_btn = gr.Button("↑", variant="secondary")
|
| 78 |
+
down_btn = gr.Button("↓", variant="secondary")
|
| 79 |
|
| 80 |
+
gr.Markdown("## Estado del Jugador")
|
| 81 |
debug_panel = gr.DataFrame(
|
| 82 |
headers=["Atributo", "Valor"],
|
| 83 |
+
datatype=["str", "str"],
|
| 84 |
interactive=False
|
| 85 |
)
|
| 86 |
|
| 87 |
+
def update_frame():
|
| 88 |
+
game.update_game_state({
|
| 89 |
+
'left': False,
|
| 90 |
+
'right': False,
|
| 91 |
+
'up': False,
|
| 92 |
+
'down': False
|
| 93 |
+
})
|
| 94 |
+
return game.optimized_render(), [
|
| 95 |
+
["Posición", f"{game.player.position.x:.1f}, {game.player.position.y:.1f}"],
|
| 96 |
+
["Velocidad", f"{game.player.velocity.x:.1f}, {game.player.velocity.y:.1f}"]
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
interface.load(
|
| 100 |
+
fn=update_frame,
|
| 101 |
+
outputs=[game_display, debug_panel],
|
| 102 |
every=0.033
|
| 103 |
)
|
| 104 |
|
| 105 |
return interface
|
| 106 |
+
|
| 107 |
+
if __name__ == "__main__":
|
| 108 |
+
interface = create_game_interface()
|
| 109 |
+
interface.launch()
|