Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pgzero
- import random
- WIDTH = 800
- HEIGHT = 600
- GROUND_Y = HEIGHT - 70
- # -------------------------------
- # ESTADOS DE JUEGO
- # -------------------------------
- game_state = "start" # 'start' | 'intro' | 'playing'
- mode = None # 'single' | 'two'
- nivel = 1
- # -------------------------------
- # RECURSOS DE JUGADOR / PARTIDA
- # -------------------------------
- players = [] # Lista de actores-jugadores
- player_imgs = ["gladiador1", "gladiador2"]
- weapons = ["espada", "lanza"] # Se amplía fácilmente
- current_weapon = [0, 0] # Índice del arma por jugador
- lives = [3, 3] # Corazones por jugador
- max_lives = 3
- # Economía del juego
- player_gems = 0 # Gemas acumuladas
- GEMS_PER_LEVEL = 10
- WEAPON_COST = 15 # Gemas necesarias para comprar arma en cofre
- REVIVE_COST = 20 # Gemas necesarias para revivir
- # Objetos del mapa
- cofres = None # Actores-cofre
- intro_timer = 0 # Controla duración de cinemática
- # -------------------------------
- # CONFIGURACIÓN INICIAL
- # -------------------------------
- def reset_game():
- """Prepara variables para una partida nueva."""
- global players, cofres, current_weapon, lives, player_gems, nivel
- nivel = 1
- players = [Actor(player_imgs[0], (120, GROUND_Y))]
- if mode == "two":
- players.append(Actor(player_imgs[1], (680, GROUND_Y)))
- current_weapon[:] = [0, 0]
- lives[:] = [max_lives, max_lives]
- cofres = []
- cofres.extend([
- Actor("cofre_cerrado", (400, GROUND_Y)),
- Actor("cofre_cerrado", (600, GROUND_Y))
- ])
- player_gems = 0
- # -------------------------------
- # FUNCIÓN DRAW
- # -------------------------------
- def draw():
- screen.clear()
- if game_state == "start":
- screen.draw.text("IL GLADIATORE PERDUTO", center=(WIDTH//2, 100), fontsize=60)
- screen.draw.text("Presiona 1 para 1 jugador", center=(WIDTH//2, 220), fontsize=40)
- screen.draw.text("Presiona 2 para 2 jugadores", center=(WIDTH//2, 270), fontsize=40)
- elif game_state == "intro":
- screen.blit("coliseo_fondo", (0, 0))
- for p in players:
- p.draw()
- screen.draw.text("Te despiertas dentro del Coliseo...", center=(WIDTH//2, 60), fontsize=40)
- elif game_state == "playing":
- fondo = "coliseo_fondo" if nivel == 1 else "catacumbas_fondo"
- screen.blit(fondo, (0, 0))
- for p in players:
- p.draw()
- for c in cofres:
- c.draw()
- arma_texto = "Arma: " + weapons[current_weapon[0]]
- screen.draw.text(arma_texto, (10, 10), fontsize=30)
- screen.draw.text("Gemas: " + str(player_gems), (10, 45), fontsize=30, color="yellow")
- for i in range(lives[0]):
- screen.blit("corazon", (WIDTH - 40*(i+1), 10))
- # -------------------------------
- # ACTUALIZACIÓN GENERAL
- # -------------------------------
- def update(dt):
- global game_state, intro_timer
- if game_state == "intro":
- intro_timer += 1
- if intro_timer > 180:
- game_state = "playing"
- elif game_state == "playing":
- update_players()
- check_cofres()
- apply_gravity()
- # -------------------------------
- # CONTROL DE MOVIMIENTO
- # -------------------------------
- def update_players():
- if keyboard.a:
- players[0].x -= 4
- if keyboard.d:
- players[0].x += 4
- if keyboard.w and players[0].y == GROUND_Y:
- players[0].y -= 120
- if players[0].y < GROUND_Y:
- players[0].y += 5
- if mode == "two":
- if keyboard.left:
- players[1].x -= 4
- if keyboard.right:
- players[1].x += 4
- if keyboard.up and players[1].y == GROUND_Y:
- players[1].y -= 120
- if players[1].y < GROUND_Y:
- players[1].y += 5
- # -------------------------------
- # FÍSICA SIMPLE
- # -------------------------------
- def apply_gravity():
- for p in players:
- if p.y < GROUND_Y:
- p.y += 5
- if p.y > GROUND_Y:
- p.y = GROUND_Y
- # -------------------------------
- # MECÁNICA DE COFRES
- # -------------------------------
- def check_cofres():
- global player_gems, nivel
- for i, p in enumerate(players):
- for c in cofres[:]:
- if p.colliderect(c) and keyboard.e:
- if player_gems >= WEAPON_COST:
- player_gems -= WEAPON_COST
- current_weapon[i] = (current_weapon[i] + 1) % len(weapons)
- cofres.remove(c)
- if not cofres:
- nivel += 1
- player_gems += GEMS_PER_LEVEL
- cofres.extend([
- Actor("cofre_cerrado", (400, GROUND_Y)),
- Actor("cofre_cerrado", (600, GROUND_Y))
- ])
- # -------------------------------
- # EVENTOS DE TECLADO
- # -------------------------------
- def on_key_down(key):
- global game_state, mode, intro_timer, player_gems, lives
- if game_state == "start":
- if key == keys.K_1:
- mode = "single"
- reset_game()
- game_state = "intro"
- intro_timer = 0
- elif key == keys.K_2:
- mode = "two"
- reset_game()
- game_state = "intro"
- intro_timer = 0
- elif game_state == "playing":
- if key == keys.SPACE:
- player_gems += GEMS_PER_LEVEL
- if key == keys.R and lives[0] == 0 and player_gems >= REVIVE_COST:
- player_gems -= REVIVE_COST
- lives[0] = 1
Advertisement
Add Comment
Please, Sign In to add comment