コード例 #1
0
 private void AutoCreateCollisionGroup(CollisionGroupIdentifier group)
 {
     if (!m_Delegates.ContainsKey(group))
     {
         m_Delegates.Add(group, new LinkedList<CollisionDelegate>());
     }
 }
コード例 #2
0
        public Vector2 DisallowIntersection(Shape shape, CollisionGroupIdentifier group, Vector2 Velocity, Shape.CollideType typeCheck = Shape.CollideType.All)
        {
            if (Velocity == Vector2.Zero)
                return shape.position;

            LinkedList<CollisionDelegate> delegates = m_Delegates[group];
            List<CollisionDelegate> CollidingDelegates = new List<CollisionDelegate>();

            Shape nextFrameShape = shape;
            Shape fixedPositionShape = shape;
            nextFrameShape.position += Velocity;

            Velocity.Normalize();

            foreach (CollisionDelegate cd in delegates)
            {
                while (nextFrameShape.Collides(cd.shape, typeCheck))
                {
                    if (!fixedPositionShape.Collides(cd.shape, typeCheck))
                    {
                        fixedPositionShape.position += Velocity;
                    }
                    else
                    {
                        fixedPositionShape.position -= Velocity;
                        nextFrameShape.position = fixedPositionShape.position;
                    }
                }
            }

            return nextFrameShape.position;
        }
コード例 #3
0
 /// <summary>
 /// Returns the first instance that is detected to collide with the given shape.
 /// </summary>
 /// <param name="shape">Shape to be checked against for collision.</param>
 /// <param name="typeCheck">Definition of what a "collision" is for this check. Optional.</param>
 /// <returns></returns>
 public CollisionDelegate CollisionCheckFirstObject(Shape shape, CollisionGroupIdentifier group, Shape.CollideType typeCheck = Shape.CollideType.All)
 {
     LinkedList<CollisionDelegate> delegates = m_Delegates[group];
     CollisionDelegate firstInstance = new CollisionDelegate();
     foreach (CollisionDelegate cd in delegates)
     {
         if (shape.Collides(cd.shape, typeCheck))
         {
             firstInstance = cd;
             break;
         }
     }
     return firstInstance;
 }
コード例 #4
0
        /// <summary>
        /// Returns a list of collision delegates containing all delegates whose shapes met the collision check with the given shape.
        /// </summary>
        /// <param name="shape">Shape to be compared against for collision.</param>
        /// <param name="typeCheck">Definition of what a "collision" is for this check. Optional.</param>
        /// <returns></returns>
        public List<CollisionDelegate> CollisionCheckAllObjects(Shape shape, CollisionGroupIdentifier group, Shape.CollideType typeCheck = Shape.CollideType.All)
        {
            LinkedList<CollisionDelegate> delegates = m_Delegates[group];
            List<CollisionDelegate> CollidingDelegates = new List<CollisionDelegate>();

            foreach (CollisionDelegate cd in delegates)
            {
                if (shape.Collides(cd.shape, typeCheck))
                {
                    CollidingDelegates.Add(cd);
                }
            }
            return CollidingDelegates;
        }
コード例 #5
0
        /// <summary>
        /// Returns whether or not an instance collides with the given shape.
        /// </summary>
        /// <param name="shape">Shape to be checked against for collision.</param>
        /// <param name="typeCheck">Definition of what a "collision" is for this check. Optional.</param>
        /// <returns></returns>
        public bool CollisionCheck(Shape shape, CollisionGroupIdentifier group, Shape.CollideType typeCheck = Shape.CollideType.All)
        {
            LinkedList<CollisionDelegate> delegates = m_Delegates[group];
            bool isColliding = false;

            foreach (CollisionDelegate cd in delegates)
            {
                if (shape.Collides(cd.shape, typeCheck))
                    isColliding = true;
            }
            return isColliding;
        }
コード例 #6
0
        /// <summary>
        /// Adds the given delegate to the designated delegate group.
        /// </summary>
        /// <param name="group">Group the delegate should be added to.</param>
        /// <param name="collisionDelegate">Collision delegate to be added.</param>
        /// <returns>A CollisionDelegateReference to be used for removal of the delegate from the collision world and for manipulation of the delegate.</returns>
        public CollisionDelegateReference AddDelegate(CollisionGroupIdentifier group, CollisionDelegate collisionDelegate)
        {
            AutoCreateCollisionGroup(group);

            CollisionDelegateReference newReference = new CollisionDelegateReference();

            newReference.m_NodeGroup = group;
            newReference.m_Node = m_Delegates[group].AddLast(collisionDelegate);
            newReference.m_OwnerWorld = this;

            return newReference;
        }