VG:Chain Lightning (VG2)

From MyProjectFun
Jump to: navigation, search

Here's a cool function for something similar to a chain lightning effect. Attach this function to the enemy. Credit to Tywen for the idea.

/// <summary>
/// Tywen's chain-lightning effect.
/// </summary>
public static void Tywen_ChainEnemyExplodeFN()
{
  // If I get shot
  if (This.Sprite.CollisionWithSprite("BulletCopy") != null)
  {
    // Change my name so I don't get found
    This.Sprite.Name = "EnemyExplode";
 
    // For each other enemy, check their distance
    for (int i = 0; This.Game.FindSprite("Enemy", i) != null; ++i)
    {
      // Get the sprite
      Sprite Enemy = This.Game.FindSprite("Enemy", i);
 
      // Get the direction vector
      Point2D direction = Enemy.Position - This.Sprite.Position;
 
      // Set up a kill-radius variable for ease
      float killRadius = 150;
 
      // If the distance is less than my kill-radius (both squared)
      if (direction.length2() <= killRadius * killRadius)
      {
        // Fire a bullet in that direction
        Sprite Bullet = new Sprite(This.Game.FindSprite("Bullet"));
        Bullet.Name = "BulletCopy";
        Bullet.Position = new Point2D(This.Sprite.Position);
        Bullet.Follow(Enemy, 7.0f, 0.0f);
        Bullet.Unused = false;
      }
    }
 
    // Then die
    This.Sprite.Delete();
  }
}
Personal tools
Namespaces
Variants
Actions
Navigation
Engineering
Game Design
Multimedia Production
VG Programming
Downloads
Toolbox