嗨我正在使用pygame试图制作一个平台游戏,但有些东西会让玩家在跳跃时突然下降,所以玩家会稍微跳一下然后直接跌倒。 以下是负责跳转的代码:
def update(self):
self.speedx = 0
self.speedy = 0
self.gravity = 3
self.onGround = True
keystate = pygame.key.get_pressed()
if self.rect.y <= HEIGHT - 50:
self.speedy += self.gravity
self.onGround = False
if self.rect.y >= HEIGHT - 50:
self.speedy = 0
self.onGround = True
if keystate[pygame.K_LEFT]:
self.speedx = -5
if keystate[pygame.K_RIGHT]:
self.speedx = 5
if keystate[pygame.K_UP]:
self.jump()
self.rect.x += self.speedx
self.rect.y += self.speedy
def jump(self):
if self.onGround == False:
return
self.speedy = -10