皮格姆用速度跳跃

2024-09-24 02:26:32 发布

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

我试图实现跳进一个2-D战斗游戏使用速度。当按下“w”时,玩家可以跳跃,但是每次物体落地时,它落地的高度都会更高。我想让物体回到它最初跳下的位置。有什么想法吗?你知道吗

velocity = list([-10, -9.5, -9, -8.5, -8, -7.5, -7, -6.5, -6, -5.5, -5, -4.5, -4, -3.5, -3, -2.5, -2, -1.5, -1, -0.5 , 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, 10])


class Player():

   def __init__(self):
       velocity_index = 0

   def jump(self):
       self.image = self.jump_list[self.pos_jump]
       self.rect.y += velocity[self.velocity_index]
       if self.velocity_index ==0:
          self.pos_jump += 1
       elif self.velocity_index==40:
          self.pos_jump += 1
          self.image = self.jump_list[self.pos_jump]
       if self.pos_jump == self.ani_max_jump:
          self.pos_jump = 0
       if self.velocity_index!=40:
          self.velocity_index += 1
       elif self.velocity_index==40:
          self.velocity_index =0
          self.jumping = False 

Tags: posimageself游戏indexifdef玩家