我编写了以下代码来使用tiles渲染地图,它在文件中循环并将字母转换为tiles(矩形)
currtile_x = 0
currtile_y = 0
singlerun = 1
if singlerun == 1:
singlerun = 0
with open('townhall.map', 'r') as f:
for line in f:
for character in line:
if character == "\n":
currtile_y += 10
else:
if character == "x":
pygame.draw.rect(screen, (1,2,3), (currtile_x, currtile_y, 10, 10), 0)
currtile_x += 10
else:
if character == "a":
pygame.draw.rect(screen, (0,255,255), (currtile_x, currtile_y, 10, 10), 0)
currtile_x += 10
这是你的名字市政厅.map文件:
xxxxx
xaaax
xaaax
xaaax
xxxxx
当向代码中添加事件循环代码时,代码运行良好。既然你还没有发布整个程序,我所能做的就是发布一个包含你代码的工作程序。你知道吗
相关问题 更多 >
编程相关推荐