如何让玩家在pygam中的多个平台上登陆

2024-04-26 22:47:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在屏幕上制作多个平台(块),玩家可以在上面跳跃和降落。当我只保留一个方块时,玩家可以在上面跳跃并轻松落地,但当我创建其他平台时,玩家可以跳跃,它会被方块击中并在地图下方移动,但如果我尝试跳过其他平台,它会轻松落地

到目前为止我试过的

       # Checking Collision of Platform and Hero
    self.obstacleHit_or_not(self.hero, self.platform, 460)
    self.obstacleHit_or_not(self.hero, self.platform1, 460)

    # This function works for Blocks only
def obstacleHit_or_not(self, hero, platform, position):
    hit = pygame.sprite.collide_rect(hero, platform)

    if hit:
        #print("ITS HITTING")
        hero.y = position

    elif self.hero.y == position:
        #print("HITTING INSIDE OF 450")
        while True:
            hero.y += 5
            if hero.y >= 625:
                break

有人能帮我解决这个问题吗?我只想让我的玩家在我在屏幕上创建的每个方块上着陆。提前谢谢


Tags: orselfif屏幕玩家notposition平台