Endless Runner - segment generation

Hi,

I’m making an endless runner game and I’m wondering about approach to generating levels. I would like to create segments and stitch them together. A segment would be a finite section of a level with its own obstacles and spawners for enemies and collectibles. Segments would need to be added at runtime at random from a pre-defined selection. I would like to offload segment creation work to another person, who is going to focus on level design, so ideally no programming should be necessary to create another segment.

What is the correct approach to take in Defold? In my understanding, the segments need to be Defold collections, and these collections need to be instantiated by a collection factory at runtime. Since one factory can spawn only one type of collection, there would need to be multiple factories, one for each segment type, and I could parent them in a single “factory controller” game object, that would tell an appropriate factory to generate a segment.

Is this a correct approach or is there a better one?

Yes, that sounds about right I think. How many different segments would you have?

I think we’ll end up using about 15-20 different segments, for variety. They will reuse graphic elements for the most part, but will have different layouts.

I’ve noticed there is no way to get a list child objects from an object, so I figure that when I ask the designer to extend the factory controller object with new factories, I will have to register these factories in the scripts. Is there any built-in mechanism in Defold that would allow my designer to extend the selection of objects I’d create, without him having to touch any of the code?

15-20 collections shouldn’t be a problem.

You are correct that there is no way to get the child objects. You could in your main collection let the segment designer create one game object per collection and in each game object attach the collection factory plus a script. The purpose of the script would be in the init function to register the contained factory with the main collection by doing a msg.post():

msg.post("game:/game", "register_segment", { url = msg.url("#collectionfactory") })

Maybe this picture better illustrates what I mean:

3 Likes

@britzl Thank you very much, I think this will work exactly the way I’d like. I will try this and let you know! :slight_smile:

Just want to chime in to say this is exactly how we handled level creation in our game “Hammerwatch Coliseum”. The levels are made up of random “pieces” that was created by level designers without coding skills. They then added these to a collection with a unified naming with incremental numbers (“room_1”, “room_2” etc) and we have a script with two properties, min_room and max_room which they changed as they added new rooms (and it also allowed us to set min_room and max_room to the same number to force a certain map-segment to be created during debugging and development).

5 Likes