0

我正在尝试使用 pyglet 制作横向卷轴游戏,并且我已经设法绘制了背景、角色和一些地形。(我对 GUI 的东西很陌生)问题是当玩家移动角色时,地形是要自己生成的(就像像泰拉瑞亚这样的游戏)但我找不到不制作 1000 个副本的方法精灵。你对我将如何处理这件事有任何想法吗?如果我没有说清楚,请随时提出问题:)

编辑:到目前为止,我一直在为每个地形创建一个变量,如下所示:

ground_1 = pyglet.sprite.Sprite(ground1, x=-100, y=200, batch = terrain)
ground = pyglet.sprite.Sprite(ground1, 0, y=200, batch = terrain)
ground2 = pyglet.sprite.Sprite(ground1, x=100, y = 200, batch = terrain)
ground3 = pyglet.sprite.Sprite(ground1, x=200, y = 200, batch = terrain)
ground4 = pyglet.sprite.Sprite(ground1, x=300, y = 200, batch = terrain)
ground5 = pyglet.sprite.Sprite(ground1, x=400, y = 200, batch = terrain)
ground6 = pyglet.sprite.Sprite(ground1, x=500, y = 200, batch = terrain)
ground7 = pyglet.sprite.Sprite(ground1, x=600, y = 200, batch = terrain)
ground8 = pyglet.sprite.Sprite(ground1, x=700, y = 200, batch = terrain)
ground9 = pyglet.sprite.Sprite(ground1, x=800, y = 200, batch = terrain)
ground10 = pyglet.sprite.Sprite(ground1, x=900, y = 200, batch = terrain)

我还创建了一个类来查看块上是否有一棵树:

class block():
    """ block """
    def __init__(self,image,tree,grass,destroyed):
        self.image = image
        self.tree = tree
        self.grass = grass
        self.destroyed = destroyed

newGround1 = block(newGround,tree[treeR],grass[grassR],destroyed[destroyedR])

groundO = block(ground_1,False,False,False)
groundO1 = block(ground,True,False,False)
groundO2 = block(ground2,False,False,False)
groundO3 = block(ground3,False,False,False)
groundO4 = block(ground4,False,False,False)
groundO5 = block(ground5,False,False,False)
groundO6 = block(ground6,False,False,False)
groundO7 = block(ground7,False,False,False)
groundO8 = block(ground8,False,False,False)
groundO9 = block(ground9,False,False,False)
groundO10 = block(ground10,False,False,False)

但我想知道我是否必须为我想要的所有地形创建ground2、ground3、ground4 ...,或者是否有更简单的生成方式(可能无限制)

4

1 回答 1

0

听起来您应该能够将所有这些ground对象存储在列表中,而不是存储它们。

#pseudocode
grounds_list = []
for x in range(0, 100000, 100):
   ground = pyglet.sprite.Sprite(ground1, x, y=200, batch = terrain) #x gets passed in here
   groundO1 = block(ground,True,False,False)
   grounds_list.append(ground) #store the objects you want to keep

因此,当您需要查找更多内容时,您会遍历这个 grounds_list。

于 2013-09-22T21:25:58.250 回答