Space Miner Automatic Planet Generation P6


Full planet generation with better textures is now finished. Next step will be to figure out how to generate collision mapping for it.




Space Miner Automatic Planet Generation P5


I introduced the rules I talked about previously, and I also solved the problem with the surface connecting properly at the end. I basically introduced a weight based on the current angle of the vector pointing to the latest tile. This weight would make it more and more probable that tiles are chosen to move closer to the height of the starting point.

I also added tile filling for the planet (that was very irritating to get done), so now I can basically generate a whole planet.

Things to do:

  • How do we get collision detection with the ship?
  • Test different planet sizes on target, start thinking about optimization if we run into problems
  • Make some nicer looking placeholder graphics to make it look a bit more like a planet


Space Miner Automatic Planet Generation P4


Some progress today for my planet generator in Space Miner, I have added a random generation for the next tile to be chosen (Lower, Level or Higher). I have also worked a bit on getting the edges between Areas connected properly.

Basically what I have now is a randomly generated planet surface without the logic to tie together the start and end surface. I am able to choose the radius of the planet, which gives me control of the size I want. The screenshots I am showing off has a radius of about 40, but real planets will hopefully be at least 10x-50x larger.

The next tasks will be:

  • Make the generator tie together the start and end of the surface by moving towards the same radius
  • Make the probability of next tile being Higher and Lower based on the current radius
    • Higher tile is more probable if radius is low
    • Lower tile is more probable if radius is high
    • Level tile should have a static probability… I think.
  • Make it a high probability of the next tile being the same as the previous one


Space Miner Automatic Planet Generation P3


Some progress done today. Basically I have mapped the areas in code with their respective Cells and how every area is connected to areas close to itself.

For example, Area1 has the Cell with the surface on top and is connected to A8 for increasing height and A2 for decreasing height.

If Area1 wants to continue with an Area1 cell (with the surface on top of the cell), then the next tile will be placed with an x = 1, y = 0 increment.

If Area1 wants to continue with an Area2 cell (decreasing height), then the next tile will be placed with an x = 1, y = 0 increment

If Area1 wants to continue with an Area8 cell (increasing height), then the next tile will be placed with an x =1, y = 1 increment.

This mapping has to be done for every Area1, …, Area8.

By following these rules all the way through Area1, we can procedurally generate a surface in that area. By keeping a vector from the planet centre to the latest created tile, we can decide when we change to Area2, Area3, Area4, …, Area8 based on the angle of that vector.

This is the class I am using now to keep track of these mapping, you can think of one CellPlacing as one Area with some added information.

 //Maps the connections between different areas, also keeps the Cell tied to every Area
 private class CellPlacing
 //The Cell to use as a tile
 public Cell cell;

 //The link to the next level CellPlacing (will be a link back to itself)
 public CellPlacing nextLevel = null;
 //The relative x, y for where to place the next tile
 public Vector2 nextLevelPos = null;

 //The link to the next decreasing height CellPlacing
 public CellPlacing nextLower = null;
 //The relative x, y for where to place the next tile
 public Vector2 nextLowerPos = null;

 //The link to the next increasing height CellPlacing
 public CellPlacing nextHigher = null;
 //The relative x, y for where to place the next tile
 public Vector2 nextHigherPos = null;

 //The starting angle for this area
 float startAngle;
 //The ending angle for this area
 float endAngle;

 //Takes the Cell to use as a tile, Area start angle and Area end angle
 public CellPlacing(Cell inCell, float inStartAngle, float inEndAngle)
 cell = inCell;
 startAngle = inStartAngle;
 endAngle = inEndAngle;

 //Creates a connection to the next level CellPlacing (should always be a link back to itself)
 public void SetNextLevel(CellPlacing inNextLevel, Vector2 inNextLevelPos)
 nextLevel = inNextLevel;
 nextLevelPos = inNextLevelPos.cpy();

 //Creates a connection to the CellPlacing with an increasing height Cell
 public void SetNextHigher(CellPlacing inNextHigher, Vector2 inNextHigherPos)
 nextHigher = inNextHigher;
 nextHigherPos = inNextHigherPos.cpy();

 //Creates a connection to the CellPlacing with a decreasing height Cell
 public void SetNextLower(CellPlacing inNextLower, Vector2 inNextLowerPos)
 nextLower = inNextLower;
 nextLowerPos = inNextLowerPos.cpy();

