public override void RespondToCollision(CollisionInfo collisionInfo)
 {
     if (collisionInfo.HitObject is Ground || collisionInfo.HitObject is Explosion)
     {
         this.Exists = false;
     }
 }
Esempio n. 2
0
        public void HandleCollisions(IEnumerable<ICollidable> collidableObjects)
        {
            foreach (var collidable in collidableObjects)
            {
                this.objectsInPlane.Insert(collidable);
            }

            foreach (var collidable in collidableObjects)
            {
                var candidateCollisionItems = this.objectsInPlane
                    .GetItemsInRange(new List<ICollidable>(), collidable.Bounds);

                foreach (var candidateCollider in candidateCollisionItems)
                {
                    if (Rectangle.Intersects(collidable.Bounds, candidateCollider.Bounds)
                        && candidateCollider != collidable)
                    {
                        var collisionInfo = new CollisionInfo(candidateCollider);
                        collidable.RespondToCollision(collisionInfo);
                    }
                }
            }

            this.objectsInPlane.Clear();
        }
        public static void HandleCollisions(IList<EnvironmentObject> objects)
        {
            foreach (var obj in objects)
            {
                collidingObjects.Insert(obj);
            }

            foreach (var obj in objects)
            {
                var candidateCollisionItems =
                    collidingObjects.GetItems(new List<ICollidable>(), obj.Bounds);
                foreach (var item in candidateCollisionItems)
                {
                    if (Rectangle.Intersects(obj.Bounds, item.Bounds) && item != obj)
                    {
                        var collisionInfo = new CollisionInfo(item);
                        obj.RespondToCollision(collisionInfo);
                    }
                }
            }

            collidingObjects.Clear();
        }
Esempio n. 4
0
 public abstract void RespondToCollision(CollisionInfo collisionInfo);
 public abstract void RespondToCollision(CollisionInfo collisionInfo);