就像标题所说,我需要在基于磁贴的游戏中处理液体。
信息:每个图块都是16xPixels,它有一个WaterLevel(字节)。 水应该与其附近的其他瓷砖平均,因为每个瓷砖都有水位。但我似乎无法做到。
我希望它像在这个视频中一样: http://www.youtube.com/watch?v=3v9sH638nr0
但我不能这样做。帮助
if (WaterLevel > 0)
{
//Bottom
if (Program.Game.CurrentMap.Tiles[(int)TileLocation.X, (int)TileLocation.Y + 1].Collide == false && Program.Game.CurrentMap.Tiles[(int)TileLocation.X, (int)TileLocation.Y + 1].WaterLevel != 255)
{
if ((int)Program.Game.CurrentMap.Tiles[(int)TileLocation.X, (int)TileLocation.Y + 1].WaterLevel + (int)WaterLevel > 255)
{
WaterLevel -= (byte)(255 - Program.Game.CurrentMap.Tiles[(int)TileLocation.X, (int)TileLocation.Y + 1].WaterLevel);
Program.Game.CurrentMap.Tiles[(int)TileLocation.X, (int)TileLocation.Y + 1].WaterLevel = 255;
}
else
{
Program.Game.CurrentMap.Tiles[(int)TileLocation.X, (int)TileLocation.Y + 1].WaterLevel += WaterLevel;
this.WaterLevel = 0;
}
}
//Left or Right
else
{
bool Left = Program.Game.CurrentMap.Tiles[(int)TileLocation.X - 1, (int)TileLocation.Y].Collide;
bool Right = Program.Game.CurrentMap.Tiles[(int)TileLocation.X + 1, (int)TileLocation.Y].Collide;
byte Divider = 1;
int Average = WaterLevel;
if (Left)
{
Divider += 1;
Average += Program.Game.CurrentMap.Tiles[(int)TileLocation.X - 1, (int)TileLocation.Y].WaterLevel;
}
if (Right)
{
Divider += 1;
Average += Program.Game.CurrentMap.Tiles[(int)TileLocation.X + 1, (int)TileLocation.Y].WaterLevel;
}
WaterLevel = (byte)(Average / Divider);
Average /= Divider;
Divider -= 1;
if (Left)
{
Program.Game.CurrentMap.Tiles[(int)TileLocation.X - 1, (int)TileLocation.Y].WaterLevel = (byte)(Average / Divider);
Average /= Divider;
Divider -= 1;
}
if (Right)
{
Program.Game.CurrentMap.Tiles[(int)TileLocation.X + 1, (int)TileLocation.Y].WaterLevel = (byte)(Average / Divider);
Average /= Divider;
Divider -= 1;
}
}
}