Пример #1
0
 public void Update()
 {
     foreach (KeyValuePair <GameObject, Point> entry in objectsAndNewPoints)
     {
         HashSet <GameObject> possibleObjects = map.GetNearbyCollidableObjects(entry.Key);
         HashSet <GameObject> collidedObjects = new HashSet <GameObject>();
         foreach (GameObject obj in possibleObjects)
         {
             if (Intersect(entry.Key, entry.Value, obj))
             {
                 collidedObjects.Add(obj);
             }
         }
         if (collidedObjects.Count > 0)
         {
             if (entry.Key.IsSolid)
             {
                 foreach (GameObject obj in collidedObjects)
                 {
                     CollisionDirection direction = GetDirection(entry.Key, entry.Value, obj);
                     entry.Key.HandleCollision(direction, obj);
                     obj.HandleCollision(GetOppositeDirection(direction), entry.Key);
                 }
                 PlaceObject(entry.Key, entry.Value);
             }
             else
             {
                 HandleNonSolidCollisions(entry.Key, entry.Value, collidedObjects);
             }
         }
         else
         {
             PlaceObject(entry.Key, entry.Value);
         }
     }
     objectsAndNewPoints.Clear();
 }