private void UpdateTerrain(int minY, int minX, int maxX)
{
minY = Math.Max(0, minY);
// For every column check whether there is air below sand so that the latter moves downwards
for (int x = minX; x < maxX; ++x)
{
int lowestAirPosition = height;
for (int y = minY; y < height; ++y)
{
TerrainType cur = PublicShape.TerrainBitmap[x, y];
//PublicShape.TerrainBitmap[x, y] = TerrainType.Air;
if (cur == TerrainType.Air)
{
if (lowestAirPosition == height)
{
lowestAirPosition = y;
}
}
else if (cur == TerrainType.Sand)
{
if (lowestAirPosition < height)
{
// Fill lowest air with sand
PublicShape.TerrainBitmap[x, lowestAirPosition] = TerrainType.Sand;
++lowestAirPosition;
// This position is now air
PublicShape.TerrainBitmap[x, y] = TerrainType.Air;
}
}
else
{
// Reset
lowestAirPosition = height;
}
}
}
}