private void UpdateCollisions() { // To start afresh if (m_Collisions.Count > 0) { m_Collisions.Clear(); } for (int i = 0; i < m_Collidables.Count; i++) { for (int j = 0; j < m_Collidables.Count; j++) { // Looping through one object with every other Collidable collidable1 = m_Collidables[i]; Collidable collidable2 = m_Collidables[j]; // Making sure they're not same if (!collidable1.Equals(collidable2)) { // If the collision test is successful, then // add a new collsion betweeen the two objects if (collidable1.CollisionTest(collidable2)) { m_Collisions.Add(new Collision(collidable1, collidable2)); } } } } }
// To avoid repeated collision tests public bool Equals(Collision other) { if (other == null) { return(false); } if (A.Equals(other.A) && B.Equals(other.B)) { return(true); } return(false); }