Lukeetah commited on
Commit
84cb684
·
verified ·
1 Parent(s): 5dc271a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -55
app.py CHANGED
@@ -1,79 +1,109 @@
1
- # app.py (actualizado)
2
  import gradio as gr
3
- import numpy as np
4
- from optimization import SpaceOptimizer
5
- from dialogue_system import DynamicNarrative
 
 
6
 
7
- class EnhancedCosmicGaucho(CosmicGauchoGame):
 
8
  def __init__(self):
9
- super().__init__()
10
- self.narrative = DynamicNarrative()
11
- self.optimizer = SpaceOptimizer()
12
- self.load_optimized_assets()
 
13
 
14
- def load_optimized_assets(self):
15
- """Carga assets optimizados usando compresión"""
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 render_frame(self) -> Image.Image:
23
- """Renderizado optimizado con sprites comprimidos"""
24
- img = Image.new('RGBA', (800, 600), (0, 0, 0, 0))
25
-
26
- # Lógica de renderizado usando el atlas de sprites
27
- # (Implementación detallada requeriría sistema de coordenadas)
28
 
29
- return img.convert('RGB')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- def handle_dialogue(self, option_index: int):
32
- """Maneja la selección de diálogos"""
33
- current_text = self.narrative.select_option(option_index, self.player)
34
- return self.update_interface(current_text)
 
 
 
 
 
35
 
36
- def update_interface(self, dialog_text: str = ""):
37
- """Actualiza la interfaz con datos optimizados"""
38
- debug_info = [
39
- ["Posición X", self.player.position.x],
40
- ["Posición Y", self.player.position.y],
41
- ["Cristales", sum(self.player.inventory['cristales'].values())]
42
- ]
43
- return {
44
- game_display: self.render_frame(),
45
- debug_panel: debug_info,
46
- dialog_display: dialog_text
47
- }
48
 
49
- def create_enhanced_interface():
50
  game = EnhancedCosmicGaucho()
51
 
52
- with gr.Blocks(title="El Gaucho Cósmico 2.0", theme=gr.themes.Base(primary_hue="blue", secondary_hue="teal")) as interface:
 
 
 
 
 
53
  with gr.Row():
54
- with gr.Column(scale=2):
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(scale=1):
63
- with gr.Accordion("Diálogos Interactivos", open=False):
64
- dialog_choices = gr.Radio(choices=[], label="Opciones Culturales")
65
- dialog_submit = gr.Button("Seleccionar", variant="secondary")
 
 
 
 
66
 
 
67
  debug_panel = gr.DataFrame(
68
  headers=["Atributo", "Valor"],
69
- datatype=["str", "number"],
70
  interactive=False
71
  )
72
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  interface.load(
74
- fn=game.render_frame,
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()