Загрузка данных
import pgzrun
import random
cell = Actor('border') # Стена
cell1 = Actor('floor') # Пол
cell2 = Actor("crack") # Трещина
cell3 = Actor("bones") # Кости
cell4 = Actor("lava") # лава
cell5 = Actor("777") # лава2
cell6 = Actor("mana") # ф лава
cell7 = Actor("poison") #зелень
cell8 = Actor("yellow") # жолтый
cell9 =Actor("blue")
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, 7, 1, 7, 1, 7, 1, 7, 0],
[0, 1, 7, 1, 7, 1, 7, 1, 0],
[0, 7, 1, 7, 1, 7, 1, 7, 0],
[0, 1, 7, 1, 7, 1, 7, 1, 0],
[0, 7, 1, 7, 1, 7, 1, 7, 0],
[0, 1, 6, 1, 7, 1, 6, 1, 0],
[0, 6, 1, 6, 1, 6, 1, 6, 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, 0, 0, 0, 1, 0, 0, 0, 0]
# [0, 0, 0, 0, 1, 0, 0, 0, 0]
# [0, 0, 0, 0, 1, 0, 0, 0, 0]
# [0, 0, 0, 0, 1, 0, 0, 0, 0]
# [0, 0, 0, 0, 1, 0, 0, 0, 0]
# [0, 0, 0, 0, 1, 0, 0, 0, 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, 6, 1, 7, 1, 6, 1, 0],
[0, 6, 1, 7, 1, 6, 1, 7, 0],
[0, 1, 6, 1, 6, 1, 6, 1, 0],
[0, 9, 1, 6, 1, 6, 1, 9, 0],
[0, 1, 9, 1, 9, 1, 8, 1, 0],
[0, 9, 1, 9, 1, 8, 1, 9, 0],
[0, 1, 8, 1, 8, 1, 9, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[-1, -1, -1, -1, -1, -1, -1, -1, -1]
]
level3_map = [
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 5, 4, 1, 4, 1, 4, 5, 0],
[0, 5, 1, 4, 1, 4, 1, 5, 0],
[0, 5, 4, 1, 4, 1, 4, 5, 0],
[0, 5, 1, 4, 1, 4, 1, 5, 0],
[0, 5, 4, 1, 4, 1, 4, 5, 0],
[0, 5, 1, 4, 1, 4, 1, 5, 0],
[0, 5, 4, 1, 4, 1, 4, 5, 0],
[0, 5, 1, 4, 1, 4, 1, 5, 0],
[-1, -1, -1, -1, -1, -1, -1, -1, -1,]
]
levels = [level1_map, level2_map, level3_map, ]
level = 0
my_map = levels[level]
char = Actor('stand')
char.left = cell.width
char.top = cell.height
char.health = 1
char.attack = 1000
enemies = []
lava = []
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()
elif my_map[i][j] == 4:
cell4.left, cell4.top = x, y
cell4.draw()
elif my_map[i][j] == 5:
cell5.left, cell5.top = x, y
cell5.draw()
elif my_map[i][j] ==6:
cell6.left, cell6.top = x, y
cell6.draw()
elif my_map[i][j] ==7:
cell7.left, cell7.top = x, y
cell7.draw()
elif my_map[i][j] ==8:
cell8.left, cell8.top = x, y
cell8.draw()
elif my_map[i][j] ==9:
cell9.left, cell9.top = x, y
cell9.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):
global lava
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 = 'right'
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
char.image = 'forward'
elif keyboard.up and char.y - cell.height > cell.height:
char.y -= cell.height
char.image = 'back'
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)
boss_index = char.collidelist(enemies)
if boss_index != -1:
char.x = old_x
char.y = old_y
boss = enemies[boss_index]
boss.health -= char.attack
char.health -= boss.attack
if boss.health <=0:
enemies.pop(boss_index)
lava_index = char.collidelist(lava)
if lava_index != -1:
char.x = old_x
char.y = old_y
lava = enemies[lava_index]
lava.health -= char.attack
char.health -= lava.attack
if lava.health <=0:
enemies.pop(lava_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()