General Advice - Procedurally Creating Platforms?

Forum Home Forum Home > Construct 2 General > Construct 2 general
 Post Reply Post Reply Page  12>
Author
233 Rep
Post Options Post Options   Quote Maximo Quote  Post ReplyReply Direct Link To This Post Topic: General Advice - Procedurally Creating Platforms?
    Posted: 29 Jan 2012 at 5:56am
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!


Edited by Maximo - 29 Jan 2012 at 6:10am
Back to Top
16,524 Rep
Post Options Post Options   Quote newt Quote  Post ReplyReply Direct Link To This Post Posted: 29 Jan 2012 at 7:40am
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:
A: add entries at startup
B: use an algo, random(n) = this, do foo.
Back to Top
233 Rep
Post Options Post Options   Quote Maximo Quote  Post ReplyReply Direct Link To This Post Posted: 29 Jan 2012 at 5:25pm
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.

Edited by Maximo - 29 Jan 2012 at 5:30pm
Back to Top
16,524 Rep
Post Options Post Options   Quote newt Quote  Post ReplyReply Direct Link To This Post Posted: 29 Jan 2012 at 6:25pm
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.
Back to Top
233 Rep
Post Options Post Options   Quote Maximo Quote  Post ReplyReply Direct Link To This Post Posted: 29 Jan 2012 at 6:39pm
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...



Edited by Maximo - 29 Jan 2012 at 6:42pm
Back to Top
16,524 Rep
Post Options Post Options   Quote newt Quote  Post ReplyReply Direct Link To This Post Posted: 29 Jan 2012 at 6:53pm
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
Back to Top
233 Rep
Post Options Post Options   Quote Maximo Quote  Post ReplyReply Direct Link To This Post Posted: 29 Jan 2012 at 7:06pm
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?!]

Edited by Maximo - 29 Jan 2012 at 7:10pm
Back to Top
5,655 Rep
Post Options Post Options   Quote VampyricalCurse Quote  Post ReplyReply Direct Link To This Post Posted: 29 Jan 2012 at 10:27pm
Originally posted by newt newt wrote:

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


Excellent example newt.
Back to Top
3,411 Rep
Post Options Post Options   Quote gazoogle Quote  Post ReplyReply Direct Link To This Post Posted: 30 Jan 2012 at 11:39am


Newt -This was so clear and concise, what a great answer.

Edited by gazoogle - 30 Jan 2012 at 11:40am
Back to Top
16,524 Rep
Post Options Post Options   Quote newt Quote  Post ReplyReply Direct Link To This Post Posted: 30 Jan 2012 at 4:08pm
Thanks guys, glad I could help.
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down