示例#1
0
        /// <summary>
        /// Проверяет столкновения для всех сталкиваемых игровых объектах.
        /// </summary>
        private void CollisionCheck()
        {
            var objects = CollidingObjects.ToList();

            for (var i = 0; i < objects.Count; i++)
            {
                for (var j = i + 1; j < objects.Count; j++)
                {
                    if (!LayerSettings.CheckCollision(objects[i].Layer, objects[j].Layer))
                    {
                        continue;
                    }
                    if (objects[i].Collider is null || objects[j].Collider is null)
                    {
                        continue;
                    }
                    var collision = Collider.Collide(objects[i].Collider, objects[j].Collider);
                    if (!collision.Collide)
                    {
                        continue;
                    }
                    if (!objects[i].Collider.IsTrigger && !objects[j].Collider.IsTrigger)
                    {
                        var massSum = objects[i].Mass + objects[j].Mass;
                        DisplacementObjectAfterCollision(objects[i], massSum, collision, 1);
                        DisplacementObjectAfterCollision(objects[j], massSum, collision, -1);
                    }
                    objects[i].Collision(objects[j]);
                    objects[j].Collision(objects[i]);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Проверяет столкновения для всех сталкиваемых игровых объектах.
        /// </summary>
        private void CollisionCheck(List <GameObject> gameObjects)
        {
            var objects = gameObjects.Where(o => o.IsColliding).ToList();

            for (var i = 0; i < objects.Count; i++)
            {
                for (var j = i + 1; j < objects.Count; j++)
                {
                    if (!LayerSettings.CheckCollision(objects[i].Layer, objects[j].Layer))
                    {
                        continue;
                    }
                    if (objects[i].Collider is null || objects[j].Collider is null)
                    {
                        continue;
                    }

                    Collide(objects[i], objects[j]);
                }
            }
        }