python - Making Sprite Jump in Pygame -


making basic game , im trying character jump when space pressed

i have simulated gravity pulls down when space released

but when push space down goes , doesnt stop

i want goo 1 second go down

here key press handling code snippet:

key = pygame.key.get_pressed() if key[pygame.k_left]:     self.rect.x -= 30 if key[pygame.k_right]:     self.rect.x += 30 if key[pygame.k_space]:     self.rect.y += -20 if key[pygame.k_space] == false:     self.rect.y += 20 

like said code makes sprite go when space pressed , down when space released when pressed want wait 1 second make sprite go down if space bar still down

please help!!

thank you

there 2 things should introduce. states , velocity.

in order make player fall, want him jump when on ground. define 2 states. standing , jumping. pressing space make player jump if state standing.

to make player fall ball, introduce velocity. when player on ground, have velocity set 0. when press space, change velocity 100. in each loop, if player state jumping, reduce velocity earth's gravity. last thing check, when player reaches ground level, should set velocity 0 , player state standing.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -