雪碧不停地上下摇晃

2024-09-28 22:40:27 发布

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

我在我的游戏中加入了重力,它不断地拉到我的玩家身上。然而,当我的球员站在一个平台上,他不断地上下晃动。我怎样才能解决这个问题?你知道吗

PLAYER_ACC = 0.65
PLAYER_FRICTION = -0.12
PLAYER_GRAVITY = 0.

class Player(pg.sprite.Sprite):
    def __init__(self, game, x, y):
        self.pos = vec(WIDTH / 2, HEIGHT / 2)
        self.vel = vec(0, 0)
        self.acc = vec(0, 0

    def collision_with_walls(self):
        collision = pg.sprite.spritecollide(self, self.game.walls, False)
        if collision:
            self.pos.y = collision[0].rect.top
            self.vel.y = 0

    def update(self):
        self.acc.x += self.vel.x * PLAYER_FRICTION
        self.vel += self.acc
        self.pos += self.vel + 0.5 * self.acc
        self.collision_with_walls()

        self.rect.midbottom = self.pos

感谢所有/任何帮助!你知道吗


Tags: posrectselfgamedefwithaccpg