Загрузка данных


import pgzrun
from random import randint

size_w = 7
size_h = 7

cell = Actor("border")
cell2 = Actor("bones")
cell3 = Actor("crack")
cell4 = Actor("floor")


player = Actor("forward", topleft = (cell.height * 3, cell.width * 3))
player.health = 100
player.damage = 20
enemies = []




def spawn_enemies():
    for i in range(3):
        x = randint(1,5) * cell.width
        y = randint(1,5) * cell.height
        enemy = Actor("enemy", topleft = (x, y))
        enemy.hp = randint(5, 20)
        enemy.damage = randint(1, 3)
        enemies.append(enemy)
spawn_enemies()


WIDTH = cell.width * size_w
HEIGHT = cell.height * size_h
TITLE = "Рога ликииииииыиррыффы"

map = [
    [0,0,0,0,0,0,0],
    [0,1,2,1,2,2,0],
    [0,1,1,3,3,2,0],
    [0,1,2,2,3,2,0],
    [0,1,2,2,2,2,0],
    [0,3,2,3,1,3,0],
    [0,0,0,0,0,0,0],
]
def map_draw():
    for i in range(len(map)):
        for k in range(len(map[i])):
            x = k * cell.width
            y = i * cell.height

            if map[i][k] == 0:
                cell.topleft = (x,y)
                cell.draw()
            elif map[i][k] == 1:
                cell2.topleft = (x,y)
                cell2.draw()
            elif map[i][k] == 2:
                cell3.topleft = (x,y)
                cell3.draw()
            elif map[i][k] == 3:
                cell4.topleft = (x,y)
                cell4.draw()

def draw():
    map_draw()
    player.draw()
    for i in enemies:
        i.draw()
        screen.draw.text(f"Здоровье врага: {i.hp}", center=(i.x, i.y - 55), color="red")
    screen.draw.text(f"Здоровье: {player.health}", (15, 15), color="white")

def update():
    pass

def on_key_down():
    old_x = player.x
    old_y = player.y

    if keyboard.d and player.x < WIDTH - player.width - cell.width or keyboard.right and player.x < WIDTH - player.width - cell.width:
        player.x += cell.width
        player.image = "right"

    if keyboard.a and player.x > player.width + cell.width or keyboard.left and player.x > player.width + cell.width:
        player.x -= cell.width
        player.image = "left"

    if (keyboard.w or keyboard.up) and player.y > player.height + cell.height:
        player.y -= cell.height
        player.image = "back"

    if (keyboard.s or keyboard.down) and player.y < HEIGHT - player.height - cell.height:
        player.y += cell.height
        player.image = "forward"

    enemy_index = player.collidelist(enemies)
    if enemy_index != -1:
        player.x = old_x
        player.y = old_y
        enemy = enemies[enemy_index]
        enemy.hp -= player.damage
        player.health -= enemy.damage
        if enemy.hp <= 0:
            enemies.pop(enemy_index)

pgzrun.go()