/// <summary> /// Adds a GameObject reference to the Objects dictionary /// If a CollidableObject is passed, it is also added to the CollidableObjects List /// </summary> /// <param name="name">GameObject name</param> /// <param name="g">GameObject reference</param> public static void Add(string name, GameObject g) { Objects.Add(name, g); if (g is CollidableObject) { CollidableObject c = (CollidableObject)g; CollidableObjects.Add(c); NonUIObjects.Add(g); } else if (g is Background) { Background b = (Background)g; Backgrounds.Add(b); } else if (g is UIObject) { UIObject ui = (UIObject)g; UIObjects.Add(ui); } else if (g is SFXWrapper) { SFXWrapper wrap = (SFXWrapper)g; SoundEffects.Add(wrap); } else { NonUIObjects.Add(g); } }
/// <summary> /// Create a standard collider attached to the host GameObject /// </summary> public Collider(CollidableObject host) { Host = host; CurrentCollisions = new HashSet <Collider>(); Hitbox = new Rectangle(Host.Location.X, Host.Location.Y, Host.Location.Width, Host.Location.Height); hitboxOffset = new Rectangle(0, 0, 1, 1); // no offset sendEvents = true; }
/// <summary> /// Am I currently colliding with the other CollidableObject? /// </summary> /// <param name="other"></param> /// <returns></returns> public bool CollidingWith(CollidableObject other) { if (!other.Active) { return(false); } return(CurrentCollisions.Contains(other.Coll)); }
/// <summary> /// Create a collider offset from the host. /// This will not broadcast events to avoid redundant events being sent out /// </summary> /// <param name="host">The Host GameObject</param> /// <param name="offset">A rectangle representing the x-offset, y-offset, width, height </param> public Collider(CollidableObject host, Rectangle offset) { Host = host; CurrentCollisions = new HashSet <Collider>(); //Apply the offset hitboxOffset = offset; Hitbox = new Rectangle(Host.Location.X + offset.X, Host.Location.Y + offset.Y, offset.Width, offset.Height); sendEvents = false; }