Exemplo n.º 1
0
        /// <summary>
        /// Detects and executes all collision functions of the objects that collide with eachother.
        /// </summary>
        /// <param name="sprites"></param>
        public void DetectCollisions(List <GameObject> sprites)
        {
            List <ICollidable> collidables = GetCollidableList(sprites);

            for (int i = 0; i < collidables.Count; i++)
            {
                if (collidables[i] is IInteractable)
                {
                    for (int j = 0; j < collidables.Count; j++)
                    {
                        if (i != j)
                        {
                            if (DetectCollision(collidables[i], collidables[j]))
                            {
                                IInteractable x = collidables[i] as IInteractable;
                                x.Collide(collidables[j]);
                                if (collidables[j] is IInteractable)
                                {
                                    IInteractable y = collidables[i] as IInteractable;
                                    y.Collide(collidables[i]);
                                }
                            }
                        }
                    }
                }
            }
        }