理解这个for循环滚动迷宫游戏

时间:2016-05-31 02:24:59

标签: python for-loop pygame

所以我做了一个简单的“在迷宫中导航你的立方体”类型的游戏。看看youtube周围,我发现了一些可以用来轻松布局迷宫的代码。

level1_map = [[1,0,0,0,0,0,0,0,0,0,0,0],
          [1,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,1,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0],
          [0,0,0,0,0,0,0,0,0,0,0,0]]

所以我的窗口大小设置为600x800,因为每个块将是50x50,有12行和18列。

class Level():

def __init__(self,map):
    self.map = map
    self.blocklist = []

def createMap(self):
    for y in range(0,len(self.map)):
        for x in range(0,len(self.map[y])):
            if self.map[y][x] == 1:
                self.blocklist.append(Block(x*12,y*18))

^我的等级班。顺便说一句,我有一个Block类。 好的主要问题是我不理解前面的代码块(for循环)。它工作得很好,但我想让我的游戏能够滚动并跟随立方体,所以我需要使布局延伸到我的600x800窗口之外。 for循环似乎不适用于我的窗口大小,但是当我尝试向我的布局添加更多行/列时,它不会在窗口之外添加块。如果有人可以向我解释for循环并为我的问题提出建议,那将会很有帮助。提前致谢

0 个答案:

没有答案