Guest User

Untitled

a guest
Jul 22nd, 2025
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. #pgzero
  2. import random
  3.  
  4. WIDTH = 800
  5. HEIGHT = 600
  6. GROUND_Y = HEIGHT - 70
  7.  
  8. # -------------------------------
  9. # ESTADOS DE JUEGO
  10. # -------------------------------
  11. game_state = "start" # 'start' | 'intro' | 'playing'
  12. mode = None # 'single' | 'two'
  13. nivel = 1
  14.  
  15. # -------------------------------
  16. # RECURSOS DE JUGADOR / PARTIDA
  17. # -------------------------------
  18. players = [] # Lista de actores-jugadores
  19. player_imgs = ["gladiador1", "gladiador2"]
  20. weapons = ["espada", "lanza"] # Se amplía fácilmente
  21. current_weapon = [0, 0] # Índice del arma por jugador
  22. lives = [3, 3] # Corazones por jugador
  23. max_lives = 3
  24.  
  25. # Economía del juego
  26. player_gems = 0 # Gemas acumuladas
  27. GEMS_PER_LEVEL = 10
  28. WEAPON_COST = 15 # Gemas necesarias para comprar arma en cofre
  29. REVIVE_COST = 20 # Gemas necesarias para revivir
  30.  
  31. # Objetos del mapa
  32. cofres = None # Actores-cofre
  33. intro_timer = 0 # Controla duración de cinemática
  34.  
  35. # -------------------------------
  36. # CONFIGURACIÓN INICIAL
  37. # -------------------------------
  38.  
  39. def reset_game():
  40. """Prepara variables para una partida nueva."""
  41. global players, cofres, current_weapon, lives, player_gems, nivel
  42. nivel = 1
  43. players = [Actor(player_imgs[0], (120, GROUND_Y))]
  44. if mode == "two":
  45. players.append(Actor(player_imgs[1], (680, GROUND_Y)))
  46. current_weapon[:] = [0, 0]
  47. lives[:] = [max_lives, max_lives]
  48. cofres = []
  49. cofres.extend([
  50. Actor("cofre_cerrado", (400, GROUND_Y)),
  51. Actor("cofre_cerrado", (600, GROUND_Y))
  52. ])
  53. player_gems = 0
  54.  
  55. # -------------------------------
  56. # FUNCIÓN DRAW
  57. # -------------------------------
  58.  
  59. def draw():
  60. screen.clear()
  61.  
  62. if game_state == "start":
  63. screen.draw.text("IL GLADIATORE PERDUTO", center=(WIDTH//2, 100), fontsize=60)
  64. screen.draw.text("Presiona 1 para 1 jugador", center=(WIDTH//2, 220), fontsize=40)
  65. screen.draw.text("Presiona 2 para 2 jugadores", center=(WIDTH//2, 270), fontsize=40)
  66.  
  67. elif game_state == "intro":
  68. screen.blit("coliseo_fondo", (0, 0))
  69. for p in players:
  70. p.draw()
  71. screen.draw.text("Te despiertas dentro del Coliseo...", center=(WIDTH//2, 60), fontsize=40)
  72.  
  73. elif game_state == "playing":
  74. fondo = "coliseo_fondo" if nivel == 1 else "catacumbas_fondo"
  75. screen.blit(fondo, (0, 0))
  76. for p in players:
  77. p.draw()
  78. for c in cofres:
  79. c.draw()
  80. arma_texto = "Arma: " + weapons[current_weapon[0]]
  81. screen.draw.text(arma_texto, (10, 10), fontsize=30)
  82. screen.draw.text("Gemas: " + str(player_gems), (10, 45), fontsize=30, color="yellow")
  83. for i in range(lives[0]):
  84. screen.blit("corazon", (WIDTH - 40*(i+1), 10))
  85.  
  86. # -------------------------------
  87. # ACTUALIZACIÓN GENERAL
  88. # -------------------------------
  89.  
  90. def update(dt):
  91. global game_state, intro_timer
  92.  
  93. if game_state == "intro":
  94. intro_timer += 1
  95. if intro_timer > 180:
  96. game_state = "playing"
  97.  
  98. elif game_state == "playing":
  99. update_players()
  100. check_cofres()
  101. apply_gravity()
  102.  
  103. # -------------------------------
  104. # CONTROL DE MOVIMIENTO
  105. # -------------------------------
  106.  
  107. def update_players():
  108. if keyboard.a:
  109. players[0].x -= 4
  110. if keyboard.d:
  111. players[0].x += 4
  112. if keyboard.w and players[0].y == GROUND_Y:
  113. players[0].y -= 120
  114. if players[0].y < GROUND_Y:
  115. players[0].y += 5
  116.  
  117. if mode == "two":
  118. if keyboard.left:
  119. players[1].x -= 4
  120. if keyboard.right:
  121. players[1].x += 4
  122. if keyboard.up and players[1].y == GROUND_Y:
  123. players[1].y -= 120
  124. if players[1].y < GROUND_Y:
  125. players[1].y += 5
  126.  
  127. # -------------------------------
  128. # FÍSICA SIMPLE
  129. # -------------------------------
  130.  
  131. def apply_gravity():
  132. for p in players:
  133. if p.y < GROUND_Y:
  134. p.y += 5
  135. if p.y > GROUND_Y:
  136. p.y = GROUND_Y
  137.  
  138. # -------------------------------
  139. # MECÁNICA DE COFRES
  140. # -------------------------------
  141.  
  142. def check_cofres():
  143. global player_gems, nivel
  144. for i, p in enumerate(players):
  145. for c in cofres[:]:
  146. if p.colliderect(c) and keyboard.e:
  147. if player_gems >= WEAPON_COST:
  148. player_gems -= WEAPON_COST
  149. current_weapon[i] = (current_weapon[i] + 1) % len(weapons)
  150. cofres.remove(c)
  151.  
  152. if not cofres:
  153. nivel += 1
  154. player_gems += GEMS_PER_LEVEL
  155. cofres.extend([
  156. Actor("cofre_cerrado", (400, GROUND_Y)),
  157. Actor("cofre_cerrado", (600, GROUND_Y))
  158. ])
  159.  
  160. # -------------------------------
  161. # EVENTOS DE TECLADO
  162. # -------------------------------
  163.  
  164. def on_key_down(key):
  165. global game_state, mode, intro_timer, player_gems, lives
  166.  
  167. if game_state == "start":
  168. if key == keys.K_1:
  169. mode = "single"
  170. reset_game()
  171. game_state = "intro"
  172. intro_timer = 0
  173. elif key == keys.K_2:
  174. mode = "two"
  175. reset_game()
  176. game_state = "intro"
  177. intro_timer = 0
  178.  
  179. elif game_state == "playing":
  180. if key == keys.SPACE:
  181. player_gems += GEMS_PER_LEVEL
  182. if key == keys.R and lives[0] == 0 and player_gems >= REVIVE_COST:
  183. player_gems -= REVIVE_COST
  184. lives[0] = 1
  185.  
Advertisement
Add Comment
Please, Sign In to add comment