Jump to content
  • Advertisement
  • entries
    23
  • comments
    21
  • views
    20636

Random Galaxy Generation in Shipyard

Sign in to follow this  
nerdboy64

1149 views

[color=rgb(51,51,51)][font=Georgia]

It's come time in Shipyard to add more sectors to travel to, and to have them generate randomly rather than being hard-coded like the current world. I also wanted the sectors to display on a "galaxy map," where sectors were placed randomly rather than being on a grid. I started with this, creating an algorithm to place points on the map as if they were sectors, even though they didn't function at that time. After a couple hours of tweaking, here are some examples of galaxies it generated:

[/font][/color]

[color=rgb(51,51,51)][font=Georgia]

javaw-2013-11-10-20-39-07-035-1024x598.png

[/font][/color]

[color=rgb(51,51,51)][font=Georgia]

javaw-2013-11-10-20-39-09-647-1024x598.png

[/font][/color]

[color=rgb(51,51,51)][font=Georgia]

These weren't produced by the final version, but rather an earlier version that kept a large minimum distance between sectors. The current version has a shorter minimum distance which creates more variation between worlds.

[/font][/color]

[color=rgb(51,51,51)][font=Georgia]

My algorithm for galaxy generation isn't exactly simple, but I will try to explain it here. First, a starting sector (always called "Galactic Core") is placed in the center of the galaxy. Then, the generator picks a random angle (We'll call it a) and distance d between 12 and 32 pixels, and places a second sector d pixels away from the Galactic Core, at an angle of a. From there, it randomly selects one of the two existing sectors and repeats the process of creating a new sector d pixels away at an angle of a. It also checks to make sure that the new sector is at least 12 pixels away from all of its neighbors, and if it's too close, the new sector is not created. The same is true if the new sector is more than 96 pixels away from the center, to keep them in a roughly circular pattern. The process repeats until there are 50 sectors in the world, each no closer than 12 pixels to any other and no farther than 96 from the center. Finally, any sector within 32 pixels of another sector is considered to be within warp gate range, so a line is drawn between them to denote this.

[/font][/color]

[color=rgb(51,51,51)][font=Georgia]

Here's an example of something generated by the final version:

[/font][/color]

[color=rgb(51,51,51)][font=Georgia]

javaw-2013-11-16-15-36-15-786-1024x598.png

[/font][/color]

[color=rgb(51,51,51)][font=Georgia]

Once that was done, it was time to code the internal generation of sectors. This was, thankfully, much easier to do. All the internal generation algorithm had to do was place one each of the basic stations (warp gate, item shop, and shipyard), as well as a random number of other objects (planets, item crates, etc.) on a 2D grid. No real fancy stuff, just a random X and Y value for a predefined set of objects. Sectors also generate with a random "style" attribute which dictates which background image to use. This is, again, just a random integer with nothing fancy under the hood.

[/font][/color]
Sign in to follow this  


2 Comments


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!