[RELEASED] Marching squares

Hi,

I’ve been working on 2D terrain generator similar to the terraria. With this tool you can create terraria like game or any other 2D world and you can even have few worlds in one scene with unlimited number of tiles.

Since this system uses marching squares algorithm with even easy to use interface it is not hard to get great looking terrain.

Terrain is infinite.

Here is the preview:
2424388--165999--here.gif

Now you can get it on the assetstore:

As I develop this I’ll be updating this post so stay tuned!
Thank you for your time!

2 Likes

This looks very cool - gunna watch the thread and keep up to date.

Amazing large tracts of land.

Thank you for your kind words! :slight_smile:

New update.
I’ve been working on a multi threading and along the way I even improved the performance a lot.
There is now even ‘object’ tile which helps to create nice looking trees.
Tile now support events.

Here is the video (22500 tiles):

Why bother using marching squares? You could do exactly the same thing easier just with rectangular arrays? Marching squares typically have angular edges not right-angles. Do you mean to call it a quadtree?

Well I found somewhere this definition of marching squares:
Marching Squares is a family of algorithms for automation that appear in everything from isolating isobars on weather graphs to selecting shape outlines in image editors, and even generating game worlds.

I used marching squares to calculate really fast which tile should be used in a specific condition. ( conditions are already given by the user and the conditions is based on surrounding tiles-squares).
In the terrain below there are only 3 unique tiles( grass , air and dirt). I only set air, dirt or grass in the world. Here is the example without marching squares:
2437344--167080--before.PNG

Chunk is made of squares. They have a right-angles.

Now when you define few conditions and use fast marching squares algorithm you get much better result. Shown below.

Condition example;
if this tile is dirt and air is surrounding this tile use a different tile that suits this condition.

With marching squares:
2437344--167081--after.PNG

There are many conditions shown in a picture above.

Hope this makes sense! :slight_smile:

So, to sum up, I used marching squares to get fast and great looking terrains.

This is looking quite sweet.

1 Like

Extreme test, do not do this at home :wink:

Let there be vine! There is also background world showed in pictures below.

Each tile got changed(now they are all part of my work).

I am planning to release it soon on the asset store. Any suggestions are welcome!

Latest video. I have submitted the asset on the asset store. Waiting approval.

Now you can get it on the asset store.

Good luck on creating 2d terrains! :slight_smile:

Here is the water that is still WIP. It’s funny how simple it was to implement this in the whole system.
I’m thinking if I should also use marching squares algorithm on water or some different approach to make it look smooth.
2689041--190193--c24fb3f81d6803cc3e6e911591c5a673.gif

2 Likes

That’s pretty cool!

1 Like

is it possible to save level ?

using UnityEngine;
using System.Collections;
using MarchingSquares;

public class SaveWorld : World {

protected override void OnChunkCreated(Chunk chunk)
{

//sets all titles in the chunk to tile with array
for (int x = 0; x < World.CHUNK_SIZE; x++)
{
for (int y = 0; y < World.CHUNK_SIZE; y++) {
chunk.SetTileLocal (x, y, 0);
}
}
}
}

It is, and it is very simple just add one line in the world script:
Note: System is already saving levels it just does not load them.

1 Like

Marching squares is sometimes used to render an approximate of blobby objects/metaballs, which happen to work pretty well to represent liquids. However, I would presume recalculating the squares for a lot of cells is hard on performance. Maybe take a look at implementing each water particle/cell as a pre-computed sprite containing an image of the metaball ‘energy field’ which will allow the drops of water to blob together nicely and be very efficient to render - though you’d need a custom shader I think to draw the metafield’s threshold… maybe render water to the display’s alpha channel then grab it?

You were right about water performance so I gave up on that. I’ll take different approach now and hopefully I’ll make it better this time.

Anyway I updated asset price, so more people can afford it!

looks interesting. you should integrate a node based system for the generation of terrains. so that it’s get easy to make lots of biomes and caves with it.

That’s really nice thought, but scripting your world is also interesting way and very simple too.