如何使用pygame定位对象



到目前为止,我正在做一个迷宫游戏。我有以下代码,它可以读取文本文件的位置和必须放置的障碍物,但我对pygame没有足够的知识来在屏幕上显示它们。

def set_walls(self, walls):
walls_length = len(walls)
for i in range(walls_length):
# First case is row...
if "row" in walls[i]:
row_index = int(re.sub("[^0-9]", "", walls[i]))
print(row_index)
column_indexes = walls[i+1].split()
print(column_indexes)
for index in column_indexes:
self.wall_vertical[row_index - 1][int(index) - 1] = 1
# Second case is column...
elif "column" in walls[i]:
column_index = int(re.sub("[^0-9]", "", walls[i]))
row_indexes = walls[i + 1].split()
for index in row_indexes:
self.walls_horizontal[int(index) - 1][column_index - 1] = 1

如果你有每面墙的索引,你可以把它们乘以墙的宽度和高度,这应该会把所有的墙都放在正确的位置。我忍不住多看看你是如何没有提供文本文件样本的。

x = x_index * wall_width
y = y_index * wall_height

最新更新