Finding a solution path with an array

0 favourites
  • 1 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi, I've been recently looking into how Spelunky generates its levels and wanted to try something similar in construct. The reference I'm looking at is on this page which basically details how the rooms and solution path are generated. While it seems fairly easy to understand, I'm having a bit of trouble finding a good way to make the solution path. I'm not following it exactly, but using it as a sort of guide.

    I'm using a 4x4 array and generating numbers which then generate tiles that correspond to those numbers.

    I start by choosing a random number betwen 0 and 3 for my starting room on the top row and set it's value in the array to "start" just so I have a reference (I'm not worrying too much about room types working together at the moment just want to understand the solution path)

    I have a global variable called "picker" I choose (0,1,2) and set picker to one of these numbers - 0 will be left, 1 down and 2 right

    I then look for "start" in the array using a For each XY element loop and then depending on what number the variable picker is adjust by either adding or subtracting to the array.CurX or CurY and placing another key word - this time "path" - this will be my second room.

    This seems to work ok, but I can see it will get more and more complicated with each iteration as I will need to keep track of a bunch of different things like whether or not the last placed room has moved on the y axis of the array or remained on the same line etc

    I've tried placing a third room "path2" and already things seem to be falling apart. There must be a better way to go about this, but I don't seem to be logical enough to work it out.

    I've linked my work in progress below, it's messy, buggy and probably more confusing than the ramblings above. I think though that I'm probably going about this the wrong way and while it might eventually get me there it won't be efficient and it's already becoming unwieldy and confusing.

    Can someone with experience with these things or a bit more nouse than myself give me a tip perhaps on a more effective way to do this?

    File here if you dare to look

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)