1

正如标题所说,我需要在基于瓷砖的游戏中处理液体。

信息:每个图块是 16xPixels,它有一个水位(字节)。水应该与它附近的其他瓷砖平均起来,因为每个瓷砖都有一个水位。但我似乎做不到。

我希望它像在这个视频中一样: 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;
                }
            }
        }
4

0 回答 0