Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void CheckCollisions()
- {
- //Loop through each collision group (CG1)
- foreach (KeyValuePair<string, CollisionGroup> CG in CollisionGroups)
- {
- //Only process collision groups that both have objects and have something to collide with.
- if (CG.Value.Collidables.Count > 0 && CG.Value.CollidesWith.Count > 0)
- {
- //Loop through each collision group (CG2) that this group (CG1) can collide with
- foreach (string Key in CG.Value.CollidesWith)
- {
- //Does CG2 even exist?
- if (CollisionGroups.ContainsKey(Key))
- {
- //Only process if that collision group contains something to collide with
- if (CollisionGroups[Key].Collidables.Count > 0)
- {
- //Compare every object from CG1 against CG2
- foreach (Collidable C1 in CG.Value.Collidables)
- {//CG1 Tier
- foreach (Collidable C2 in CollisionGroups[Key].Collidables)
- {//CG2 Tier
- //Check if they collide with each other
- if (MathUtil.RectIntersect(C1.GetBounds(), C2.GetBounds()))
- {
- //Trigger the collision
- C1.Collision(C2);
- C2.Collision(C1);
- }
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement