示例#1
0
 /// <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));
 }
示例#2
0
        /// <summary>
        /// Called every frame by the CollidableObject, which is called every frame by the Game1 class.
        /// Updates a Rectangle at the location of the Host GameObject each frame.
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(GameTime gameTime)
        {
            //Don't bother checking collisions if not active
            if (!Host.Active)
            {
                return;
            }

            UpdateHitbox();

            if (!ChecksCollisions)
            {
                return;
            }

            foreach (CollidableObject c in GameManager.CollidableObjectsInView)
            {
                if (!c.Active)
                {
                    continue;
                }
                //Don't check collisions with yourself!
                if (c.Name == Host.Name)
                {
                    continue;
                }
                //If we intersect with a new object
                if (Hitbox.Intersects(c.Coll.Hitbox) && !CurrentCollisions.Contains(c.Coll))
                {
                    CurrentCollisions.Add(c.Coll);
                    OnCollision(c.Coll);
                }
                //If stop intersecting with an object we just were intersecting with
                if (!Hitbox.Intersects(c.Coll.Hitbox) && CurrentCollisions.Contains(c.Coll))
                {
                    OnCollisionExit(c.Coll);
                    CurrentCollisions.Remove(c.Coll);
                }
            }
        }