LightningAngleLoop Actionscript

Table of contents | Previous document | Download LightningAngleLoop.as | SWF!T Homepage

RCSfile: LightningAngleLoop.as,v  Revision: 1.2  Date: 2003/02/14 03:44:59  

Copyright 2003 Orgdot AS. All Rights Reserved. http://dev.swfit.com
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


Loop script for the angled lightning.
author      Olaf Havnes
version     Revision: 1.2  Date: 2003/02/14 03:44:59  
since       SWFIT1.0



Build this bolt of lightning.

if (num_lightning < tot_lightning)
{

Set flags

   kill = false;
   plain = true;
   glow = false;

Duplicate the bottom clip

   lclip = "clip_" add num_lightning;
   right = eval ("right_" add bot_c);
   if (right) duplicateMovieClip ("right", lclip, num_lightning);
   else duplicateMovieClip ("left", lclip, num_lightning);
   setProperty (lclip, _y, - height_l * bot_c);
   setProperty (lclip, _x, bot_side_shift);
   bot_side_shift = right ? bot_side_shift - width_l : bot_side_shift + width_l;
   bot_c++;

   num_lightning++;

Duplicate the top clip

   lclip = "clip_" add num_lightning;
   right = eval ("right_" add top_c);
   top_side_shift = right ? top_side_shift + width_l: top_side_shift - width_l;
   if (right) duplicateMovieClip ("right", lclip, num_lightning);
   else duplicateMovieClip ("left", lclip, num_lightning);
   setProperty (lclip, _y, - height_l * top_c);
   setProperty (lclip, _x, top_side_shift);
   top_c--;

   num_lightning++;
}


Prepare for the next bolt of lightning.

if (bolt && num_lightning == tot_lightning)
{
   bolt = false;
   kill = true;
   tot_lightning = num_lightning + segs;
   bot_side_shift = 0;
   top_side_shift = 0;

Pre-generate some values

   i = 0;
   right = 0;
   while (i < segs)
   {
       remainder = segs - i;
       if (remainder == right || right == segs / 2 - 1)
       {
           set ("right_" add i, false);
           right --;
       }
       else if (remainder == - right || right == - segs / 2 + 1)
       {
           set ("right_" add i, true);
           right ++;
       }
       else
       {
           val = random (remainder - right) < remainder / 2;
           set ("right_" add i, val);
           right = val ? right + 1 : right - 1;
       }
       i++;
   }
   top_c = segs - 1;
   bot_c = 0;
}


Trigger the next bolt of lightning.

if (num_lightning == tot_lightning)
{
   glow_counter ++;
   if (glow_counter == glow_life)
   {
       glow_counter = 0;
       bolt = true;
   }
   else
   {
       pause++;
       if (pause >= frame_pause) pause = 0;

       if (pause == 1)
       {
           plain = false;
           glow = true;
       }
       else
       {
           plain = true;
           glow = false;
       }
   }
}