Lukeetah commited on
Commit
56f5e02
·
verified ·
1 Parent(s): 1a07fc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -54
app.py CHANGED
@@ -1,10 +1,9 @@
1
- # app.py - VERSIÓN ÉPICA GAUCHO CÓSMICO
2
  import gradio as gr
3
  import time
4
  import math
5
- from PIL import Image, ImageDraw, ImageFont
6
- import io
7
- import numpy as np
8
  from game_engine import GauchoCharacter, PhysicsEngine, WorldGenerator, Vector2D
9
 
10
  class EpicGauchoRenderer:
@@ -15,11 +14,13 @@ class EpicGauchoRenderer:
15
  self.world_tiles = self._create_epic_tiles()
16
 
17
  def _generate_stars(self, count):
 
 
18
  return [(
19
- np.random.randint(0, 800),
20
- np.random.randint(0, 600),
21
- np.random.choice([1, 2, 3]),
22
- np.random.choice([(255, 255, 255), (200, 200, 255), (255, 255, 200)])
23
  ) for _ in range(count)]
24
 
25
  def _create_epic_tiles(self):
@@ -45,12 +46,13 @@ class EpicGauchoRenderer:
45
  # Estela de movimiento
46
  trail_length = min(30, abs(velocity.x) + abs(velocity.y))
47
  if trail_length > 5:
48
- trail_x = x - velocity.x * 3
49
- trail_y = y - velocity.y * 3
50
  draw.ellipse([trail_x-10, trail_y-10, trail_x+10, trail_y+10],
51
- fill=(100, 200, 255, 128))
52
 
53
  # Cuerpo del gaucho (más épico)
 
54
  draw.ellipse([x-25, y-25, x+25, y+25],
55
  fill=(139, 69, 19), outline=(101, 67, 33), width=3)
56
 
@@ -92,6 +94,7 @@ class CosmicGauchoEpic:
92
  self.crystals = self._spawn_crystals()
93
  self.enemies = []
94
  self.particles = []
 
95
 
96
  def _spawn_crystals(self):
97
  """Genera cristales de valores argentinos"""
@@ -102,11 +105,13 @@ class CosmicGauchoEpic:
102
  'type': crystal_type,
103
  'position': Vector2D(200 + i * 150, 200 + (i % 2) * 200),
104
  'collected': False,
105
- 'pulse': 0
106
  })
107
  return crystals
108
 
109
  def update_game_state(self, movement: str = "none"):
 
 
110
  acceleration = Vector2D(0, 0)
111
  speed = 4.0
112
 
@@ -154,8 +159,8 @@ class CosmicGauchoEpic:
154
  # Fondo estrellado épico
155
  for star_x, star_y, size, color in self.renderer.background_stars:
156
  # Parallax scrolling
157
- scroll_x = star_x - self.camera_offset.x * 0.3
158
- scroll_y = star_y - self.camera_offset.y * 0.3
159
  if 0 <= scroll_x <= 800 and 0 <= scroll_y <= 600:
160
  draw.ellipse([scroll_x-size, scroll_y-size, scroll_x+size, scroll_y+size], fill=color)
161
 
@@ -163,11 +168,11 @@ class CosmicGauchoEpic:
163
  grid_size = 100
164
  for x in range(-200, 1000, grid_size):
165
  for y in range(-200, 800, grid_size):
166
- screen_x = x - self.camera_offset.x
167
- screen_y = y - self.camera_offset.y
168
  if -100 <= screen_x <= 900 and -100 <= screen_y <= 700:
169
  # Campo energético
