コード例 #1
0
        private static bool checkCollisions(IEntityPhysics moveableEntity, IEntity otherEntity)
        {
            Shape moveableEntityBoundingBox = moveableEntity.boundingBox();
            Shape otherEntityBoundingBox    = otherEntity.boundingBox();

            if (moveableEntityBoundingBox is Circle && otherEntityBoundingBox is Circle)
            {
                Circle movingEntityCircle = (Circle)moveableEntityBoundingBox;
                Circle otherEntityCircle  = (Circle)otherEntityBoundingBox;

                float penetration;
                if ((penetration = circleCollision(movingEntityCircle, otherEntityCircle)) > 0)
                {
                    float hitAngle = MyMathHelper.angleBetween(otherEntityCircle.origin, movingEntityCircle.origin);
                    EventHandlers.getInstance().raiseEvent(new CollisionArgs(moveableEntity, otherEntity, hitAngle, penetration));
                    return true;
                }
            }
            else if (moveableEntityBoundingBox is Circle && otherEntityBoundingBox is QuadCollection)
            {
                Circle movingEntityCircle     = (Circle)moveableEntityBoundingBox;
                QuadCollection quadCollection = (QuadCollection)otherEntityBoundingBox;

                foreach (Quad quad in quadCollection.quads)
                {
                    KeyValuePair<float?, float> collisionAngle;
                    if ((collisionAngle = quadCircleCollision(quad, movingEntityCircle)).Key != null)
                    {
                        EventHandlers.getInstance().raiseEvent(new CollisionArgs(moveableEntity, otherEntity, (float)collisionAngle.Key, collisionAngle.Value));
                        return true;
                    }
                }
            }
            else
            {
                Debug.Assert(false, "No Collision defined for types " + moveableEntityBoundingBox.GetType() + " " + otherEntityBoundingBox.GetType());
            }

            return false;
        }