#๐Ÿ”’ Need help randomizing pipes for a flappy bird game.

20 messages ยท Page 1 of 1 (latest)

past halo
#

So, i started a new project with pygame : recreate flappy bird. My main goals for this project are trying to get better at using classes in my code, and figuring out how to setup a scrolling in a game.
The thing is i am kind of stuck when it comes to generating pipes randomly, but still controlling the RNG with a max gap value between each pipes for example. if you guys could share hints on how to do this, it would help a lot. Let me know if you need code samples.

torpid axleBOT
#

@past halo

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.

wicked rover
#

You can do change of height

#

like, between -100px to +100px

#

and then only take those who is inbound

#

and pick the change of height from the filtered range

dense viper
#

You could generate one random pipe first, then make the second pipe based off of that to keep the gap at a range you want

midnight obsidian
#

Generate randomly the height of the bottom pipe within a range
Generate randomly the gap within a range
Generate the height of the top pip by using the height of the bottom, the gap and the heigt of the screen

past halo
#

So i do two different classes : one for bottom pipe and one for the upper one that follows the bottom, right ??

midnight obsidian
#

For example, let's say you want all pipes to be at least 100 height, and the gap to be between 200 - 300 pixels
Assuming the height of the screen is 1000
(you can change all these values for your case)

bottom_height = randint(100, 600) # replace 600 by 1000 - min_height - max_gap
gap = randint(200, 300) # or simply gap = 250
top_height = 1000 - bottoom_height - gap

midnight obsidian
#

Then you either have 2 classes or one class with a flag specifying top or bottom

wicked rover
#

You need random between the top and bottom? I thought it was constant

midnight obsidian
#

I think in the original game it's constant

past halo
midnight obsidian
#

it doesn't matter much for the discussion anyway

#

It will probably be easier to have 2 classes

past halo
torpid axleBOT
#
Python help channel closed using Discord native close action

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.