170
- alpha = int(50 + 30 * math.sin(time.time() + x/100))
171
  color = (0, 50 + alpha//2, 100 + alpha)
172
  draw.rectangle([screen_x, screen_y, screen_x+90, screen_y+90],
173
  fill=color, outline=(0, 150, 255), width=1)
@@ -175,37 +180,38 @@ class CosmicGauchoEpic:
175
  # Cristales épicos
176
  for crystal in self.crystals:
177
  if not crystal['collected']:
178
- crystal_x = crystal['position'].x - self.camera_offset.x
179
- crystal_y = crystal['position'].y - self.camera_offset.y
180
 
181
  if 0 <= crystal_x <= 800 and 0 <= crystal_y <= 600:
182
  # Efecto de pulso
183
- pulse = math.sin(time.time() * 3 + crystal['pulse']) * 10
184
- size = 20 + pulse
185
 
186
  # Aura del cristal
187
  draw.ellipse([crystal_x-size-5, crystal_y-size-5,
188
  crystal_x+size+5, crystal_y+size+5],
189
- fill=(255, 255, 255, 50))
190
 
191
  # Cristal
192
- crystal_color = {
193
  'Solidaridad': (255, 100, 100),
194
  'Familia': (100, 255, 100),
195
  'Amistad': (100, 100, 255),
196
  'Respeto': (255, 255, 100),
197
  'Creatividad': (255, 100, 255)
198
- }.get(crystal['type'], (255, 255, 255))
 
199
 
200
  draw.polygon([
201
  (crystal_x, crystal_y-size),
202
- (crystal_x-size*0.7, crystal_y),
203
  (crystal_x, crystal_y+size),
204
- (crystal_x+size*0.7, crystal_y)
205
  ], fill=crystal_color, outline=(255, 255, 255), width=2)
206
 
207
- # Gaucho épico
208
- player_screen_x = 400 # Siempre centrado
209
  player_screen_y = 300
210
  self.renderer.draw_epic_gaucho(draw, player_screen_x, player_screen_y, self.player.velocity)
211
 
@@ -216,47 +222,30 @@ class CosmicGauchoEpic:
216
  return {
217
  "🗺️ Coordenadas": f"({self.player.position.x:.0f}, {self.player.position.y:.0f})",
218
  "⚡ Momentum": f"({self.player.velocity.x:.1f}, {self.player.velocity.y:.1f})",
219
- "💎 Cristales": f"{cristales_obtenidos}/7",
220
- "🎯 Misión": "Recuperar la identidad argentina" if cristales_obtenidos < 7 else "¡MISIÓN CUMPLIDA!",
221
  "🔥 Épica": "MÁXIMA"
222
  }
223
 
224
  def create_epic_interface():
225
  game = CosmicGauchoEpic()
226
 
227
- custom_css = """
228
- .epic-title {
229
- background: linear-gradient(45deg, #FF6B6B, #4ECDC4, #45B7D1, #96CEB4, #FFEAA7);
230
- -webkit-background-clip: text;
231
- -webkit-text-fill-color: transparent;
232
- font-size: 3em !important;
233
- font-weight: bold;
234
- text-align: center;
235
- }
236
- .epic-container {
237
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
238
- border-radius: 15px;
239
- padding: 20px;
240
- }
241
- """
242
-
243
  with gr.Blocks(
244
  title="🚀 EL GAUCHO CÓSMICO ÉPICO 🇦🇷",
245
- css=custom_css,
246
  theme=gr.themes.Soft()
247
  ) as interface:
248
 
249
  gr.HTML("""
250
- <div class="epic-title">
251
  🌟 EL GAUCHO CÓSMICO 🌟<br>
252
- <span style="font-size: 0.6em; color: #FFD700;">
253
  AVENTURA ÉPICA DE IDENTIDAD CULTURAL ARGENTINA
254
  </span>
255
  </div>
256
  """)
257
 
258
  with gr.Row():
259
- with gr.Column(scale=2, elem_classes="epic-container"):
260
  game_display = gr.Image(
261
  label="🌌 LA PAMPA CÓSMICA ÉPICA",
262
  interactive=False,
@@ -272,7 +261,7 @@ def create_epic_interface():
272
 
273
  with gr.Column(scale=1):
274
  gr.Markdown("### 🎯 ESTADO ÉPICO DEL GAUCHO")
275
- status_display = gr.JSON(label="📊 DATOS DE MARTÍN 'EL MATE'", elem_classes="epic-container")
276
 
277
  gr.Markdown("### 🗣️ FILOSOFÍA GAUCHA CÓSMICA")
278
  wisdom_quotes = [
@@ -283,12 +272,10 @@ def create_epic_interface():
283
  "¡Vamos a mostrarles qué es ser argentino!"
284
  ]
285
 
286
- import random
287
  wisdom_display = gr.Textbox(
288
  value=random.choice(wisdom_quotes),
289
  label="💭 Sabiduría del Gaucho",
290
- interactive=False,
291
- elem_classes="epic-container"
292
  )
293
 
294
  def epic_move_and_update(direction):
 
1
+ # app.py - VERSIÓN ÉPICA SIN ERRORES DE NUMPY
2
  import gradio as gr
3
  import time
4
  import math
5
+ from PIL import Image, ImageDraw
6
+ import random
 
7
  from game_engine import GauchoCharacter, PhysicsEngine, WorldGenerator, Vector2D
8
 
9
  class EpicGauchoRenderer:
 
14
  self.world_tiles = self._create_epic_tiles()
15
 
16
  def _generate_stars(self, count):
17
+ """Genera estrellas sin usar numpy.choice con tuplas"""
18
+ star_colors = [(255, 255, 255), (200, 200, 255), (255, 255, 200), (255, 200, 255)]
19
  return [(
20
+ random.randint(0, 800),
21
+ random.randint(0, 600),
22
+ random.choice([1, 2, 3]),
23
+ random.choice(star_colors) # Usamos random de Python, no numpy
24
  ) for _ in range(count)]
25
 
26
  def _create_epic_tiles(self):
 
46
  # Estela de movimiento
47
  trail_length = min(30, abs(velocity.x) + abs(velocity.y))
48
  if trail_length > 5:
49
+ trail_x = int(x - velocity.x * 3)
50
+ trail_y = int(y - velocity.y * 3)
51
  draw.ellipse([trail_x-10, trail_y-10, trail_x+10, trail_y+10],
52
+ fill=(100, 200, 255))
53
 
54
  # Cuerpo del gaucho (más épico)
55
+ x, y = int(x), int(y)
56
  draw.ellipse([x-25, y-25, x+25, y+25],
57
  fill=(139, 69, 19), outline=(101, 67, 33), width=3)
58
 
 
94
  self.crystals = self._spawn_crystals()
95
  self.enemies = []
96
  self.particles = []
97
+ self.game_time = 0
98
 
99
  def _spawn_crystals(self):
100
  """Genera cristales de valores argentinos"""
 
105
  'type': crystal_type,
106
  'position': Vector2D(200 + i * 150, 200 + (i % 2) * 200),
107
  'collected': False,
108
+ 'pulse': i * math.pi / 3 # Desfase para que no pulsen todos juntos
109
  })
