How do I make a Factorio-like?

0 favourites
  • 3 posts
From the Asset Store
Push the Box Puzzle Game likes Sokoban made with Illustrator
  • Hi everyone!

    I'm trying to make a simple automation factorio-like game, however i'm facing some issues.

    In order to generate the map I've started with the "Procedural Terrain Generation" from the example browser, and that's very nice, the chunk system works nicely when seen from above too, so chunks of terrains are saved in a JSON and loaded when needed, perfect.

    So I need to destroy and recreate sprites while the player moves around in order to save up on memory, which i did, it works, awesome BUT I need the factories, furnaces, etc... to keep working even when destroyed!

    So I thought, well I will put every structures in an array that will control everything from backstage (factory production, conveyor belts, etc...) and will be refreshed every tick or so.

    But that means that even with a map of 100*100, and with an array depth of 50 in order to register data from every square, that would already be 500.000 array cells to be read every ticks, no way that wouldn't overload the CPU.

    Plus the size of that array is currently limited, I don't know how to resize it and make it go larger in every way in order to register the player's expansion in the world.

    So two questions really:

    1. How would you deal with managing factories and belts in the background?
    2. How can I resize the array dynamically, is it even the right way to go about it?

    Thank you so much for any help or idea :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The problem with this approach is that most of the cells will be empty, so a lot of memory will be wasted. Also, referencing 50 values stored on Z axis by their index will not be fun.

    I would probably use JSON and store only the cells which contain objects. Or it could be a combination of an array+JSON. Say, the array will store only object types for occupied cells (belt, pipe etc.) And the rest of the information will be in JSON under the key with the same coordinates - for example "Pipes.152_330". Knowing the object type and cell x/y you could easily access it. This will be a flexible and expandable system.

  • Wow that's a very good idea, I will try it right away, thank you so much :D

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)