Exemple #1
0
        public void Update(ref Tile[,,] tiles, ref WaterDrop [,] drops, float elapsedTime)
        {
            if (this.volume <= 0.0f || (elapsedTime - lastUpdate) < updateTime) { return; }

            lastUpdate = elapsedTime;

            if (tiles[1, tileY, tileX].tileType == TileType.Dirt)
            {
                this.volume = 0.0f;
                return;
            }

            if (tiles[1, tileY, tileX].tileType == TileType.Sand)
                waterSand = true;
            else
                waterSand = false;

            if (belowClear() && tiles[1, tileY + 1, tileX].tileType == TileType.Dirt || tiles[1, tileY + 1, tileX].tileType == TileType.Decoration || this.volume >= 1 && drops[grabY(1), tileX].volume >= 16)
             {
                 if (this.volume > drops[tileY, grabX(-1)].volume && this.volume > drops[tileY, grabX(1)].volume) // Going Left and Right
                 {
                     if (tileX == grabX(-1) || tileX == grabX(1)) return; // If Self, return
                     if (this.volume < 0.01f) { this.volume = 0.0f; return; }

                     float totalVol = drops[tileY, grabX(-1)].volume + this.volume + drops[tileY, grabX(1)].volume;

                     bool tmp = false;
                     int dividerAmount = 1;

                     if (tiles[1, tileY, grabX(-1)].tileType != TileType.Dirt)
                         dividerAmount++;

                     if (tiles[1, tileY, grabX(1)].tileType != TileType.Dirt)
                         dividerAmount++;

                     if (tiles[1, tileY, grabX(-1)].tileType != TileType.Dirt)
                     {
                         drops[tileY, grabX(-1)].volume = (float)Math.Round(totalVol / dividerAmount, 2);
                         tmp = true;
                     }

                     if (tiles[1, tileY, grabX(1)].tileType != TileType.Dirt) {
                         drops[tileY, grabX(1)].volume = (float)Math.Round(totalVol / dividerAmount, 2);
                         tmp = true;
                     }

                     if (tmp)
                        this.volume = (float)Math.Round(totalVol / dividerAmount, 2);
                 }
                 else if (this.volume > drops[tileY, grabX(-1)].volume) // Going Left
                 {
                     if (tileX == grabX(-1)) return;
                     if (this.volume < 0.01f) { this.volume = 0.0f; return; }

                     if (tiles[1, tileY, grabX(-1)].tileType == TileType.Dirt)
                         return;

                     float totalVol = drops[tileY, grabX(-1)].volume + this.volume;
                     totalVol = (float)Math.Round(totalVol / 2, 2);

                     drops[tileY, grabX(-1)].volume = totalVol;
                     this.volume = totalVol;
                 }
                 else if (this.volume > drops[tileY, grabX(1)].volume) // Going Right
                 {
                     if (tileX == grabX(1)) return;
                     if (this.volume < 0.01f) { this.volume = 0.0f; return; }

                     if (tiles[1, tileY, grabX(1)].tileType == TileType.Dirt)
                        return;

                     float totalVol = drops[tileY, grabX(1)].volume + this.volume;
                     totalVol = (float)Math.Round(totalVol / 2,2);

                     drops[tileY, grabX(1)].volume = totalVol;
                     this.volume = totalVol;
                 }
             }

            // Check left empty AND left down is empty (then fall)

            if (belowClear() && tiles[1, tileY + 1, tileX].tileType != TileType.Dirt)
            {
                // this.position.Y += 16;
                // this.tileY = (int)this.position.Y / 16;

                // if the current volume is more than zero and bottom drop is empty, pour all of water into bottom drop
                if (this.volume > 0.0 && drops[grabY(1), tileX].volume <= 0.0)
                {
                    drops[grabY(1), tileX].volume = this.volume;
                    this.volume = 0;
                }

                if (drops[grabY(1), tileX].volume < 16)
                { // if the drop below isnt full, drip into it

                    // Space left to pour into
                    float deltaPour = (16 - drops[grabY(1), tileX].volume);

                    // Delta between deltaPour and vol
                    float amountRemaining = (deltaPour - this.volume);

                    drops[grabY(1), tileX].volume += this.volume;

                    if (amountRemaining > 16)
                        this.volume = (amountRemaining - 16);
                    else
                        this.volume = 0.0f;
                }

                // If bottom, left and right drops are full, push water into one above.
                /*
                if (this.volume >= 16.0 && drops[grabY(1), tileX].volume >= 16.0f && drops[grabY(0), grabX(-1)].volume >= 16.0f && drops[grabY(0), grabX(1)].volume >= 16.0f && tiles[tileY - 1, tileX].tileType == TileType.Empty)
                {
                    float deltaPour = (16 - drops[grabY(-1), tileX].volume);

                    // Delta between deltaPour and vol
                    float amountRemaining = (deltaPour - this.volume);

                    drops[grabY(-1), tileX].volume += this.volume;

                    if (amountRemaining > 16)
                        this.volume = (amountRemaining - 16);
                    else
                        this.volume = 0.0f;
                }*/
            }

            if (this.volume > 16.0f)
                this.volume = 16.0f;

               // if (this.volume >= 16.0f && tiles[grabY(-1), tileX].tileType == TileType.Empty)
            //    topMost = true;

            if (grabY(-1) > 0)
            {
                if (drops[grabY(-1), tileX].volume <= 0.0f)
                    topMost = true;
                else
                    topMost = false;
            }
        }
Exemple #2
0
 public void setupDrops()
 {
     droplets = new WaterDrop[levelHeight, levelWidth];
     Random rand = new Random();
     for (int y = 0; y < levelHeight; y++)
     {
         for (int x = 0; x < levelWidth; x++)
         {
             droplets[y, x] = new WaterDrop(x, y, levelWidth, levelHeight, 0);
         }
     }
 }