0 Favourites

Suggestion needed for random generation method.

  • Hi guys. I need to generate a random galaxy with let's say 10 stars. When you mouse over a star it will have a list of how many planets are present and what types. When you click on a star a new layout is loaded showing this system up close and in detail.

    How I've done it thus far is on start of layout generate random stars. Each star has a variable named "planets." On star creation planets is set to random. On clicking on a star layout 2 is loaded and the amount of random planets are spawned based on star.planets.

    There should be a cleaner and more effective way to do this. Possibly by using a database? I haven't touched those features of Construct yet.

    Suggestions please. Thank you guys.

  • There's nothing terribly wrong with that. Depends on how you expect your project to grow, i.e. will you eventually have 100 stars, etc. Perhaps give all stars an ID on creation (or use their IID) and use this ID as an index into an array that has the number of planets for each star. Might be overkill at the moment but as you add more info to your stars you can just add another 'x' value for each star. Also you can load/save as JSON file, etc. and even create the file offline in some editor. I'm not sure if I'd go down the database path just yet (C2 doesn't really have it's own db as such) but it depends on the aims of your project. Welcome to C2.

  • Thank you for the reply. How well does Construct handle save states after a galaxy is generated? I don't want it to be random every time you enter and leave a view.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • You should have a scan of the manual, there is 'persistent' behaviour, plus different options for saving game state, some quite new.

  • Hmmm... I'm starting to think arrays might be the way to handle this. Thoughts?

  • If you want it to persist between sections, check the Webstorage object or write state to a DB.

    Regarding arrays, yes, they are good for that and you could even save a whole array to a Webstorage object using JSON.

  • Or you could do it the true procedural way and use seeded random numbers so given a seed the outcome is always the same. I believe Rex had a plugin for this.

  • I have a galaxy generation algorithm that outputs 10,000+ stars with planets etc.

    [attachment=0:13htk0al][/attachment:13htk0al]

    It is all in the math that you use. We store all of our information in JSON flat file, load via AJAX, parse with RexRainbow's Hash plugin.

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