Помогите с созданием карты Pygame

Мне необходимо создание карты через список, но я ничего не могу найти. Сейчас я создаю карты вручную и это не очень приятно.

Вот код:


from fonts import *


pygame.init()
press_e = False
screen = pygame.display.set_mode((1000, 800))
clock = pygame.time.Clock()
x, y = 100, 510

npc_talk = 0

main = True

while main:
    clock.tick(90)
    keys = pygame.key.get_pressed()
    screen.fill((0, 0, 0))

    w1 = pygame.Rect((400, 0, 200, 300))
    w2 = pygame.Rect((400, 300, 200, 300))
    w3 = pygame.Rect((800, 200, 200, 800))
    npc1_r = pygame.Rect((125, 125, 150, 150))
    npc1 = pygame.Rect((150, 150, 100, 100))

    player_rect = pygame.Rect((x, y, 100, 100))

    pl = pygame.Rect((x - 10, y, 10, 100))
    pr = pygame.Rect((x + 100, y, 10, 100))
    pu = pygame.Rect((x, y - 10, 100, 10))
    pd = pygame.Rect((x, y + 100, 100, 10))

    # pygame.draw.rect(screen, (255, 0, 0), pu)
    # pygame.draw.rect(screen, (255, 0, 0), pd)
    # pygame.draw.rect(screen, (255, 0, 0), pl)
    # pygame.draw.rect(screen, (255, 0, 0), pr)
    # pygame.draw.rect(screen, (0, 255, 255), npc1_r)

    pygame.draw.rect(screen, (0, 255, 0), player_rect)
    # pygame.draw.rect(screen, (255, 0, 0), w3)
    #
    # pygame.draw.rect(screen, (255, 0, 0), w1)
    # pygame.draw.rect(screen, (255, 0, 0), w2)

    pygame.draw.rect(screen, (0, 0, 255), npc1)

    pwcu = (not pu.colliderect(w1) and not pu.colliderect(w2) and not pu.colliderect(w3))
    pwcd = (not pd.colliderect(w1) and not pd.colliderect(w2) and not pd.colliderect(w3))
    pwcl = (not pl.colliderect(w1) and not pl.colliderect(w2) and not pl.colliderect(w3))
    pwcr = (not pr.colliderect(w1) and not pr.colliderect(w2) and not pr.colliderect(w3))

    alls = pr.colliderect(npc1_r) or pu.colliderect(npc1_r) or pl.colliderect(npc1_r) or pd.colliderect(npc1_r)

    if npc_talk == 0:
        if keys[pygame.K_w]:
            if pu.colliderect(npc1): # y >= 25 and pwcu and not
                y2 = y + 10
                y = y - 10
        if keys[pygame.K_s]:
            if pd.colliderect(npc1): # y <= 675 and pwcd and not
                y2 = y - 10
                y = y + 10
        if keys[pygame.K_a]:
            if not pl.colliderect(npc1): # x >= 25 and pwcl and
                x2 = x + 10
                x = x - 10
                if x <= 25:
                    x = 975
        if keys[pygame.K_d]:
            if not pr.colliderect(npc1): # x <= 875 and pwcr and
                x2 = x - 10
                x = x + 10

    if npc_talk == 1:
        if alls:
            pygame.draw.rect(screen, (255, 0, 255), (0, 400, 1000, 400))
            pygame.draw.rect(screen, (0, 0, 255), (50, 420, 100, 100))
            screen.blit(npc_name1, (200, 420))
            screen.blit(npc_text, (200, 470))
            screen.blit(your_name, (200, 530))
        if not player_rect.colliderect(npc1_r):
            npc_talk = 0
    if player_rect.colliderect(npc1_r) and npc_talk == 0:
        screen.blit(talk, (x-140, y+20))

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            main = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_e:
                npc_talk = not npc_talk
            if event.key == pygame.K_e:
                print(x, y)
                x, y = 100, 510


    pygame.draw.rect(screen, (255, 0, 0), (0, 0, 1000, 20))
    pygame.draw.rect(screen, (255, 0, 0), (0, 780, 1000, 20))
    pygame.draw.rect(screen, (255, 0, 0), (0, 0, 20, 800))
    pygame.draw.rect(screen, (255, 0, 0), (980, 0, 20, 800))

    pygame.display.update()

Ответы (0 шт):