示例#1
0
        public void Update(float dt)
        {
            float num = this.NoAttractPhaseFriction;

            this.timeRemainingWithoutAttract -= dt;
            if ((double)this.timeRemainingWithoutAttract <= 0.0)
            {
                if (this.Points.Count > 1)
                {
                    num = this.Friction;
                }
                for (int index1 = 0; index1 < this.Points.Count; ++index1)
                {
                    for (int index2 = 0; index2 < this.Points.Count; ++index2)
                    {
                        if (index1 != index2)
                        {
                            PointGatherEffect.StarPoint point1 = this.Points[index1];
                            PointGatherEffect.StarPoint point2 = this.Points[index2];
                            if (point2.AttractedToOthers)
                            {
                                this.Points[index2] = this.ProcessAttractionBetweenPoints(point1, point2, dt, false);
                            }
                        }
                    }
                }
            }
            PointGatherEffect.StarPoint pA = new PointGatherEffect.StarPoint()
            {
                Pos = new Vector2(0.5f), size = this.attractionToCentreMass, Velocity = Vector2.Zero
            };
            for (int index = 0; index < this.Points.Count; ++index)
            {
                PointGatherEffect.StarPoint point = this.Points[index];
                if ((double)point.drawnSize < (double)point.size)
                {
                    point.drawnSize = Math.Min(point.size, point.drawnSize + dt * 15f);
                }
                point.Pos += point.Velocity * dt;
                if ((double)point.Pos.X > 1.0 || (double)point.Pos.Y > 1.0 || (double)point.Pos.X < 0.0 || (double)point.Pos.Y < 0.0)
                {
                    point.Pos.X     = Math.Max(0.0f, Math.Min(point.Pos.X, 1f));
                    point.Pos.Y     = Math.Max(0.0f, Math.Min(point.Pos.Y, 1f));
                    point.Velocity *= -0.5f;
                }
                point.Velocity    -= point.Velocity * (num * dt);
                this.Points[index] = point;
                if (this.Points.Count > 1)
                {
                    this.Points[index] = this.ProcessAttractionBetweenPoints(pA, point, dt, true);
                }
            }
            this.ResolveMergesThisFrame();
            if ((double)this.starSize <= 0.0)
            {
                return;
            }
            this.starSize -= dt * 3f;
        }
示例#2
0
        private PointGatherEffect.StarPoint ProcessAttractionBetweenPoints(PointGatherEffect.StarPoint pA, PointGatherEffect.StarPoint pB, float dt, bool constantForce = false)
        {
            Vector2 vector2_1 = constantForce ? pA.Pos + pA.Velocity * 0.4f : pA.Pos;
            float   num1      = (float)Math.Pow((double)Vector2.Distance(pA.Pos, pB.Pos), 2.0);

            if (constantForce)
            {
                num1 = 0.2f;
            }
            float   num2      = this.GravityConstant * (pA.size * pB.size) / num1 * (pA.size / pB.size);
            Vector2 vector2_2 = vector2_1 - pB.Pos;

            vector2_2.Normalize();
            Vector2 vector2_3 = vector2_2 * num2;

            pB.Velocity += vector2_3 * dt;
            return(pB);
        }
示例#3
0
 private int ResolveMergesThisFrame()
 {
     if ((double)this.timeRemainingWithoutAttract <= 0.0)
     {
         for (int index1 = 0; index1 < this.Points.Count; ++index1)
         {
             for (int index2 = 0; index2 < this.Points.Count; ++index2)
             {
                 if (index1 != index2)
                 {
                     PointGatherEffect.StarPoint point1 = this.Points[index1];
                     PointGatherEffect.StarPoint point2 = this.Points[index2];
                     if ((double)Vector2.Distance(point1.Pos, point2.Pos) < (double)this.absorbDistance * (1.0 + 0.200000002980232 * ((double)point1.size + (double)point2.size)))
                     {
                         float num1 = point1.size / point2.size;
                         float num2 = (double)point1.drawnSize > (double)point2.drawnSize ? point1.drawnSize : point2.drawnSize;
                         PointGatherEffect.StarPoint starPoint = new PointGatherEffect.StarPoint()
                         {
                             Pos = (double)point1.size > (double)point2.size ? point1.Pos : point2.Pos, Velocity = Vector2.Lerp(Vector2.Zero, point1.Velocity + point2.Velocity, 0.3f), size = point1.size + point2.size, drawnSize = num2
                         };
                         this.Points.RemoveAt(index1);
                         if (index2 > index1)
                         {
                             this.Points.RemoveAt(index2 - 1);
                         }
                         else
                         {
                             this.Points.RemoveAt(index2);
                         }
                         this.Points.Add(starPoint);
                         return(1 + this.ResolveMergesThisFrame());
                     }
                 }
             }
         }
     }
     return(0);
 }