Exemplo n.º 1
0
 public void Add(Drop drop)
 {
     var item = this;
     while (item.next != null)
     {
         item = item.next;
     }
     item.next = new DropItem(drop);
 }
Exemplo n.º 2
0
 public void Remove(Drop drop)
 {
     DropItem item = this;
     DropItem prevItem = null;
     while (item.next != null)
     {
         prevItem = item;
         item = item.next;
         if (item.dropdata.Gid == drop.Gid)
         {
             prevItem.next = item.next;
         }
     }
 }
Exemplo n.º 3
0
        public DropItem Update(Drop drop, bool forceDelete)
        {
            if (drop.Gid != null)
            {
                if (matrix[drop.Gmx] == null || matrix[drop.Gmx][drop.Gmy] == null)
                {
                    return null;
                }
                matrix[drop.Gmx][drop.Gmy].Remove(drop);
                if (forceDelete)
                {
                    return null;
                }

                drop.Gmx = (int)Math.Floor(drop.X / resolution);
                drop.Gmy = (int)Math.Floor(drop.Y / resolution);
                if (matrix[drop.Gmx] == null || matrix[drop.Gmx][drop.Gmy] == null)
                {
                    return null;
                }
                matrix[drop.Gmx][drop.Gmy].Add(drop);

                var collisions = Collisions(drop);
                if (collisions != null && collisions.Next != null)
                {
                    return collisions.Next;
                }
            }
            else
            {
                drop.Gid = Guid.NewGuid().ToString().ToString().Substring(2, 9);
                drop.Gmx = (int)Math.Floor(drop.X / resolution);
                drop.Gmy = (int)Math.Floor(drop.Y / resolution);
                if (matrix[drop.Gmx] == null || matrix[drop.Gmx][drop.Gmy] == null)
                {
                    return null;
                }

                matrix[drop.Gmx][drop.Gmy].Add(drop);
            }
            return null;
        }
Exemplo n.º 4
0
        private bool Gravity_Linear(CanvasDrawingSession context, Drop drop)
        {
            if (ClearDrop(context, drop))
            {
                return true;
            }

            if (drop.Yspeed != 0)
            {
                drop.Yspeed += gravity_force_factor_Y * (float)Math.Floor(drop.R);
                drop.Xspeed += gravity_force_factor_X * (float)Math.Floor(drop.R);
            }
            else
            {
                drop.Yspeed = gravity_force_factor_Y;
                drop.Xspeed = gravity_force_factor_X;
            }
            drop.X += drop.Xspeed;
            drop.Y += drop.Yspeed;
            drop.Draw(this, context);
            return false;
        }
Exemplo n.º 5
0
        private bool Gravity_None_Linear(CanvasDrawingSession context, Drop drop)
        {
            if (ClearDrop(context, drop))
            {
                return true;
            }
            if (drop.Collided)
            {
                drop.Collided = false;
                drop.Seed = (float)Math.Floor(drop.R * ((float)random.NextDouble()) * fps);
                drop.Skipping = false;
                drop.Slowing = false;
            }
            else if (drop.Seed == 0 || drop.Seed < 0)
            {
                drop.Seed = (float)Math.Floor(drop.R * random.NextDouble() * fps);
                drop.Skipping = drop.Skipping == false ? true : false;
                drop.Slowing = true;
            }

            drop.Seed--;

            if (drop.Yspeed != 0)
            {
                if (drop.Slowing)
                {
                    drop.Yspeed /= 1.1f;
                    drop.Xspeed /= 1.1f;
                    if (drop.Yspeed < gravity_force_factor_Y)
                    {
                        drop.Slowing = false;
                    }

                }
                else if (drop.Skipping)
                {
                    drop.Yspeed = gravity_force_factor_Y;
                    drop.Xspeed = gravity_force_factor_X;
                }
                else
                {
                    drop.Yspeed += 1 * gravity_force_factor_Y * (float)Math.Floor(drop.R);
                    drop.Xspeed += 1 * gravity_force_factor_X * (float)Math.Floor(drop.R);
                }
            }
            else
            {
                drop.Yspeed = gravity_force_factor_Y;
                drop.Xspeed = gravity_force_factor_X;
            }

            if (gravityAngleVariance != 0)
            {
                drop.Xspeed += ((float)(random.NextDouble() * 2 - 1) * drop.Yspeed * gravityAngleVariance);
            }

            drop.Y += drop.Yspeed;
            drop.X += drop.Xspeed;

            drop.Draw(this, context);
            return false;
        }
Exemplo n.º 6
0
 private bool Gravity_None(CanvasDrawingSession context, Drop drop)
 {
     return true;
 }
Exemplo n.º 7
0
        private bool Trail_Smudge(CanvasDrawingSession context, Drop drop)
        {
            var y = drop.Y - drop.R - 3;
            var x = drop.X - drop.R / 2 + (random.NextDouble() * 2);
            if (y < 0 || x < 0)
            {
                return false;
            }
            context.DrawImage(img, new Rect(x, y, drop.R, 2), new Rect(x / ImgScalefactor, y / ImgScalefactor, drop.R / ImgScalefactor, 2 / ImgScalefactor), 1);

            return true;
        }
Exemplo n.º 8
0
 private bool Trail_Drops(CanvasDrawingSession context, Drop drop)
 {
     if (drop.TrailY == 0 || drop.Y - drop.TrailY >= random.NextDouble() * 100 * drop.R)
     {
         drop.TrailY = drop.Y;
         PutDrop(context, new Drop(drop.X + ((float)random.NextDouble() * 2 - 1) * (float)random.NextDouble(), drop.Y - drop.R - 5, (int)Math.Ceiling(drop.R / 5), 0));
     }
     return true;
 }
