How do I create a hierarchy of objects that can be encountered? Array or JSON?

0 favourites
  • 5 posts
From the Asset Store
An example of how to make old style RPG random encounters and a limited battle system.
  • I want to create an array or .json file for my game.

    is a side-scrolling space shooter.

    My idea is this: every movement of e.g.: 1000px is chosen to create either an enemy, or some asteroids (for example 70% probability asteroids, 30% enemies).

    The point is that there are many object types that fall into the "enemy" family, and many object types in the "asteroid" family.

    And each level has characteristics, some enemies are not present in that series of levels.

    And I was thinking of also including items that enemies can drop, or if an asteroid is destroyed there is a 5% chance of finding a rare item.

    So I would have to create a hierarchy of objects that can be encountered in each level, and then enter the values ​​manually.

    How should I proceed? I have to use Arrays? Or JSON? Else?

  • Welll.....

    Manually entering data into an array would be tedious. And, any time you need to make changes or add things... ick.

    Manually creating a JSON would be even more tedious. Just making sure you got the syntax right.

    Assuming you don't have a lot of experience with MySQL or PHP, what I would do is something like this. And keep in mind, this is not an ideal solution but it would be a good starting place to learn about databases.

    First, I would download SQLite Studio (google it) and use it to create a database of the objects in the game. Depending on how you structured it, it would be dead easy to add levels, add new objects, etc. just by adding a new item to the table.

    After you have the database I would then look at using an SQLite to JSON converter like this one: mygeodata.cloud/converter/sqlite-to-json

    SQLite creates a db file that you'd upload to it. I've never used that site before so I can't promise it would work.

    Then, bring your JSON into the game, parse the crap out of it and stuff all that into an array.

    The advantage of that is, you could have a table for enemies, a table for asteroids and a table for drops and you could load each into separate arrays.

    That being said, if you have gobs of stuff to add, arrays do have limitations.

    I'm sure you could do it in firebase but, I've never worked with it so I couldn't tell you where to even start there.

  • The easiest solution is to create all objects on each level in advance, and then pick and activate them one-by-one when needed. If there are not too many objects, you can do this manually in layout editor - say, add 10 asteroids, 10 enemy1, 5 enemy2, 1 boss etc.

    Add them all to a family. Every 1000px pick a random family member, move it to the screen and activate its behaviors.

    With a large number of objects you can still do something similar:

    On Start of layout
     Repeat 100 times: Create asteroid at (-9999,-9999)
     Repeat 200 times: Create enemy1 at (-9999,-9999)
     ....
    

    For a large number of levels you can use an array or JSON. I'm not sure about SQLLite, it will probably be an overkill.

    I actually find it easier to enter data in table format in the Array Editor (or you can copy from Excel), and then convert the array to JSON in runtime:

    Each level in the array is on a separate sheet.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Welll.....

    Manually entering data into an array would be tedious. And, any time you need to make changes or add things... ick.

    Manually creating a JSON would be even more tedious. Just making sure you got the syntax right.

    Assuming you don't have a lot of experience with MySQL or PHP, what I would do is something like this. And keep in mind, this is not an ideal solution but it would be a good starting place to learn about databases.

    First, I would download SQLite Studio (google it) and use it to create a database of the objects in the game. Depending on how you structured it, it would be dead easy to add levels, add new objects, etc. just by adding a new item to the table.

    thank you for all answers.

    I wouldn't know what to do. The idea of ​​having to add other things (and STUDY other things) bores me... But after all, the more I program, the more I want to do complex things.

    I don't know if I should do as you said or do as in the last example of dop2000. (which is already complicated, but I can do it, I'm studying it).

    For now I don't really want to download SQLite or learn MySQL or PHP yet, but if you tell me it's really convenient (and I'll need it in the future) then I'll seriously consider it. Is it?

    Until now I have inserted the objects for each layout manually, but now I already have 15 - 20 levels in my game. And then I MUST be able to make sure that the levels are a little randomized. I would like to make a game with even 50+ levels. There are already about 10 enemies and I want to add more, and there are also tools or upgrades. However I MUST be able to randomize the game, still following a logic of my own invention.

    Here, look at this screenshot, this is the minimum complexity I would like to do, for the moment.

    Another thing: I found this link, take a look: https://www.construct.net/en/forum/construct-2/how-do-i-18/store-sub-array-inside-main-102648

  • You can do everything you want (memory limitations excepted) by using arrays. You don't need SQLite or Mysql or PHP. What I was suggesting was an easier way to generate the data for those arrays. You can always enter them manually. One thing to consider to reduce memory usage is to procedurally create an array map of your level then use that array to draw your level. Here's an example I did years ago using I think 12 image tiles to generate a procedural map. The array to create the map is just numbers.

    construct.net/en/forum/construct-3/your-construct-creations-9/procedural-archipelago-every-146271

    and the working demo:

    twistedvoid.com/c3examples/Castaway2

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