🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

[SDL2/C++] space map generation

Started by
4 comments, last by a light breeze 3 years, 9 months ago

hello all !

I am at the beginning of the creation of a space 4x and first of all i need to generate a galaxy of stars linked by connecting lines that changes in each new game, I'll add a few pictures to show what i mean

as you see, how can i have a simple 2d map with connected points like these images ? I thought to program each line with a length and a random angle but it is still unclear, thanks in advance !

Advertisement

Are you looking for a Delaunay triangulation?

@undefined Yes i can use delaunay triangulation for connecting points (stars) by triangular lines but what i should use if the points are not triangles but others polygons ?

It is not a 2D map, it is a graph (drawn by assigning a location to each site in a 2D scene) and it should be constructed with graph theory tools and constraints:

  • Maybe a planar graph (connections, especially if they are understood to be long distance like “wormholes”, could cross each other in the map)
  • An appropriate number of neighbours of specific types within a certain distance of sites of specific types (with distance measured by some combination of hop count, link length, assorted travel costs). For example, specific resources close to the player's starting location.
  • A certain minimum and maximum distance between specific sites. For example, enemy capitals not too close or too far.
  • Minimum and maximum size measures for the whole graph (not only the number of sites and links, but also the longest shortest path between any two sites, between the player's starting location and any other site, etc.)
  • Connectivity constraints, such as limiting or ensuring hubs with many links or limiting bottlenecks (for example, for any two sites A and B and any set of n other sites there must be a path from A to B that doesn't pass through those sites)

Omae Wa Mou Shindeiru

Create a bunch of random points, with a minimum distance between points. (If a randomly generated point is too close to another point, discard it and generate another random point.) Each point so chosen is a star. Make a list of all pairs of stars, measure the distance between them, and sort from shortest to longest. Starting at the pair of stars closest to each other, draw a connection between each pair of stars unless this connection would cross another connection that you have already drawn. (You don't want connections to cross because that makes the map harder to read.) Keep going until every star is reachable from every other star.

This topic is closed to new replies.

Advertisement