Exemplo n.º 9
0
 private bool Trail_None(CanvasDrawingSession context, Drop drop)
 {
     return true;
 }
Exemplo n.º 10
0
 public void Remove(Drop drop)
 {
     matrix[drop.Gmx][drop.Gmy].Remove(drop);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Adds a new raindrop to the animation.
 /// </summary>
 /// <param name="context">context</param>
 /// <param name="drop">drop object to be added to the animation</param>
 private void PutDrop(CanvasDrawingSession context, Drop drop)
 {
     drop.Draw(this, context);
     if (Gravity != null && drop.R > gravityThreshold)
     {
         if (enableCollisions)
         {
             matrix.Update(drop, false);
         }
         drops.Add(drop);
     }
 }
Exemplo n.º 12
0
 public DropItem(Drop drop)
 {
     dropdata = drop;
     next = null;
 }
Exemplo n.º 13
0
        public DropItem Collisions(Drop drop)
        {
            var item = new DropItem(null);
            var first = item;

            item = AddAll(item, drop.Gmx - 1, drop.Gmy + 1);
            item = AddAll(item, drop.Gmx, drop.Gmy + 1);
            item = AddAll(item, drop.Gmx + 1, drop.Gmy + 1);

            return first;
        }
Exemplo n.º 14
0
        private bool Collision_Sample(CanvasDrawingSession context, Drop drop, DropItem collisions)
        {
            DropItem item = collisions;
            Drop drop2 = null;
            while (item != null)
            {
                Drop p = item.Dropdata;

                if (Math.Sqrt(Math.Pow(drop.X - p.X, 2) + Math.Pow(drop.Y - p.Y, 2)) < (drop.R + p.R))
                {
                    drop2 = p;

                    break;
                }
                item = item.Next;
            }
            if (drop2 == null)
            {
                return false;
            }

            // rename so that we're dealing with low/high drops
            Drop higher, lower;
            if (drop.Y > drop2.Y)
            {
                higher = drop;
                lower = drop2;
            }
            else
            {
                higher = drop2;
                lower = drop;
            }
            // force stopping the second drop
            ClearDrop(context, lower);
            ClearDrop(context, higher, true);
            matrix.Remove(higher);
            lower.Draw(this, context);
            lower.Colliding = higher;
            lower.Collided = true;
            return true;
        }
Exemplo n.º 15
0
 /// <summary>
 /// Clear the drop and remove from the list if applicable.
 /// </summary>
 /// <param name="context">context</param>
 /// <param name="drop">drop to be cleared</param>
 /// <param name="force">force force removal from the list</param>
 /// <returns> result if true animation of this drop should be stopped</returns>
 private bool ClearDrop(CanvasDrawingSession context, Drop drop, bool force = false)
 {
     bool result = drop.Clear(this, context, force);
     if (result)
     {
         drops.Remove(drop);
     }
     return result;
 }
Exemplo n.º 16
0
 private bool Reflection_Miniature(CanvasDrawingSession context, Drop drop)
 {
     var sx = Math.Max((drop.X / ImgScalefactor - reflectionDropMappingWidth), 0);
     var sy = Math.Max((drop.Y / ImgScalefactor - reflectionDropMappingHeight), 0);
     var sw = PositiveMin(reflectionDropMappingWidth * 2, width/ImgScalefactor - sx);
     var sh = PositiveMin(reflectionDropMappingHeight * 2, height / ImgScalefactor - sy);
     var dx = Math.Max(drop.X - 1.1 * drop.R, 0);
     var dy = Math.Max(drop.Y - 1.1 * drop.R, 0);
     context.DrawImage(img, new Rect(dx, dy, drop.R * 2, drop.R * 2), new Rect(sx, sy, sw, sh));
     return true;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Draws a raindrop on canvas at the current position.
 /// </summary>
 public void Draw(RainyDay rainyday, CanvasDrawingSession context)
 {
     float orgR = r;
     r = 0.95f * r;
     if (r < 3)
     {
         clipGeo = CanvasGeometry.CreateCircle(context, new Vector2(x, y), r);
     }
     else if (colliding != null || yspeed > 2)
     {
         if (colliding != null)
         {
             var collider = colliding;
             r = 1.001f * (r > collider.r ? r : collider.r);
             x += (collider.x - x);
             colliding = null;
         }
         float yr = 1 + 0.1f * yspeed;
         using (CanvasPathBuilder path = new CanvasPathBuilder(context))
         {
             path.BeginFigure(x - r / yr, y);
             path.AddCubicBezier(new Vector2(x - r, y - r * 2), new Vector2(x + r, y - r * 2), new Vector2(x + r / yr, y));
             path.AddCubicBezier(new Vector2(x + r, y + yr * r), new Vector2(x - r, y + yr * r), new Vector2(x - r / yr, y));
             path.EndFigure(CanvasFigureLoop.Closed);
             clipGeo = CanvasGeometry.CreatePath(path);
         }
     }
     else
     {
         clipGeo = CanvasGeometry.CreateCircle(context, new Vector2(x, y), 0.9f * r);
     }
     r = orgR;
     if (rainyday.Reflection != null)
     {
         using (context.CreateLayer(1, clipGeo))
         {
             rainyday.Reflection(context, this);
         }
     }
     if (clipGeo != null)
     {
         clipGeo.Dispose();
     }
 }