How do I create Galaxy for space game using arrays??

0 favourites
  • 5 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I need to figure out how to create a Galaxy for my space game. Let's just assume there's going to be 1000 solar systems and the Galaxy. And then using some sort of randomizer I need to randomize the possibility that each solar system may or may not have a son planets moons for planets so on. I will also need to randomly assign names to each solar system and planet and so on. I'm assuming I will be using some sort of array or possibly multiple arrays to create this. A little guidance would be appreciated as I'm new to construct. I managed to figure this out in qbasic though LOL

    Let me know if you have any other questions for me regarding what I'm trying to accomplish thanks ahead of time.

  • I came across this article on how the galaxy is generated in the original "Elite" game a few weeks ago, I haven't read through the details of the algorithm but it doesn't look too hard. Might be useful

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'll take a stab at it this weekend. Thanks for your input. If anyone else can come up with an easier way I would accept that answer as well LOL.

  • Hah yeah it's perhaps not the easiest introduction to procedural generation! Did you make any progress?

    I've been thinking about how I would go about doing this, which is perhaps not the simplest way but I guess you could remove/modify some steps to make them simpler.

    For positioning there's a technique I've been trying out recently called "Poisson disc sampling" which allows you to randomly place objects in an area, but ensure they aren't too close to each other. Here is a good animated explanation of how it works. There's also this video by Sebastian Lague.

    I plumbed some of my code into an example project for you to take a look at. I used inline JavaScript to do the Poisson instead of event sheets, hopefully that isn't too scary. For the other parts I used normal events, as scripting doesn't have access to some of the properties we need.

    For planets I used round(random(min, max)) to get a count, then placed them at a random distance/angle from the star. We have a behaviour called "Orbit" that makes them move, and "pinned" it to the star so it follows it. Then used more random calculations for the properties.

    Naming things is a little more complicated, there's a technique called Markov Chains which can be used for this. I've never written one but it looks quite easy, you can hold the name fragments in an array. There's a built in tool called the "array editor" which can be used to create and edit array files, which you can then load into an array object at runtime.

    As you can see quite a lot of this can be done without arrays, you can just use loops and local variables. If you want your code to be able to show the relations between planetary systems, suns, planets, moons you might have to create an array for lookups.

    There's plenty more that can be done from the demo project, hopefully it shows you enough to figure out the rest.

  • You could use the Advanced Random plug, Cellular, or Voronoi to generate systems.

    The z peaks would be the stars and planets.

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