I did some basic graphics and did the mapping as described. I proceeded to generate the following “planet” by just choosing the next level CellPlacing and switch over to the next CellPlacing when the area changes.
There is no logic to figure out when the planet is finished yet, so the last side is kind of missing =)
The next steps will probably be to find out when to end the generation, and then start playing around with some randomly increasing / decreasing surfaces. This is coming to be a fun project =)

Until next time,

Space Miner Automatic Planet Generation P2


Not much to write down today, I came up with a visualization of how I expect to generate the planet. It starts off at the top with a vector and a flat tile, and then goes tile by tile to the right until 1/2 of the planet has been generated. This needs to be codified somehow =)


The length of the vector will affect the probability of the next tile being a level tile, a tile going further away or a tile coming closer to the center. The probability of the next tile being the same as the previous tile will also be high to avoid a jagged mess of very small hills.


Space Miner Automatic Planet Generation P1


I thought I would make a shot at automatic planet tile generation for Space Miner. This would save a lot of design time and open interesting opportunities in the future for automatic generation of random planets.

Generating a tilemap in LibGDX turns out to be quite easy, here is a small code snippet to help you get started:

TiledMap map = new TiledMap();
MapLayers layers = map.getLayers();

TiledMapTileLayer layer1 = new TiledMapTileLayer(100, 100, 16, 16);

//Create cells and use them to fill in the layer
Cell cell = new Cell();

Texture text = new Texture(“data/PlanetSurface/EarthTiles.pix.png”);
TextureRegion tr = new TextureRegion(text, 0, 0, 16, 16);
cell.setTile(new StaticTiledMapTile(tr));

layer1.setCell(0, 0, cell);

//Add more cells and setCell here


I have tested this code with one celltype pasted onto a 1000×1000 map on my cheapish android phone. The map was generated quite fast, and the fps was smooth.

Ok, so now we know how to generate a TiledMap without a pre-defined map file. How would we go about generating a whole planet?

What I will test is to divide the planet into x amount of areas based on the center of planet to surface angle.

Areas divided into degrees with 0 facing up:
1 = 337.5 to 22.5
A2 = 22.5 to 67.5
A3 = 67.5 to 112.5
A4 = 112.5 to 157.5
A5 = 157.5 to 202.5
A6 = 202.5 to 247.5
A7 = 247.5 to 292.5
A8 = 292.5 to 337.5

Each Area (A1 – A8) will have its own flat surface tiles. To build stuff like mountains, tiles from neighboring Areas will be used.

Possible Areas to use tiles from when generating the surface inside a specific area:
A1 => A7, A8, A1, A2, A3
A2 => A8, A1, A2, A3, A4
A3 => A1, A2, A3, A4, A5
A4 => A2, A3, A4, A5, A6
A5 => A3, A4, A5, A6, A7
A6 => A4, A5, A6, A7, A8
A7 => A5, A6, A7, A8, A1
A8 => A6, A7, A8, A1, A2

Adding more Areas would make the planet more smooth, but 8 is probably good as a starting point.

The start of generation will be to select a certain height from center at 0 degrees (middle of A1) and select the flat tile from A1 there. From there the automatic generation would place surface tiles moving clockwise until a full revolution is done. Care must be taken that the last tile will fit into the first one.

From the first tile, a random selection of the next tile will occur from the list of possible tiles to select. Depending on the height from centrum of the planet, increasing height tiles will be chosen with a higher/lower ratio than decreasing height tiles. This should generate planet surfaces with mountains and valleys.

Space Miner with round planets?

Well, I’ve finally started work on a larger Space Miner update, I have been putting this off for a little while.

Right now when entering the landing phase, what you are presented with is a flat map which repeats if the ship goes too far right or left. What I really want to add are circular maps which would be much more like real planets. You would be able to enter the landing phase with a movement perpendicular to the planet center, and basically be in a circular orbit.

By doing the landing phase like this, it is possible to enter a planet with a high perpendicular velocity and thereby have much more time to make a good landing and even to locate a good landing place. It will also become possible to zoom out to get a better overview of how high the ship is.

I will do some testing with the different sized tilemaps and see if very large maps can be run on Android phones. Ideally I would like to be able to have a large planet with a diameter of thousands of tiles minimum. I really want to have relative sizes between the planets, this would mean that the smallest planets are much, much smaller than the largest ones.