Paste #39317: Untitled Paste

Date: 2017/01/23 17:52:37 UTC-08:00
Type: Plain Text

View Raw Paste Download This Paste
Copy Link



                    for (int i = 0; i < Entities.Count; i++)
                    {
                        Entity n = Entities[i];
                        n.Tick((float)e.Time);
                        for (int j = 0; j < Entities.Count; j++)
                        {
                            Entity a = Entities[j];
                            if (n != a)
                            {
                                Vector2 distance = a.Position - n.Position;
                                if (distance.LengthSquared <= (a.Size + n.Size) * (a.Size + n.Size))
                                {
                                    Entities.RemoveAt(j);
                                    j--;
                                    n.Size = (float)Math.Pow(a.Mass + n.Mass, 1.0 / 3.0);
                                    n.Mass += a.Mass;
                                    n.Position = (n.Position * n.Mass + a.Position * a.Mass) / (n.Mass + a.Mass);
                                    n.Velocity += a.Velocity;
                                }
                                else
                                {
                                    n.Velocity = a.Mass * distance / distance.LengthSquared;
                                }
                            }
                        }
                    }