public override void RespondToCollision(CollisionInfo collisionInfo) { if (collisionInfo.HitObject is Ground || collisionInfo.HitObject is Explosion) { this.Exists = false; } }
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(); }
public abstract void RespondToCollision(CollisionInfo collisionInfo);