Пример #1
0
        public bool isCollidingWith(Collider other)
        {
            this.UpdatePosition();
            other.UpdatePosition();
            //if our rectangles don't intersect, then we aren't touching.
            if(!firstCollider.Intersects(other.firstCollider))
                return false;

            int top = Math.Max(this.firstCollider.Top, other.firstCollider.Top);
            int bottom = Math.Min(this.firstCollider.Bottom, other.firstCollider.Bottom);
            int left = Math.Max(this.firstCollider.Left, other.firstCollider.Left);
            int right = Math.Min(this.firstCollider.Right, other.firstCollider.Right);
            Color self;
            Color them;

            //otherwise, check every pixel to find out if we are touching.
            for (int y = top; y < bottom; y++)
            {
                for (int x = left; x < right; x++)
                {
                    self = this.secondCollider[(x - this.firstCollider.Left) +
                                (y - this.firstCollider.Top) * this.firstCollider.Width];
                    them = other.secondCollider[(x - other.firstCollider.Left) +
                                (y - other.firstCollider.Top) * other.firstCollider.Width];

                    if (self.A != 0 && them.A != 0)
                    {
                        return true;
                    }
                }
            }
            return false;
        }
Пример #2
0
 public void RemoveCollider(Collider coll)
 {
     if (PlayerColliders.Remove(coll))
     {
         return;
     }
     if (EnemyColliders.Remove(coll))
     {
         return;
     }
     //This would be an error!
     Debug.Assert(false, "CollisionManager :: RemoveCollider(Collider coll) => Collider not found.");
     return;
 }
Пример #3
0
 //Add and Remove colliders
 public void AddCollider(Collider coll, Side side)
 {
     switch (side)
     {
         case Side.Player:
             PlayerColliders.Add(coll);
             break;
         case Side.Enemy:
             EnemyColliders.Add(coll);
             break;
         default:
             System.Console.WriteLine("CollisionManager :: Neutral Collider not added");
             break;
     }
 }
Пример #4
0
 //Virtual Functions
 //When this is overloaded, the inheriting class MUST provide a texture!
 public virtual void Load(ContentManager Content)
 {
     Debug.Assert((texture != null), "Texture has not been provided");
     size = new Vector2(texture.Width, texture.Height);
     collider = new Collisions.Collider(this, texture);
 }