Exemplo n.º 1
0
        private static void PassToNarrow(List <GameObject> objList)
        {
            short count = (short)objList.Count;

            // Loop through every object, starting from left.
            for (short left = 0; left < count; left++)
            {
                GameObject obj = objList[left];

                // Determine the right-boundary of the LEFT CURSOR object.
                int rBound = obj.posX + obj.bounds.Right;

                // Assign the RIGHT CURSOR as one to the right of LEFT CURSOR.
                short right = (short)(left + 1);

                // Compare the LEFT CURSOR to objects to its right until a short-circuit is found.
                while (right < count)
                {
                    GameObject obj2 = objList[right];
                    right++;

                    // Check if the RIGHT CURSOR object cannot collide (it's X position is too far right).
                    // If so, short-circuit this loop; there is no reason to test against additional objects.
                    if (rBound < obj2.posX)
                    {
                        break;
                    }

                    // The RIGHT CURSOR can potentially collide. Send it to NARROW COLLISION for testing.
                    CollideNarrow.ProcessCollision(obj, obj2);
                }
            }
        }
Exemplo n.º 2
0
        public static void ProcessCollision(GameObject obj, GameObject obj2)
        {
            // If an overlap is not detected, end the narrow testing here.
            if (!CollideDetect.IsOverlapping(obj, obj2))
            {
                return;
            }

            // Order the objects by archetype, and run them through the collision map.
            if (obj.Meta.Archetype < obj2.Meta.Archetype)
            {
                CollideNarrow.RefineCollision(obj, obj2);
            }
            else
            {
                CollideNarrow.RefineCollision(obj2, obj);
            }
        }