Can anyone code this behavior for me?[procedural level generation]

angryraccoon

  • Posts: 18
I'd love a behavior or set of behaviors or whatever that allowed me to procedurally and or randomly create worlds each time the game is started up, much like Minecraft or Terraria, on a 2D grid with tiles or actors or whatever so that certain tiles or actors(grass, dirt), are on a certain level, and so that caves and mountains and stuff are created together coherently, not just in a random spattering of tiles/actors. Is this even possible? I've tried many times myself and I just don't have the skill or knowledge for it. Thanks!

SWATLLAMA

  • Posts: 1059
I don't think this is even possible in design mode, or in stencyl, since Stencyl has lots of things already in the code mode, the BOX2D stuff... I could be wrong though. If you want it done, ask on the Kong forums or some other forums though, and specify that it's for stencyl. Though as far as I know, it's extremely hard to do in any language, whether it's AS2, AS3, C++ (Okay, it's not as hard in C++) Java, etc..
Hail The Llama
http://www.kongregate.com/accounts/lSWATLLAMA
"Play the games" ~ The Grand Llama

It's my life goal to rickroll as many people as possible

Rawr

  • Posts: 85
I "think" this could be done...just requires a heck lot of math and I'm not sure if design mode supports it. Insuring that the levels are suitable for the game is another story...man it's kinda getting scary. ;D

coleislazy

  • *
  • Posts: 2607
It is certainly possible, but difficult.

You would have to get comfortable with using List attributes, especially using multidimensional lists (http://community.stencyl.com/index.php/topic,1946.msg13807.html#msg13807). Figuring out how to cobble things together properly, like the caves and mountains you mentioned, would be harder, but certainly doable.

Now, your biggest challenge will be the limitations of run-time tile generation. Tiles that are added at run-time are not "clumped" together into one collision box like they are when they are placed by hand. This introduces all kinds of problems ranging from actors getting "stuck" on tile corners to poor performance. If you go this route, I would suggest you do one of three things:
  • Make the movement grid-based and turn off all collision boxes.
  • Write your own collision-detection code that skips the built-in physics altogether.
  • Figure out a way to generate terrain regions over your tiles and turn off collision boxes on the tiles themselves.

I did 1 for my game. 2 could be very difficult. 3 would probably be the most difficult, but would have the best results.

Please do not let me dissuade you from attempting this! I'm sure the community (and myself) will help you if you get stuck. Good luck!

coleislazy

  • *
  • Posts: 2607
Just to add a little side-note: I've seen nothing so far that requires you to use code-mode. You will certainly have to use code blocks inside design mode for certain functions, but you can always use design mode if it works best for you!

AnachroNia

  • Posts: 72
I've seen nothing so far that requires you to use code-mode.

I've seen - it's called optimization :)

If you want to generate level on the fly - you have to analyze the expected result and find some simple rules that guarantee it makes playable levels each time. For example there are a lot of maze-building / path-finding algorithms :) I don't know what is the case but if you tell something more about your project maybe we can find a way to do it :)

About 1,2,3 from coleislazy's post.
1. It's ok only if it's intended to be like this :)
2. This is a bad idea :) Box2D uses optimized algorithms. You can make something better/faster only if there are really specific rules applied to your scene :)
3. http://api.stencyl.com/as3/stencyl/api/engine/scene/TerrainRegion.html
http://api.stencyl.com/as3/stencyl/api/engine/GameState.html
The only strange thing is that tile collision shapes are stored as Int - this means somewhere should be an array with this shapes from the tile editor but I can't find it :(

xmagicx60

  • Posts: 213
Ive created a Random Level Generation system, but its laggy and is still limited by the size of the scene.

coleislazy

  • *
  • Posts: 2607
I've seen nothing so far that requires you to use code-mode.

I've seen - it's called optimization :)

If you want to generate level on the fly - you have to analyze the expected result and find some simple rules that guarantee it makes playable levels each time. For example there are a lot of maze-building / path-finding algorithms :) I don't know what is the case but if you tell something more about your project maybe we can find a way to do it :)

About 1,2,3 from coleislazy's post.
1. It's ok only if it's intended to be like this :)
2. This is a bad idea :) Box2D uses optimized algorithms. You can make something better/faster only if there are really specific rules applied to your scene :)
3. http://api.stencyl.com/as3/stencyl/api/engine/scene/TerrainRegion.html
http://api.stencyl.com/as3/stencyl/api/engine/GameState.html
The only strange thing is that tile collision shapes are stored as Int - this means somewhere should be an array with this shapes from the tile editor but I can't find it :(

Code mode and design mode produce the same end results. You can use anything in design mode that you could in code mode with the use of code blocks. My point was that you can tie any code you need to do back into the blocks of design mode. An advanced use may require many code blocks, but if you wish to, you could still do it in design mode.

And I wasn't speaking of how to draw the terrain region, but how to draw it over randomly generated levels in a way that makes sense in the game world.