I was trying to build a game on Pygame. Now the jump animation that I added gets over in like 0.01 seconds. What could I do to make it last for a second at least ?
the player class -
class player_level1(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.move_frame = 0
self.image = pygame.image.load("Player_Sprite_R.png")
self.pos = vec(int(width/2),286-53)
self.vel = vec(0,40)
self.acc = vec(0,8)
self.jumping = False
self.rect = self.image.get_rect()
def move(self):
run_ani_R = [pygame.image.load("Player_Sprite_R.png"),
pygame.image.load("Player_Sprite2_R.png"),
pygame.image.load("Player_Sprite3_R.png"),
pygame.image.load("Player_Sprite4_R.png"),
pygame.image.load("Player_Sprite5_R.png"),
pygame.image.load("Player_Sprite6_R.png"),
pygame.image.load("Player_Sprite_R.png")
]
self.move_frame += 1
if self.move_frame > 6 :
self.move_frame = 0
self.image = run_ani_R[self.move_frame]
def render(self):
print(self.pos)
self.rect.bottomleft = self.pos
displaysurface.blit(self.image,self.pos)
def jump(self):
self.rect.y += 1
print("jump")
#check to see if player is in contact with the ground
hits = pygame.sprite.spritecollide(self,floor_group,False)
self.rect.y -= 1
#If touching the ground, and not currently jumping -> jump
if hits and not self.jumping:
print("Jump exec")
self.jumping = True
self.vel.y = 12
displaysurface.blit(self.image,self.rect)
self.jumping = False
def gravity(self):
hits = pygame.sprite.spritecollide(player,floor_group,False)
if self.vel.y > 0 :
if hits :
lowest = hits[0]
if self.pos.y < lowest.rect.bottom :
self.pos.y = lowest.rect.top + 1
self.vel.y = 0
self.jumping = False
#lines to incorporate platformer genre
the game loop
while True:
if Levels.level == 1:
player.gravity()
.....
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
player.jumping == True
player.jump()