public ButtonForm(Collidable collider, bool keepTime = true) : base(keepTime) { Collider = collider; CollidingWithMouse = false; MouseCollidingFor = 0; MouseNotCollidingFor = 0; }
/// <summary> /// Check for a collision between this Collidable object and another. /// </summary> /// <param name="other"></param> /// <returns></returns> public CollisionResponse CollidingWith(Collidable other) { return InternalChecker.CollisionBetween(this, other); }
/// <summary> /// Check for a collision between a Collidable object and another object of arbitrary /// type. This allows Collidable subclasses to implement collision methods for objects /// that aren't necessarily Collidable objects (for example, PointCollider implements /// a collision method for Point and Vector2, even though they don't inherit from /// Collidable). /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static CollisionResponse CollisionBetween(Collidable a, object b) { try { return DynamicCollisionBetween(a, b); } catch (RuntimeBinderException) { return null; } }
/// <summary> /// Check for a collision between two Collidable objects. /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static CollisionResponse CollisionBetween(Collidable a, Collidable b) { try { var abb = a.BoundingBox(); var bbb = b.BoundingBox(); // If their bounding boxes don't collide, the geometries themselves // can't be colliding either. if (!RectUtils.Collision( abb[0], abb[1], abb[2], abb[3], bbb[0], bbb[1], bbb[2], bbb[3])) return new CollisionResponse(a, b, false); if (a.Precedence >= b.Precedence) return DynamicCollisionBetween(a, b); return DynamicCollisionBetween(b, a); } catch (RuntimeBinderException) { // This occurs when the object with higher precedence doesnt implement // a CollidingWith method for the object with the lower precedence. return new CollisionResponse(a, b, false); } }
public CollisionResponse(Collidable a, Collidable b, bool colliding) { ColliderA = a; ColliderB = b; Colliding = colliding; }