public bool Intersects(CollisionBoundingBox other)
        {
            // See https://stackoverflow.com/a/402019/2442468 for how to do collision
            // Option 1: Circle center is within boundingbox
            if (other.Intersects(this.Center))
            {
                return(true);
            }

            // Option 2, BoundingBox has a point inside the circle
            if (this.Intersects(other.BoundingRect.TopLeft()))
            {
                return(true);
            }
            if (this.Intersects(other.BoundingRect.TopRight()))
            {
                return(true);
            }
            if (this.Intersects(other.BoundingRect.BottomLeft()))
            {
                return(true);
            }
            if (this.Intersects(other.BoundingRect.BottomRight()))
            {
                return(true);
            }

            // No collision detected
            return(false);
        }
        public BoundingBoxComponent(GameEntity entity, Vector2 location, Rectangle baseRect) : base(entity)
        {
            //_box = (CollisionBoundingBox)CollisionGeometryFactory.CreateGeometry(CollisionType.BoundingBox);
            _box = new CollisionBoundingBox(location, baseRect);

            Geometry = _box;

            RaiseCreated();
        }
 private bool BoundingBoxCollides(CollisionBoundingBox a, CollisionGeometry b)
 {
     if (b is CollisionBoundingBox)
     {
         return(a.Intersects((CollisionBoundingBox)b));
     }
     if (b is CollisionCircle)
     {
         return(a.Intersects((CollisionCircle)b));
     }
     return(false);
 }
 public BoundingBoxComponent(GameEntity entity, CollisionBoundingBox box) : base(entity)
 {
     _box     = box;
     Geometry = box;
     RaiseCreated();
 }
 public static bool Intersects(CollisionBoundingBox a, Rectangle b) => a.Intersects(b);
Esempio n. 6
0
 public bool Intersects(CollisionBoundingBox other)
 {
     return(this.BoundingRect.Intersects(other.BoundingRect));
 }