Jun-13-2020, 06:18 PM
I am trying to get an infinite generating 2D world algorithm to work.
This algorithm looks like something that should work, but I have coded it and it doesn't. I get a weird bug that I'll show in the following video:
https://www.reddit.com/r/pygame/comments...algorithm/
Link to my code
https://github.com/Kolterdyx/VoidShips
I found out the bug just happened on the negative side of the plane, so I have restricted the player movement to the positive side
- I first get an area that gives me 36 chunk positions around the player
- Then I check if any of those positions has a generated chunk
- If not, I generate it, and add it to a dictionary with the position as key, and a chain of characters as content. (I represent each tile as a character)
- Then I load the chunks in the area. I iterate through the content of each chunk in the area. Then I add that chunk to the loaded chunks list
- I create a 'bundle' with one tuple for each tile, wich has (tile, x, y) where tile is a char, and x and y are the position of said tile.
- I iterate through each bundle to generate each chunk around the player.
- Then I iterate through the loaded chunks list and look for those that are not in the area around the player. Each tile stores in its atributes the chunk they are in, so I look for all tiles that are in said chunks, and kill them.
This algorithm looks like something that should work, but I have coded it and it doesn't. I get a weird bug that I'll show in the following video:
https://www.reddit.com/r/pygame/comments...algorithm/
Link to my code
https://github.com/Kolterdyx/VoidShips
I found out the bug just happened on the negative side of the plane, so I have restricted the player movement to the positive side