Загрузка данных
# pgzero
import pgzrun
import random
# === Основные настройки ===
cell = Actor('border') # Стена
cell1 = Actor('floor') # Пол
cell2 = Actor("crack") # Трещина
cell3 = Actor("bones") # Кости
size_w = 9
size_h = 10
WIDTH = cell.width * size_w
HEIGHT = cell.height * size_h
TITLE = "The Wellkid Explorer"
# === Карты уровней ===
level1_map = [
[0,0,0,0,0,0,0,0,0],
[0,1,1,1,1,1,1,1,0],
[0,1,2,1,3,1,2,1,0],
[0,1,1,3,1,1,1,1,0],
[0,3,1,1,1,2,1,3,0],
[0,1,1,1,3,1,1,1,0],
[0,1,2,1,1,1,3,1,0],
[0,1,1,1,1,1,1,1,0],
[0,0,0,0,0,0,0,0,0],
[-1,-1,-1,-1,-1,-1,-1,-1,-1]
]
level2_map = [
[0,0,0,0,0,0,0,0,0],
[0,1,2,3,1,2,3,1,0],
[0,3,1,1,2,1,1,2,0],
[0,1,2,1,3,1,2,1,0],
[0,1,1,1,1,1,1,1,0],
[0,2,3,2,3,2,3,2,0],
[0,1,1,1,1,1,1,1,0],
[0,1,2,3,2,3,2,1,0],
[0,0,0,0,0,0,0,0,0],
[-1,-1,-1,-1,-1,-1,-1,-1,-1]
]
levels = [level1_map, level2_map]
level = 0
my_map = levels[level]
# === Игрок ===
char = Actor('stand')
char.left = cell.width
char.top = cell.height
char.health = 100
char.attack = 5
# === Враги ===
enemies = []
def load_level():
global my_map, enemies, char
my_map = levels[level]
enemies = []
for i in range(5 + level * 2):
x = random.randint(1, 7) * cell.width
y = random.randint(1, 7) * cell.height
enemy = Actor("enemy", topleft=(x, y))
enemy.health = random.randint(10 + level * 5, 20 + level * 5)
enemy.attack = random.randint(5 + level, 10 + level)
enemies.append(enemy)
char.left = cell.width
char.top = cell.height
char.health = 100
load_level()
# === Игровой режим ===
mode = "game"
win = 0
# === Отрисовка карты ===
def map_draw():
for i in range(len(my_map)):
for j in range(len(my_map[0])):
x = cell.width * j
y = cell.height * i
if my_map[i][j] == 0:
cell.left, cell.top = x, y
cell.draw()
elif my_map[i][j] == 1:
cell1.left, cell1.top = x, y
cell1.draw()
elif my_map[i][j] == 2:
cell2.left, cell2.top = x, y
cell2.draw()
elif my_map[i][j] == 3:
cell3.left, cell3.top = x, y
cell3.draw()
# === Отрисовка игры ===
def draw():
if mode == "game":
screen.fill("#2f3542")
map_draw()
char.draw()
for enemy in enemies:
enemy.draw()
screen.draw.text(f"HP: {char.health}", (10, 10), fontsize=24, color="white")
screen.draw.text(f"AP: {char.attack}", (10, 40), fontsize=24, color="white")
elif mode == "end":
screen.fill("black")
if win == 1:
screen.draw.text("Победа!", center=(WIDTH/2, HEIGHT/2), fontsize=60, color="green")
else:
screen.draw.text("Поражение!", center=(WIDTH/2, HEIGHT/2), fontsize=60, color="red")
# === Движение игрока и бой ===
def on_key_down(key):
if mode != "game":
return
old_x = char.x
old_y = char.y
if keyboard.right and char.x + cell.width < WIDTH - cell.width:
char.x += cell.width
char.image = 'stand'
elif keyboard.left and char.x - cell.width > cell.width:
char.x -= cell.width
char.image = 'left'
elif keyboard.down and char.y + cell.height < HEIGHT - cell.height * 2:
char.y += cell.height
elif keyboard.up and char.y - cell.height > cell.height:
char.y -= cell.height
enemy_index = char.collidelist(enemies)
if enemy_index != -1:
char.x = old_x
char.y = old_y
enemy = enemies[enemy_index]
enemy.health -= char.attack
char.health -= enemy.attack
if enemy.health <= 0:
enemies.pop(enemy_index)
# === Проверка победы/поражения и перехода ===
def victory():
global mode, win, level
if char.health <= 0:
mode = "end"
win = -1
elif len(enemies) == 0:
level += 1
if level < len(levels):
load_level()
else:
mode = "end"
win = 1
# === Обновление игры ===
def update():
if mode == "game":
victory()
pgzrun.go()