Random Groups of Objects

0 favourites
  • 3 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • I am making a sidescrolling game where obstacles will be randomly generated. However, I want the series of obstacles to be clean and not just jumbled or impossible to navigate.

    My solution to this problem was to create groups of obstacles to randomly generate instead. I imagine I will want to define these groups in an external file and load them in via the ajax object which I am comfortable with. Maybe something like this:   obj1:0,obj7:50,obj3:100,obj3:140

    That string would represent a list of objects to spawn, along with a corresponding x offset that would place it behind the spawn x location.

    Here is where I'm not sure how to proceed:

    I want to be able to create these objects based on the string without needing to use a huge amount of events or having to repeat events for each scenario. What would be the best way to approach this, keeping in mind that I want it to be clean and dynamic.

    Thanks :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Do a loop over the tokens in the string and do a compare for each object type to pick which to create.

    Something like this:

    global string objs = "obj1:0,obj7:50,obj3:100,obj3:140"
    global string current_obj = ""
    
    repeat tokencount(objs, ",") times
         + set current_obj to tokenat(objs, loopindex, ",")
        system compare tokenat(current_obj, 0, ":") = "obj1")
             +create obj1 at (int(tokenat(current_obj, 1, ":")), 0)
        system compare tokenat(current_obj, 0, ":") = "obj7")
             +create obj7 at (int(tokenat(current_obj, 1, ":")), 0)
        system compare tokenat(current_obj, 0, ":") = "obj3")
             +create obj3 at (int(tokenat(current_obj, 1, ":")), 0)
  • very straightforward, I appreciate the tip :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)