public void AddExplosion(Point ptExplosion, double timeFactor)
        {
            Explosion explosion = new Explosion(ptExplosion, timeFactor);

            explosions.Add(explosion);
        }
Example #2
0
        /// <summary>
        /// Updates the collisions.
        /// </summary>
        private void UpdateCollisions()
        {
            foreach (Projectile projectile in _projectiles)
            {
                if (projectile.Active)
                {
                    if (projectile.Hostile)
                    {
                        if (projectile.GetCircle().Intersects(_player.GetCircle()))
                        {
                            if (Circle.Intersects(projectile.GetCircles(), _player.GetCircles()))
                            {
                                projectile.Active = false;
                                NewLife();
                                break;
                            }
                        }
                    }
                    else
                    {
                        int pointsEarned = 0;
                        foreach (Satellite enemy in _enemies)
                        {
                            if (projectile.GetCircle().Intersects(enemy.GetCircle()))
                            {
                                if (Circle.Intersects(projectile.GetCircles(), enemy.GetCircles()))
                                {
                                    if (enemy.Accurate)
                                    {
                                        pointsEarned += 1000;
                                    }
                                    else
                                    {
                                        pointsEarned += 200;
                                    }
                                    enemy.Active      = false;
                                    projectile.Active = false;
                                    var explosion = new Explosion
                                    {
                                        Active   = true,
                                        Position = enemy.Position,
                                        Scale    = (float)enemy.Scale,
                                        Texture  = _ufoTexture,
                                        Velocity = new Vector2(2, 0)
                                    };
                                    _explosionSound.Play();
                                    _explosions.Add(explosion);
                                }
                            }
                        }
                        if (pointsEarned != 0)
                        {
                            AddPoints(pointsEarned);
                        }
                    }


                    foreach (Asteroid asteroid in _asteroids)
                    {
                        if (asteroid.Active)
                        {
                            if (asteroid.GetCircle().Intersects(projectile.GetCircle()))
                            {
                                asteroid.Active   = false;
                                projectile.Active = false;
                                if (projectile.Hostile == false)
                                {
                                    switch (asteroid.Generation)
                                    {
                                    case (1):
                                        AddPoints(20);
                                        break;

                                    case (2):
                                        AddPoints(50);
                                        break;

                                    case (3):
                                        AddPoints(100);
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }

            foreach (Asteroid asteroid in _asteroids)
            {
                if (asteroid.GetCircle().Intersects(_player.GetCircle()) &&
                    Circle.Intersects(asteroid.GetCircles(), _player.GetCircles()))
                {
                    NewLife();
                }
            }

            foreach (Satellite ufo in _enemies)
            {
                if (ufo.GetCircle().Intersects(_player.GetCircle()))
                {
                    if (Circle.Intersects(ufo.GetCircles(), _player.GetCircles()))
                    {
                        NewLife();
                        ufo.Active = false;
                        var explosion = new Explosion
                        {
                            Active   = true,
                            Position = ufo.Position,
                            Scale    = (float)ufo.Scale,
                            Texture  = _ufoTexture,
                            Velocity = new Vector2(2, 0)
                        };
                        _explosionSound.Play();
                        _explosions.Add(explosion);
                    }
                }
            }
        }