Game Development Community

Ways to generate a procedural level?

by CharlesL · in iTorque 2D · 10/11/2012 (3:10 pm) · 6 replies

Does anyone know of a way of generating a procedural level? (ie. ski safari, canabalt, doodle jump).

What are ways to make sure that it generates a playable level? (no huge gaps that are impossible to jump, prevent unjumpible walls, enemies that are impossible to dodge, etc.)

I remember seeing something in the Torque 2D documentation about factories? Not sure what they are... is there anything like that in iTorque? If so docs or tutorial please?

#1
10/11/2012 (5:46 pm)
I've been working on some games that needs some procedural stuff, and well, seems complicated, but its not really, one approach will be as follows:

1) Generate platform patterns hardcoded in that way by design you make sure there is no "unjumpable" gaps or miss placed obstacles

2) Once you have a decent number of different patters, just assemble the level in runtime using those patterns in a random order, and you can introduce some other parameters into the mix like player speed, time elapsed, etc..

So on every run the level will be different, this approach works well only (once again) if you have a decent number of different patterns.

Another approach will be using QuadTrees like Canavalt its a little bit more complex, this method requires some AI to test the generated level and make sure there is no dead ends.

Hope it helps

#2
10/12/2012 (5:58 am)
Cool, Thanks for the help. Both make sense and I do want very random levels, so I'll have to chew over which one to use.

Are there any good examples of quadtree implementation?
#3
10/12/2012 (2:54 pm)
Check the source code of Canabalt here:

https://github.com/ericjohnson/canabalt-ios

That game uses QuadTrees, but its implemented in ObjectiveC language, you could easily port it to C++ and register some console functions to make those objects accessible to TorqueScript.

#4
10/13/2012 (3:34 pm)
Is it possible to do in TorqueScript? Does TorqueScript not support QuadTree implementation?
#5
10/14/2012 (10:13 am)
A good implementation of QuadTrees requires to do some clever recursion and good use of Heap memory space, so this is why it has to be done directly in C/C++ in order to achieve a performance-wise behavior.

You can theoretically implement a pseudo-quadtree on T-script, but its going to be slow and the amount of code needed to make it work correctly could be huge due to the limitations of the language.

I suggest using T-Script just to handle the basic flow of the game and its basic rules, like scene transitions player states, spawning enemies, etc. All the heavy work like custom physics, AI, special FX should be done directly in C/C++




#6
10/15/2012 (11:40 am)
OK, that makes sense, but I don't understand where to write that code.
Is it done in XCode or is there a special place in the project for them?