public bool DetectFullCollision(I2DCollidableComponent component1, I2DCollidableComponent component2) { if (component1 == null || component2 == null || (!component1.EnableCollisionDetection && !component2.EnableCollisionDetection)) return false; Rectangle rect1 = component1.Rectangle; Rectangle rect2 = component2.Rectangle; Nullable<Rectangle> innerRect1 = component1.InnerRectangle; Nullable<Rectangle> innerRect2 = component2.InnerRectangle; return DetectFullCollision(ref rect1, ref rect2, ref innerRect1, ref innerRect2, component1.Texture, component2.Texture); }
public bool IsColliding(I2DCollidableComponent component, params GameComponent[] exclusionList) { if (component == null || !component.EnableCollisionDetection || component.Rectangle == Rectangle.Empty || component.Texture.Bounds == Rectangle.Empty) return false; Rectangle rect1 = component.Rectangle; Nullable<Rectangle> innerRect1 = component.InnerRectangle; for (int x = 0; x < components.Count; x++) { if (components[x] == null || components[x] == component || exclusionList.Contains(components[x])) continue; I2DCollidableComponent component2 = components[x] as I2DCollidableComponent; if (component2 == null || !component2.EnableCollisionDetection || component2.Rectangle == Rectangle.Empty || component2.Texture.Bounds == Rectangle.Empty) { continue; } Rectangle rect2 = component2.Rectangle; Nullable<Rectangle> innerRect2 = component2.InnerRectangle; if (DetectFullCollision(ref rect1, ref rect2, ref innerRect1, ref innerRect2, component.Texture, component2.Texture)) return true; } return false; }
public List<GameComponent> GetCollidedComponents(I2DCollidableComponent component, params GameComponent[] exclusionList) { List<GameComponent> componentsCollided = new List<GameComponent>(); if (component == null || !component.EnableCollisionDetection || component.Rectangle == Rectangle.Empty || component.Texture.Bounds == Rectangle.Empty) return componentsCollided; Rectangle rect1 = component.Rectangle; Nullable<Rectangle> innerRect1 = component.InnerRectangle; for (int x = 0; x < components.Count; x++) { if (components[x] == null || components[x] == component || exclusionList.Contains(components[x])) continue; I2DCollidableComponent component2 = components[x] as I2DCollidableComponent; if (component2 == null || !component2.EnableCollisionDetection || component2.Rectangle == Rectangle.Empty || component2.Texture.Bounds == Rectangle.Empty) { continue; } Rectangle rect2 = component2.Rectangle; Nullable<Rectangle> innerRect2 = component2.InnerRectangle; if (DetectFullCollision(ref rect1, ref rect2, ref innerRect1, ref innerRect2, component.Texture, component2.Texture)) componentsCollided.Add(components[x]); } return componentsCollided; }