I am trying to implement jumping into a 2-D fighting game by using velocity. The player can jump when "w" is pressed however each time when the object lands, it lands a bit higher each time. I want the object to land back in the same position as where it initially jumped from. Any ideas?
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