#๐Ÿ”’ Can someone help me with the jump code for my 2D game?

9 messages ยท Page 1 of 1 (latest)

burnt bane
#

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

sweet juncoBOT
#

@burnt bane

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

forest iris
#

!code

sweet juncoBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

last shore
#

Can you show more of your code, a pygame game usually requires an infinite loop

#

something like (this is pseudo code)

while True:
  clock tick
  handle input
  update game state
  update screen
#

plus some lines to open files, init pygame etc.

sweet juncoBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.