Advertisement
Guest User

Untitled

a guest
Aug 13th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. protected void CheckCollisions()
  2.         {
  3.  
  4.             //Loop through each collision group (CG1)
  5.             foreach (KeyValuePair<string, CollisionGroup> CG in CollisionGroups)
  6.             {
  7.  
  8.                 //Only process collision groups that both have objects and have something to collide with.
  9.                 if (CG.Value.Collidables.Count > 0 && CG.Value.CollidesWith.Count > 0)
  10.                 {
  11.  
  12.                     //Loop through each collision group (CG2) that this group (CG1) can collide with
  13.                     foreach (string Key in CG.Value.CollidesWith)
  14.                     {
  15.  
  16.                         //Does CG2 even exist?
  17.                         if (CollisionGroups.ContainsKey(Key))
  18.                         {
  19.  
  20.                             //Only process if that collision group contains something to collide with
  21.                             if (CollisionGroups[Key].Collidables.Count > 0)
  22.                             {
  23.  
  24.                                 //Compare every object from CG1 against CG2
  25.                                 foreach (Collidable C1 in CG.Value.Collidables)
  26.                                 {//CG1 Tier
  27.  
  28.                                     foreach (Collidable C2 in CollisionGroups[Key].Collidables)
  29.                                     {//CG2 Tier
  30.                                        
  31.                                         //Check if they collide with each other
  32.                                         if (MathUtil.RectIntersect(C1.GetBounds(), C2.GetBounds()))
  33.                                         {
  34.  
  35.                                             //Trigger the collision
  36.                                             C1.Collision(C2);
  37.                                             C2.Collision(C1);
  38.  
  39.                                         }
  40.  
  41.                                     }
  42.  
  43.                                 }
  44.  
  45.                             }
  46.  
  47.                         }
  48.  
  49.                     }
  50.  
  51.                 }
  52.  
  53.             }
  54.  
  55.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement