I have a net game (platformer) where I based everything on tiles. I have solid and liquid tiles. I am trying to find a good way to make water tiles simulate water roughly.
I currently have the current system: When a water tile is added above another water tile, it adds 1 to the water plate below. A number indicates pressure.
Here's what 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, it will search on the left, on the right and above if there are any water cannons and inherits the greatest pressure around it.
Example:
[0] [1][1]
And here is a great example after adding a few tiles:
[0][0] [1][1][1][1] [2][2][2][2][2]
Then I make each water-jet slab that has a pressure equal to or greater than 1, try to move left / right, if there is free space, then set the pressure to 0 and check if it can inherit the pressure around it from neighboring reservoirs, if there are by any.
This system works very well, unless tiles are removed from the water from above.
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, now it should be 0, and the bottom row should have 1.
Is there a smarter system that I can implement to make this more correct?
The following are limitations:
Each tile can only be checked by its neighbors. A tile can have any function. A tile can have any variable for storing data.
Can you guys create a better system that works better than mine?
A typical test case:
[] [] should become [][] [] [] [] should become [][][] [] [][][] should become [][][][]
Assuming the game has been running for a while.
Any suggestions would be more than welcome!