I decided to start learning programming and decided to make a 2D game in Python to get used to Python. My idea is to make a game that mixes the obstacles of Celeste and the jumping system of Flappy Bird. However, I really don't know how to make Python execute an action for a certain time and then stop and cool down before it can execute again. My idea is to make the player, after pressing the jump button, go up for a while and then stop going up, and have to wait to jump again. I had tested some codes and I will leave the code I used below the text. If someone could point out my error and teach me or send me the code of how to do it, I would really appreciate it.
#variable for when the key is pressed
keys = pygame.key.get_pressed()
loop = True
the jump button command I made
if keys[pygame.K_w]:
move_y -= jump
the code I tried to use to set the jump limit while loop:
pygame.time.get_ticks()
tick = 0
duration_of_jump = 300
if tick - duration_of_jump > duration_of_jump:
loop = False