public override void Update(GameTime gameTime) { base.Update(gameTime); for (int i = 0; i < objects.Count; ++i) { ICollidableObject obj1 = objects[i]; for (int j = i + 1; j < objects.Count; j++) { ICollidableObject obj2 = objects[j]; if (obj1.CheckCollision(obj2)) { if (!collidingObjects.Contains(obj1)) { collidingObjects.Add(obj1); collidingObjects.Add(obj2); if (this.ObjectsCollided != null) { CollisionEventArgs args = new CollisionEventArgs(obj1, obj2); this.ObjectsCollided(this, args); } } } else { collidingObjects.Remove(obj1); collidingObjects.Remove(obj2); } } } }
public static CollisionLifetimeEntry Acquire(ICollidableObject a, ICollidableObject b, float timeOfCollision) { var instance = Acquire(); instance.Reset(a, b, timeOfCollision); return(instance); }
public void AddCollidable(ICollidableObject collidable) { if (!objects.Contains(collidable)) { this.objects.Add(collidable); } }
protected void CheckCollisionFor(ICollidableObject primary, ICollidableObject secondary) { CollisionRuleEntry collisionRule; if (CollisionRules.CanCollide(primary.CollisionClass, secondary.CollisionClass, out collisionRule)) { ICollisionLifetimeEntry collisionEntry = null; //Check the collision lifetime tracker. If there is already a collision lifetime entry being tracked, do nothing and return. if (_collisionLifetimes.Contains(primary, secondary, out collisionEntry)) { //The specified entities have collided before. Check to see if this collision time is last the cooldown period if ((collisionRule != null) && !collisionEntry.CanCollideAgain(collisionRule.Cooldown, Globals.TotalGameTimeSeconds)) { return; } } if (CollisionChecker.AreInCollision(primary, secondary)) { if (collisionRule == null || collisionRule.TrackLifeTime) { _collisionLifetimes.Add(primary, secondary, Globals.TotalGameTimeSeconds); } _onCollision.Notify(new CollisionEventArgs(primary, secondary)); } } }
private void Detach() { _a.OnReleased.Remove(_onTrackedCollidablesReleased); _b.OnReleased.Remove(_onTrackedCollidablesReleased); _a = null; _b = null; }
public bool Intersects(ICollidableObject collidableObject) { if (null == collidableObject || null == CollisionExtent) { return(false); } return(CollisionExtent.Intersects(CollisionMode, collidableObject.CollisionExtent, collidableObject.CollisionMode)); }
public static int GetCombinedHash(ICollidableObject a, ICollidableObject b) { if (null == a || null == b) { return(InvalidCombinedHash); } return(a.GetHashCode() ^ b.GetHashCode()); }
/// <summary> /// Checks to see if this class contains a collision record for the two specified collidable objects. /// </summary> /// <param name="a">The first collision participant. Order does not matter.</param> /// <param name="b">The second collision participant. Order does not matter.</param> /// <returns>True if these two entities have collided in the past, false otherwise.</returns> public bool Contains(ICollidableObject a, ICollidableObject b) { if (null == a || null == b) { return(false); } return(_entries.ContainsKey(a.GetHashCode() ^ b.GetHashCode())); }
public void Execute(IGameObject gameObject, IGameObject collidedWith) { ICollidableObject trigger = (ICollidableObject)collidedWith; if (Game1.GetLevel().Players.Any(e => !e.BoundingBox.Intersects(trigger.BoundingBox))) { return; } ((CameraFocusTrigger)collidedWith).ActivateTrigger(); }
public static CollisionInteractionType GetCollisionInteractionType(ICollidableObject a, ICollidableObject b) { CollisionInteractionType type = CollisionInteractionType.Invalid; if ((null == a) || (null == b)) { return(type); } if (a == b) { return(type); } return(GetCollisionInteractionType(a.CollisionMode, b.CollisionMode)); }
public bool Add(ICollidableObject a, ICollidableObject b, float timeOfCollision) { int hash = CollisionLifetimeEntry.GetCombinedHash(a, b); if (_entries.ContainsKey(hash)) { //There is already a collision recorded for this entry, update the latest time at which it occured instead. _entries[hash].TimeOfCollision = timeOfCollision; return(true); } else { var toAdd = CollisionLifetimeEntry.Acquire(a, b, timeOfCollision); _entries.Add(hash, toAdd); return(base.Add(toAdd)); } }
private void Attach(ICollidableObject a, ICollidableObject b) { if (null == a) { throw new ArgumentNullException("a"); } if (null == b) { throw new ArgumentNullException("b"); } _a = a; _b = b; _a.OnReleased.Add(_onTrackedCollidablesReleased); _b.OnReleased.Add(_onTrackedCollidablesReleased); }
public void Execute(IGameObject gameObject, IGameObject collidedWith) { ICollidableObject door = (ICollidableObject)collidedWith; if (Game1.GetLevel().CurrentWorldState >= WorldState.Transitioning || Game1.GetLevel().Players.Any(e => !e.BoundingBox.Intersects(door.BoundingBox))) { return; } Game1.GetLevel().CurrentWorldState = WorldState.Transitioning; foreach (var player1 in Game1.GetLevel().Players) { var player = (IPhysicsObject)player1; player.IsKinematic = true; } DoorTransitionTrigger trigger = (DoorTransitionTrigger)collidedWith; trigger.ActivateTrigger(); }
/// <summary> /// Checks to see if this class contains a collision record for the two specified collidable objects. /// </summary> /// <param name="a">The first collision participant. Order does not matter.</param> /// <param name="b">The second collision participant. Order does not matter.</param> /// <param name="entry">The out parameter containing the collision record details.</param> /// <returns>True if these two entities have collided in the past, false otherwise.</returns> public bool Contains(ICollidableObject a, ICollidableObject b, out ICollisionLifetimeEntry entry) { entry = null; if (null == a || null == b) { return(false); } int hashCode = a.GetHashCode() ^ b.GetHashCode(); if (_entries.ContainsKey(hashCode)) { entry = _entries[hashCode]; return(true); } else { return(false); } }
public static bool AreInCollision(ICollidableObject a, ICollidableObject b) { if ((null == a) || (null == b)) { return(false); } if ((!a.IsCollidable) || (!b.IsCollidable)) { return(false); } CollisionInteractionType collisionType = GetCollisionInteractionType(a, b); if (collisionType == CollisionInteractionType.Invalid) { return(false); } return(a.Intersects(b)); }
public void RemoveCollidable(ICollidableObject collidable) { objects.Remove(collidable); collidingObjects.Remove(collidable); }
/// <summary> /// /// </summary> public void Add(ICollidableObject item) { collisionManager.Add(item); }
/// <summary> /// Remove item from the list of objects /// </summary> public void Remove(ICollidableObject item) { objectList.Remove(item); }
public CollisionEventArgs(ICollidableObject a, ICollidableObject b) { _a = a; _b = b; }
/// <summary> /// Remove item from the list of objects /// </summary> public void Remove(ICollidableObject item) { objectList.Remove(item); }
public void Remove(ICollidableObject item) { collisionManager.Remove(item); }
public bool Remove(ICollidableObject a, ICollidableObject b) { return(Remove(a.GetHashCode() ^ b.GetHashCode())); }
private void Reset(ICollidableObject a, ICollidableObject b, float timeOfCollision) { Attach(a, b); TimeOfCollision = timeOfCollision; }
public void Remove(ICollidableObject item) { collisionManager.Remove(item); }
/// <summary> /// /// </summary> public void Add(ICollidableObject item) { collisionManager.Add(item); }
public CollisionEventArgs(ICollidableObject source, ICollidableObject target) { this.SourceObject = source; this.TargetObject = target; }
/// <summary> /// Add item to the list of objects to check for collision /// </summary> public void Add(ICollidableObject item) { objectList.Add(item); }
public CollisionObject(ICollidableObject item1, ICollidableObject item2) { Item1 = item1; Item2 = item2; }
public CollisionObject(ICollidableObject item1, ICollidableObject item2) { Item1 = item1; Item2 = item2; }
/// <summary> /// Add item to the list of objects to check for collision /// </summary> public void Add(ICollidableObject item) { objectList.Add(item); }