Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

How to make a world infinite in pygame??

A topic by lemoncleaver created Jan 16, 2025 Views: 374 Replies: 7
Viewing posts 1 to 7

So, here is my question, I have made a game in pygame, that I am yet to share with the itch community, but my problem is that, when I try to implement chunking so that lists can fill with world data, I mess everything up, what is want to do is, to implement an algorithm so that world generation in my game can be working properly, So can anyone help me out over here, I want legit pygame advice.

Please help as soon as you ca

n

(+1)

I hope this message finds you well. I am very interested in your game and want to know its content and objectives. Additionally, I would like to know if there are opportunities to participate as a playtester or contribute as a designer.

Hello YubTeam , hope this reply finds you well, yes I would require a suitable playtester to gain proper feedback.

(+1)

Pygame dev here, I wish I could give you a straight answer, but I've never done it, my first thought was to look through github and see how other people are doing it, and theres a lot of results for "pygame infinite" Repository search results, as well as random terrain generation here: Magoninho/terrain-generation-test-pygame: Just for testing a random 2D terrain generation system i've made (not with perlin noise)

I wish I had a better answer for you, but if I was you I'd be looking through github pygame projects, combing through their code to see how other people are handling infinite worlds, generation etc.

My first thought was importing random and having python pick numbers to represent different possibilities for what to generate, something like:

If we're talking a game like minecraft something like this could implemented so that when the player steps off screen, import random and choose  a number between 1 and 4 with 1 being sand biome, 2 swamp, 3 mountain, 4 beach/ocean, and handle it like that. In addition to using a system like that for biomes you could have random make a choice to decide if there will be enemies on that chunk, treasure, nothing at all, etc etc.

Sorry for not really knowing how to help, but hopefully between some brainstorming and github repositories you can figure out a good way to implement your generator.

(1 edit) (+1)

What Frontline Studios said is basically correct, although in practice it’s much more involved. Because none of us know what you mean by “messing it up”, only vague advice can be given.

Firstly, for performance reasons you want to divide your world into chunks of some size. It’s usually a power-of-two but it doesn’t matter too much. You should keep only chunks closest to the player loaded. That means when a player comes close enough to an unloaded chunk, that is when you load it. Same thing for the opposite.

The way you generate your chunk usually relies on a whole bunch of noise functions that’s mixed together, but you should be able to get something recognizable with a single Perlin noise. After that, you come up with the logic yourself. Water is always generated at a height level <= 0; if you generate a dirt block and there’s air above it, then it’s actually grass, etc.

Structures that spawn across chunk boundaries are a different topic.

(+1)

Thank you for the help.