Beispiel #1
0
 /// <summary>
 /// The plant gets attacked by a vampire
 /// </summary>
 /// <param name="vampire">The attacker</param>
 internal void GetHit(Vampire vampire)
 {
     //Decrease the health based on vampire damage
     _health -= vampire.GetDamage();
 }
        /// <summary>
        /// Handles the projectile hitting a vampire
        /// </summary>
        internal void ProjectileHit()
        {
            // Loops from 0 to the amount of projectiles on the board.
            for (int i = 0; i < _sharedVariables.projectiles.Count; i++)
            {
                // Creates a projectile.
                Projectile projectile = _sharedVariables.projectiles[i];

                // Loops from 0 to the amount of vampires on the board.
                for (int j = 0; j < _sharedVariables.vampires.Count; j++)
                {
                    // Creates a vampire.
                    Vampire vampire = _sharedVariables.vampires[j];

                    // If the projectile is a bomb projectile.
                    if (projectile.Type == Projectile.ProjectileType.BombProjectile)
                    {
                        // Creates 3 imaginary rectangles one row above the projectile.
                        _imaginaryRectagles[0, 0] = new Rectangle((projectile.X - _sharedVariables.Width), (projectile.Y + _sharedVariables.Height), _sharedVariables.Width, _sharedVariables.Height);
                        _imaginaryRectagles[0, 1] = new Rectangle((projectile.X - _sharedVariables.Width), projectile.Y, _sharedVariables.Width, _sharedVariables.Height);
                        _imaginaryRectagles[0, 2] = new Rectangle((projectile.X + _sharedVariables.Width), (projectile.Y + _sharedVariables.Height), _sharedVariables.Width, _sharedVariables.Height);

                        // Creates 3 imaginary rectangles on the same row as the projectile.
                        _imaginaryRectagles[1, 0] = new Rectangle((projectile.X - _sharedVariables.Width), projectile.Y, _sharedVariables.Width, _sharedVariables.Height);
                        _imaginaryRectagles[1, 1] = new Rectangle(projectile.X, projectile.Y, _sharedVariables.Width, _sharedVariables.Height);
                        _imaginaryRectagles[1, 2] = new Rectangle((projectile.X + _sharedVariables.Width), projectile.Y, _sharedVariables.Width, _sharedVariables.Height);

                        // Creates 3 imaginary rectangles one row below the projectile.
                        _imaginaryRectagles[2, 0] = new Rectangle((projectile.X - _sharedVariables.Width), (projectile.Y - _sharedVariables.Height), _sharedVariables.Width, _sharedVariables.Height);
                        _imaginaryRectagles[2, 1] = new Rectangle(projectile.X, (projectile.Y - _sharedVariables.Height), _sharedVariables.Width, _sharedVariables.Height);
                        _imaginaryRectagles[2, 2] = new Rectangle((projectile.X + _sharedVariables.Width), (projectile.Y - _sharedVariables.Height), _sharedVariables.Width, _sharedVariables.Height);

                        // Loops from 0 to the constant cherry bomb splash radius.
                        for (int x = 0; x < SharedVariables.CHERRY_BOMB_SPLASH_RADIUS; x++)
                        {
                            // Loops from 0 to the constant cherry bomb splash radius.
                            for (int y = 0; y < SharedVariables.CHERRY_BOMB_SPLASH_RADIUS; y++)
                            {
                                // If the vampire intersects with the specific imaginary rectangle.
                                if (vampire.Bounds.IntersectsWith(_imaginaryRectagles[x, y]))
                                {
                                    // Calls the vampire to get hit.
                                    vampire.GetHit(projectile);
                                }
                            }
                        }
                    }

                    // If the projectile is a mine projectile.
                    else if (projectile.Type == Projectile.ProjectileType.MineProjectile)
                    {
                        // Checks if the vampire intersects with the projectile.
                        if (vampire.Bounds.IntersectsWith(projectile.Bounds))
                        {
                            // Calls the vampire to get hit.
                            vampire.GetHit(projectile);
                        }
                    }

                    // Otherwise
                    else
                    {
                        // Creates a rectangle to store the bounds of the vampire.
                        Rectangle customBounds = vampire.Bounds;

                        // If the vampire is a weak vampire.
                        if (vampire is WeakVampire)
                        {
                            // Increase the x coordinate of the vampire bounds rectangle by the amount of the constant side offset (for the transparent image).
                            customBounds.X += WeakVampire.SIDE_OFFSET;
                        }

                        // If the bounds of the vampire intersect with the projectile's bounds.
                        if (customBounds.IntersectsWith(projectile.Bounds))
                        {
                            // Calls the vampire to get hit.
                            vampire.GetHit(projectile);

                            // Calls the projectile to be removed from the board.
                            _sharedVariables.projectiles.Remove(projectile);
                        }
                    }

                    // If the vampire's health is less than or equal to 0.
                    if (vampire.GetHealth() <= 0)
                    {
                        // Calls the vampire to be removed from the board.
                        _sharedVariables.vampires.Remove(vampire);
                    }
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// The player gets hit
 /// </summary>
 /// <param name="vampire">The attacker</param>
 internal void GetHit(Vampire vampire)
 {
     vampire.Attack(player);
 }