# General Advice - Procedurally Creating Platforms?

Discussion and feedback on Construct 2

### » Sun Jan 29, 2012 5:56 am

So I'm wanting to make a game like Spelunky; a platformer that has randomly generated levels. So, in other words, the first time you start the game, there will be 3 platforms, then a long jump, and then some stairs. The next time you start the game, there might be some stairs leading up to a platform, then a long jump over to four other platforms. The third time you start the game, it creates a new random layout. I realize that something like this would have to be coded, as you would have to tell the system all the rules it would need to know to build a level. Example:

1. Platforms must be spaced between x and y pixels apart.
2. Platforms cannot be more than z pixels higher than the nearest platform (cause the character can't jump that high)
3. Platforms length minimum and maximum
4. Etc., Etc

So, here are my questions!

A) Is this type of game possible in Construct 2?

B) Is there a programming/scripting language in Construct 2?

C) If I can create a randomly generated level layout in an 2-dimensional array, how do I get Construct 2 to build that on-screen? For instance, the 1st 30x30 pixel block on the bottom left of the screen displays a platform sprite if Array[1,0] = "P", and then if Array[1,1] = "L", place a ladder sprite on top of the first platform space

(Am I making any sense here?? LOL)

Basically, can I make a platform game that randomly re-arranges the platforms according to certain rules each time you play it?

I would greatly appreciate any help or advice that anybody could give me!
Maximo2012-01-29 06:10:13
B
2
S
1
Posts: 4
Reputation: 408

### » Sun Jan 29, 2012 7:40 am

A: yes
B: no
C: arrayat loopindex "x", loopindex "y" = "banana", system make banana at loopindex "x" *30, loopindex "y" *30.

No idea how you want to populate the array.
You can either:
B: use an algo, random(n) = this, do foo.
B
173
S
50
G
195
Posts: 8,578
Reputation: 121,892

### » Sun Jan 29, 2012 5:25 pm

Newt, thanks for your response. It's good to hear that this is possible.

Few more questions!

1) Sorry for the noob question, but I'm used to seeing array syntax looking like If ArrayName[x,y] = 8, Then Do Function_Name.

I see you use the term loopindex x and loopindex y. I'm not familiar with this term. Does it replace [x,y]? So instead of ArrayName[3,2], it becomes ArrayName loopindex 3, loopindex 2? Again, sorry, I'm probably misunderstanding what you are saying.

2) Your response looks suspiciously like code, but you say there is no programing language in Construct 2. Are you saying I will have to built and manipulate dozens of multi-dimensional arrays, built item and loot tables, and build a procedural level design engine - all through the event sheet drag and drop editor? Is this even practical? I imagine that would be very cumbersome...if it's even possible.Maximo2012-01-29 17:30:16
B
2
S
1
Posts: 4
Reputation: 408

### » Sun Jan 29, 2012 6:25 pm

To begin you would want to create a trigger such as start of layout, located under the system object. Then you would create a sub event under that, a nested loop. This would be a for loop, again located under the system, I would name it "x", as per my example. To nest it, add another subevent, another for loop, "y".
Then, once more you add a sub event under that, this will be a comparison.
The array object has one built in, or you can use the system compare.
Named for loops can be referred to in expressions as loopindex("loopname"). So if you input loopindex("x") in your comparison it will use the value of the current loop, 0,1,2,3,4, etc.

There are tons of examples that come with C2, and much more on the forums.
Might want to look around, its an excellent resource.
B
173
S
50
G
195
Posts: 8,578
Reputation: 121,892

### » Sun Jan 29, 2012 6:39 pm

Thanks Newt, I get what you're saying about the loop index now. It would be similar to

For x = 1 to 10 do
For y = 1 to 10 do
Array[x,y] = 0

Thanks for the help.    I'm still a little skeptical of doing all this through a drag-and-drop editor, but I'll look into some examples and see if I can get the hang of it. You don't happen to know of any examples that do something similar to what I'm talking about, do you? Anything that is procedurally generated actually - doesn't have to be a platformer... I've seen tons of examples on how to drag and drop platform sprites in the layout view to build a level, but I haven't seen any that touches upon building one in an array and then "printing" it to the screen...

Maximo2012-01-29 18:42:01
B
2
S
1
Posts: 4
Reputation: 408

### » Sun Jan 29, 2012 6:53 pm

I think your issue right now is how to populate the list. The array object isn't set up to load from an external source.
random array
B
173
S
50
G
195
Posts: 8,578
Reputation: 121,892

### » Sun Jan 29, 2012 7:06 pm

Wow - AMAZING! That's exactly what I was looking for. I can now wrap my head around this. THANK YOU!!!

[How do I give +Rep on these forums?!]Maximo2012-01-29 19:10:27
B
2
S
1
Posts: 4
Reputation: 408

### » Sun Jan 29, 2012 10:27 pm

[QUOTE=newt] I think your issue right now is how to populate the list. The array object isn't set up to load from an external source.
random array[/QUOTE]

Excellent example newt.
B
47
S
10
G
6
Posts: 455
Reputation: 8,340

### » Mon Jan 30, 2012 11:39 am

Newt -This was so clear and concise, what a great answer.gazoogle2012-01-30 11:40:03
B
38
S
5
G
8
Posts: 67
Reputation: 6,057

### » Mon Jan 30, 2012 4:08 pm

Thanks guys, glad I could help.
B
173
S
50
G
195
Posts: 8,578
Reputation: 121,892

Next