110
  return crystals
111
 
112
  def update_game_state(self, movement: str = "none"):
113
+ self.game_time += 0.1
114
+
115
  acceleration = Vector2D(0, 0)
116
  speed = 4.0
117
 
 
159
  # Fondo estrellado épico
160
  for star_x, star_y, size, color in self.renderer.background_stars:
161
  # Parallax scrolling
162
+ scroll_x = int(star_x - self.camera_offset.x * 0.3)
163
+ scroll_y = int(star_y - self.camera_offset.y * 0.3)
164
  if 0 <= scroll_x <= 800 and 0 <= scroll_y <= 600:
165
  draw.ellipse([scroll_x-size, scroll_y-size, scroll_x+size, scroll_y+size], fill=color)
166
 
 
168
  grid_size = 100
169
  for x in range(-200, 1000, grid_size):
170
  for y in range(-200, 800, grid_size):
171
+ screen_x = int(x - self.camera_offset.x)
172
+ screen_y = int(y - self.camera_offset.y)
173
  if -100 <= screen_x <= 900 and -100 <= screen_y <= 700:
174
  # Campo energético
175
+ alpha = int(50 + 30 * math.sin(self.game_time + x/100))
176
  color = (0, 50 + alpha//2, 100 + alpha)
177
  draw.rectangle([screen_x, screen_y, screen_x+90, screen_y+90],
178
  fill=color, outline=(0, 150, 255), width=1)
 
180
  # Cristales épicos
181
  for crystal in self.crystals:
182
  if not crystal['collected']:
183
+ crystal_x = int(crystal['position'].x - self.camera_offset.x)
184
+ crystal_y = int(crystal['position'].y - self.camera_offset.y)
185
 
186
  if 0 <= crystal_x <= 800 and 0 <= crystal_y <= 600:
187
  # Efecto de pulso
188
+ pulse = math.sin(self.game_time * 3 + crystal['pulse']) * 10
189
+ size = int(20 + pulse)
190
 
191
  # Aura del cristal
192
  draw.ellipse([crystal_x-size-5, crystal_y-size-5,
193
  crystal_x+size+5, crystal_y+size+5],
194
+ fill=(100, 100, 100))
195
 
196
  # Cristal
197
+ crystal_colors = {
198
  'Solidaridad': (255, 100, 100),
199
  'Familia': (100, 255, 100),
200
  'Amistad': (100, 100, 255),
201
  'Respeto': (255, 255, 100),
202
  'Creatividad': (255, 100, 255)
203
+ }
204
+ crystal_color = crystal_colors.get(crystal['type'], (255, 255, 255))
205
 
206
  draw.polygon([
207
  (crystal_x, crystal_y-size),
208
+ (crystal_x-int(size*0.7), crystal_y),
209
  (crystal_x, crystal_y+size),
210
+ (crystal_x+int(size*0.7), crystal_y)
211
  ], fill=crystal_color, outline=(255, 255, 255), width=2)
212
 
213
+ # Gaucho épico (siempre centrado)
214
+ player_screen_x = 400
215
  player_screen_y = 300
216
  self.renderer.draw_epic_gaucho(draw, player_screen_x, player_screen_y, self.player.velocity)
217
 
 
222
  return {
223
  "🗺️ Coordenadas": f"({self.player.position.x:.0f}, {self.player.position.y:.0f})",
224
  "⚡ Momentum": f"({self.player.velocity.x:.1f}, {self.player.velocity.y:.1f})",
225
+ "💎 Cristales": f"{cristales_obtenidos}/5",
226
+ "🎯 Misión": "Recuperar la identidad argentina" if cristales_obtenidos < 5 else "¡MISIÓN CUMPLIDA!",
227
  "🔥 Épica": "MÁXIMA"
228
  }
229
 
230
  def create_epic_interface():
231
  game = CosmicGauchoEpic()
232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
  with gr.Blocks(
234
  title="🚀 EL GAUCHO CÓSMICO ÉPICO 🇦🇷",
 
235
  theme=gr.themes.Soft()
236
  ) as interface:
237
 
238
  gr.HTML("""
239
+ <div style="text-align: center; color: #FFD700; font-size: 2.5em; font-weight: bold; margin: 20px;">
240
  🌟 EL GAUCHO CÓSMICO 🌟<br>
241
+ <span style="font-size: 0.6em; color: #87CEEB;">
242
  AVENTURA ÉPICA DE IDENTIDAD CULTURAL ARGENTINA
243
  </span>
244
  </div>
245
  """)
246
 
247
  with gr.Row():
248
+ with gr.Column(scale=2):
249
  game_display = gr.Image(
250
  label="🌌 LA PAMPA CÓSMICA ÉPICA",
251
  interactive=False,
 
261
 
262
  with gr.Column(scale=1):
263
  gr.Markdown("### 🎯 ESTADO ÉPICO DEL GAUCHO")
264
+ status_display = gr.JSON(label="📊 DATOS DE MARTÍN 'EL MATE'")
265
 
266
  gr.Markdown("### 🗣️ FILOSOFÍA GAUCHA CÓSMICA")
267
  wisdom_quotes = [
 
272
  "¡Vamos a mostrarles qué es ser argentino!"
273
  ]
274
 
 
275
  wisdom_display = gr.Textbox(
276
  value=random.choice(wisdom_quotes),
277
  label="💭 Sabiduría del Gaucho",
278
+ interactive=False
 
279
  )
280
 
281
  def epic_move_and_update(direction):