A simple game, 100x100 "map", each cell holds the wall status (yes/no) and liquid volume (volume of liquid present, 0=air). From the top of the screen falls water and go to bottom as ordered by gravity and obstacles.
How to simulate this liquid (not necessarily water, I'm not sure what it will be, right now it behaves like a mix of water, gell and sand
Right now I have an algorithm like that:
- if the neighbour is WALL, do nothing in that direction
- move 3% of liquid volume down (if no obstacle), can't move down if target cell's volume is double volume of current cell
- move 2% of liquid volume right (if no obstacle and the volume of liquid in the target cell is lower)
- move 2% of liquid volume left (if no obstacle and the volume of liquid in the target cell is lower)
- move 1% of liquid volume up (if no obstacle and the volume of liquid in the target cell is lower), also only if current cell liquid volume is >1000 (so the air gives some pressure and the water does not pop up into the very top unless there is an extreme liquid pressure/volume)
I'm also wondering about more elements (like gas or oil), which makes it tricky if we make an assumption that only one element can occupy a single cell (best for the display and clarity to the player). But that's for later.