I have been making a game like Minecraft or Terraria in which you add blocks and such to the world, and I came across this interesting debacle, the game is in a top down 2D perspective, and I would like to make it so users can add water to the world, however I would also like the water to behave like water would in the real world.
In other words, spread.
I'm guessing the code would work something like
if (space next to water block is open)
{
\\spread to that block
}
However, this would not stop the water at that point, flooding the underpart of the map and creating little islands where the players have made things.
I could also pre-make the map, and put the water in that way, allowing the land mass of the map to go unscathed, however this prevents the players from making their own rivers and whatnot.
So my question is, do I prevent players from using water? Or do I allow them to and try to fix any disasters?
Would there be any use to code that allows me to limit the amount of water generated?
The reason water is important is due to the fact that several water vehicles are being planned, and water could be used as a resource to feed the player (dehydration etc)
EDIT: I have worked in water as follows. It the player will add the water like a block, at this point the water will spread in an equal outward direction.
If the water intersects ANY block it will stop and proceed with phase two, which is to move back and forth to simulate waves.
I found that through using XNA's ability to locate the side of the rectangle intersected, I can make it continue on down a length
For example:
if (water.Intersects(something) && something.position.Y >= water.Top)
{
\\allow the water to continue adding to the width until the width hits something
}
Here is an image of the partially completed function in action