Example #1
0
 public CollisionDelegate(object data, Shape shape)
 {
     this.data = data;
     this.shape = shape;
 }
Example #2
0
        public virtual bool Collides(Shape shape, Shape.CollideType detectMethod = CollideType.All)
        {
            if (shape is Rect)
                return Collides(shape as Rect, detectMethod);
            if (shape is Point)
                return Collides(shape as Point, detectMethod);
            if (shape is Circle)
                return Collides(shape as Circle, detectMethod);

            throw new Exception("Unsupported IShape specialization.");
        }
Example #3
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;
        }
Example #4
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;
 }
Example #5
0
 public CollisionDelegate()
 {
     data = null;
     shape = null;
 }
Example #6
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;
        }
Example #7
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;
        }