How do I generate a level?

Get help using Construct 2

Post » Wed Feb 26, 2014 12:33 pm

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.
B
8
S
1
Posts: 62
Reputation: 627

Post » Wed Feb 26, 2014 12:49 pm

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.
B
17
S
8
G
4
Posts: 473
Reputation: 6,221

Post » Wed Feb 26, 2014 1:17 pm

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".
B
4
Posts: 17
Reputation: 232

Post » Wed Feb 26, 2014 1:27 pm

@dilk Take a look at my project Greed viewtopic.php?f=148&t=96259 which sounds kinda similar - I can pm you the capx if it helps. And check out abhilash's tutorial, that's a great introduction to the basic concepts of random level generation. viewtopic.php?t=61806&start=0
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Wed Feb 26, 2014 1:40 pm

Image
Image
Image

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.
B
4
Posts: 17
Reputation: 232

Post » Wed Feb 26, 2014 5:30 pm

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 :D)
B
8
S
1
Posts: 62
Reputation: 627

Post » Wed Feb 26, 2014 5:32 pm

@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 ?
B
8
S
1
Posts: 62
Reputation: 627

Post » Wed Feb 26, 2014 6:05 pm

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 viewtopic.php?t=61806&start=0 which shows you how to work with arrays and nested loops, which are two things you'll be seeing a lot of if you want to generate levels procedurally :D
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Mon Mar 10, 2014 6:08 pm

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.
B
8
S
1
Posts: 62
Reputation: 627

Post » Mon Mar 10, 2014 6:26 pm

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 :D
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests