Space Miner Automatic Planet Generation P7

Hola,

I’ve been mapping the surface tiles to box2d bodies with the help of the awesome tool Physics Body Editor. I have divided all the tiles up into separate image files, and then used those as background to map the box2d bodies in the editor.

physicsBodyEditor

The resulting json file can be opened with the very helpful BodyEditorLoader.java functionality.

BodyEditorLoader surfaceLoader = new BodyEditorLoader(Gdx.files.internal("data/PlanetSurface/BodyDefinitions.json"));

 public Body AddBodyToCell(Cell cell, Vector2 position, World world, float scale)
 {
 BodyDef bd = new BodyDef();
 bd.position.set(0, 0);
 bd.type = BodyType.StaticBody;
 
 FixtureDef fd = new FixtureDef();
 fd.density = 1;
 fd.friction = 1f;
 fd.restitution = 0.05f; 
 
 Body MyBody = world.createBody(bd);
 surfaceLoader.attachFixture(MyBody, cellNameDictionary.get(cell), fd, 16f * scale);
 MyBody.setTransform(position.x, position.y, 0f);
 
 return MyBody;
 }

After some tinkering with when to load and when to remove the temporary surface bodies we get something like this:
planetProcedurallyGenerated06
The surface bodies are created in a radius around the ship. Depending on which tile is used, the corresponding body definition from the json file is added to the world.

When the ship moves away from the bodies, they will be removed from the world.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s