Привет, поэтому я создаю программу, которая создает случайную карту, используя созданные мной изображения, а затем позволяет пользователю перемещать символ по экрану, я пытаюсь проверить его, но продолжаю получать эту ошибку.
Traceback (последний вызов был последним): файл "D: \ the maker.py карты", строка 89, в display.blit (плитки [dmap [строка] [столбец]], (столбец tileSize,row tileSize)) KeyError: Surface (40x40x32 SW)
Если вы посмотрите на мой код и покажете, как его исправить, я буду очень благодарен.Спасибо
import pygame
import sys
from pygame.locals import *
import random
MUD = 0
GRASS = 1
WATER = 2
MOUNTAIN = 3
pygame.display.set_caption('Dungeons and Dragons')
pygame.display.set_icon (pygame.image.load ('mountain.png'))
tiles = { #Creates a dictionary that links each picture to the type of ground
MUD : pygame.image.load ('mud.png'),
GRASS : pygame.image.load ('grass.png'),
WATER : pygame.image.load ('water.png'),
MOUNTAIN : pygame.image.load ('mountain.png')
}
tileSize = 20
mapWidth = 30
mapHeight = 20
treasure = pygame.image.load ('treasure.png')
key = pygame.image.load ('key.png')
player = pygame.image.load ('player.png')
pposition = [0,0] # sets players start position
dmap = [[random.choice(tiles) for w in range(mapWidth)] for h in range (mapHeight)]
pygame.init()
display = pygame.display.set_mode ((mapWidth*tileSize, mapHeight*tileSize))
while True:#if the user quits the game closes
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
elif event.type == KEYDOWN:
if event.key == K_RIGHT and pposition[0] < mapWidth -1:
pposition[0] += 1
num = random.randint (1-100) # chooses a random number between 1 and 100
if num <= 10:
health -10 #if num is less than 10 than an enemy attacks and user loses health
if health <= 0: # if the user loses all health then game is over
pygame.quit()
sys.exit()
if event.key == K_LEFT and pposition[0] > 0:
pposition[0] -=1
num = random.randint (1-100)
if num <= 10:
health -10
if health <= 0:
pygame.quit()
sys.exit()
if event.key == K_UP and pposition[1] > 0:
pposition[1] -=1
num = random.randint (1-100)
if num <= 10:
health -10
if health <= 0:
pygame.quit()
sys.exit()
if event.key == K_DOWN and pposition[1] < mapHeight -1:
pposition[1] +=1
num = random.randint (1-100)
if num <= 10:
health -10
if health <= 0:
pygame.quit()
sys.exit()
for row in range (mapHeight):
for column in range(mapWidth):
display.blit(tiles[dmap[row][column]], (column*tileSize,row*tileSize))
display.blit(player,(pposition[0]*tileSize,pposition[1]*tileSize))
pygame.display.update()