小编Nil*_*lus的帖子

如何在 pygame 平台游戏中重写碰撞逻辑?

我似乎不知道如何为我的平台游戏编写碰撞逻辑。

项目文件:https://github.com/1NilusNilus/Pygame-Platformer

玩家移动代码:

def move(self):
        print(self.POS)

        if self.POS[1] > SCREEN_SIZE[1]:
            self.POS[1] = SCREEN_SIZE[1] - self.SIZE[1]

        self.RECT.x = self.POS[0]
        self.RECT.y = self.POS[1]

        self.VEL[0] = 0
        if self.DIR["left"]:
            self.VEL[0] = -5

        if self.DIR["right"]:
            self.VEL[0] = 5

        self.POS[0] += self.VEL[0]

        

        self.VEL[1] += self.GRAVITY

Run Code Online (Sandbox Code Playgroud)

瓷砖碰撞测试代码:

def testCollision(self, rect):

        self.RECT.x = self.POS[0]
        self.RECT.y = self.POS[1]

        for tile in self.TILES:
            if rect.colliderect(tile):
                self.hitlist.append(self.RECT)
        return self.hitlist
Run Code Online (Sandbox Code Playgroud)

python pygame

-2
推荐指数
1
解决办法
223
查看次数

标签 统计

pygame ×1

python ×1