views:

16

answers:

0

Hello.

I have a grid based game (platformer) where I've based everything on tiles. I have tiles that are solid and liquid. I'm trying to find of a good way to make water tiles simulate water in a rough way.

At the moment I have the current system: When a water tile is added above another water tile, it adds 1 to the water tile below. The number indicates the pressure.

Here's how it looks like at the moment:

[0]   <- This water tile has 0 in pressure.
[1]   <- This water tile has 1 in pressure.

if I add another water tile next to the bottom one, it searches from left, right and above if there are any water tiles and inheritates the biggest pressure around it.

Example:

[0]
[1][1]

And here's a bigger example after adding few water tiles:

[0][0]
[1][1][1][1]
[2][2][2][2][2]

Then I make every water tile that has pressure that is equal or bigger than 1 try to move left/right if there's free space, then set pressure to 0 and check if it can inheritate pressure around itself from neighbor water tiles if there are any.

This system works very well, except for the case when water tiles are removed from the top.

If I remove the top water tiles from the last example:

[1][1][1][1]
[2][2][2][2][2] 

Then we have the top row with pressure 1, it should have 0 there now and the bottom row should have 1.

Is there some smarter system I can implement to do this more proper?

The following are the restrictions:

Each tile can only check its neighbors tiles. Tile can have any function defined. Tile can have any variable to store data.

Can you guys come up with a better system that works better than mine?

The usual test case I do is:

[]
[] should become [][]

[]
[]
[] should become [][][]

  []
[][][] should become [][][][]

Assuming the game runs for a while.

Any suggestions would be more than welcome!