Example #1
0
        //---------------------
        // Collisions Check
        //---------------------

        #region
        private void CheckCollisions(GameElement element)
        {
            if (element is PlayerProjectile)
            {
                foreach (EnemyElement enemyElement in Controls.OfType <EnemyElement>())
                {
                    if (element.Bounds.IntersectsWith(enemyElement.Bounds))
                    {
                        if (enemyElement is EnemyProjectile)
                        {
                            Controls.Remove(enemyElement);
                        }
                        else
                        {
                            enemyElement.Health -= 1;
                            Controls.Remove(element);
                            return;
                        }
                    }
                }
            }
            else if (element is EnemyProjectile)
            {
                if (element.Bounds.IntersectsWith(player.Bounds))
                {
                    player.Health -= 1;
                    Controls.Remove(element);
                    return;
                }
            }

            if (element.CheckOutOfBounds())
            {
                Controls.Remove(element);
            }
        }