0 Favourites

# How do I generate a level?

• 13 posts
• I am making a Mining Game like Motherload (If you dont know what that is, its an xgenstudios game, google it maybe to get a better reference) but the basic concept is a 2D Mining game.

How would I generate the blocky world for my minter without having it be scrambled and random, also I dont want certain ores to appear too early, and I want the entire top layer to be grass. I have made up the block images, each 50x50 (Will probably size down even more).

So how can I achieve this generating effect without Pre-Making a world that would take up 10000000 layout size. Plus I want my miner to be able to go back up and visit the shop on the surface world.

• You can try out procedural level generation, but in a case like Motherload, I would just go with some smart randoms.

First, start by filling your level with the standard tile (grass on top, then dirt everywhere else).

In a second time, depending on the ore distribution you need, do a random on each layer to see what tile to change into an ore, and repeat for each layer until the bottom of the level.

Example, if you want :

• 1000 tiles width
• 30% stone
• 5% gold

on one layer Y, then you should have around 300 stones and 50 gold on this layer. So in a "for" loop, go form 1 to 300 (then from 1 to 50), and replace the tile at X=random(1000,Y) with stone (then with gold).

Repeat this for each layer, changing the % depending on Y (you may want more gold in higher depths), and you should be good.

• Theory:

Part I

Generate the world.

You will have Width: W and Depth: D(number of tiles in width and in depth). W and D size don't need to cover entire map. You will be generating new "tiles array entries" as player will go deeper.

You have 3(as example) materials: A, B, C (mud, iron, gold [1,2,3 - in array]).

You create "terrain" array sized WxD

You start at terrain(0,0). For this tile generate random number(100)=R.

Single Tile generation:

You create 3 sets <0,a>; <a,b>; <b,100> + if-avaible array at given depth.

a and b will regulate how often material of given type appears at current depth. If-avaible tells if at current depth it is possible to encounter current material (0 for no 1 for yes).

If 0=<R<= a

Material_code= 1

If a= R <= b

Material_code = 2

If b=R<= 500

Material_code = 3

Before setting every value you check if-avaible array

index 0 1 2 3

material is available at given depth 0 1 1 0 [At depth = 0 it is impossible to encounter gold(3) but you can encounter mud(1) and iron(2)]

You check if if-avaible_array(Material_code,)= 1

If yes: (0,0)= Material_code

If no: generate random number R(100) again.

You do this for Terrain_array from (0,0) to (W,0)

Update of probability:

Once you fill (W,0) You will move to (0,1). Before you do it:

update a, b - in order to show how probability changes with depth (with "a" getting smaller there will be less mud and more iron)

update if-avaible array in order to show if player has reached depth at which he is able to find new minerals.

Fill the row as you did before.

Part II will tell how to do "moving".

• dilk Take a look at my project Greed

• Part II:

Blue ball is your digging ship. Green numbers are ids for each tile. Red frame means how much player sees (window). Red number says which pic is it(time) 1- first, 2- second, 3- rd.

You are moving your ship down(First pic). As you "move down" instead of moving your ship down you move all the visible tiles up.(2). At some point tile with id 2 will fully overlap tile with id 1. In this moment all tiles return to their original positions(From pic 1) but you change animation for tile with id 1 to animation of tile with id 2 (On pic it was brown now you change its color to gold).

The most bottom tile "asks" The terrain array what material animation should it take (1 - mud , 2 - iron, 3- gold) . I have left 0 as special number(empty). It means you must generate additional rows to your terrain array as you did in part I.

I have no idea how to write this in construct but im pretty sure its possible.

• Let me tell you guys this is a little too advanced for me to Understand, I haven't worked in this field before and I am really just getting lost, is there any way you guys could send me a .capx example? (Oh and the .capx to your game greed would be swell )

• lolpaca, your project is similar however tru see,s to get more what I mean, however I am not sure how to achieve what he is trying to say, so I ask if maybe you could PM me an example .capx ?

• Ha, I'm not sure the Greed capx would be much help for you - the engine's quite complicated and I don't make many notes! I'd really recommend you try this tutorial

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

Construct 3 users don't see these ads
• That tutorial is really outdated, and to be honest, with the little skill I currently have with Construct, it just makes things really more confusing for me when he talks about outdated terms and stuff that people that are familiar with construct with udnerstand the new term for that but I don't.

Sorry, are there any more updated tutorials?

Because that one is from around Construct 1.

• Yeah, it is for C1, although it works almost exactly the same in both. I translated it into C2 without too many problems, but I understand it's not that straightforward for everyone, especially if English isn't your first language.

I am working on my own tutorial for more advanced procedural generation in C2, which updates and expands on abhilash's one - it might be a couple of weeks before it's ready though. Until then, I'd recommend you get used to working with arrays, you're going to be seeing a lot of them

• Thanks, PM me with the tutorial when you get it up!

• You create 3 sets <0,a>; <a,b>; <b,100> + if-avaible array at given depth.

a and b will regulate how often material of given type appears at current depth. If-avaible tells if at current depth it is possible to encounter current material (0 for no 1 for yes).

t4u What do you mean by "You create 3 sets", can you try to explain me how to achieve it using your way? You can use actual code if that helps, I'm still learning C2 so I struggle a bit trying to organize the code into it.

• Could you PM me when you get that tutorial up?

• 13 posts