我正在制作一款平台不断变化的平台游戏。我创建了一个带有参数的类,您可以在其中传递事物以创建移动平台。但是,对于其中一个,我可以上下移动,但没有。有人可以解决这个问题吗?第二个平台change_y(上下移动速度)在列表中的Level01类中。注意:此问题已被编辑,因此可能会有随机注释。
class MovingPlatform(Platform):
def __init__(self, sprite_sheet_data, change_x, change_y, x, y,
boundary_top, boundary_bottom, boundary_left,
boundary_right):
super().__init__(sprite_sheet_data)
self.change_x = change_x
self.change_y = change_y
self.rect.x = x
self.rect.y = y
self.boundary_top = boundary_top
self.boundary_bottom = boundary_bottom
self.boundary_left = boundary_left
self.boundary_right = boundary_right
self.player = None
self.level = None
等级(对象):
def __init__(self, player):
self.platform_list = None
self.platform_list = pygame.sprite.Group()
self.player = player
def update(self):
self.platform_list.update()
def draw(self, screen):
self.platform_list.draw(screen)
Level01(Level)类:
def __init__(self, player):
Level.__init__(self, player)
level_moving_blocks =
[[MovingPlatform(STONE_PLATFORM_MIDDLE, 1, 0, 1350, 280, 0,
0, 1350, 1600)],
[MovingPlatform(STONE_PLATFORM_MIDDLE, 0, 1, 2000, 400,
300, 500, 0, 0)]
]
for block in level_moving_blocks:
block.player = self.player
block.level = self
self.platform_list.add(block)