BubbleTroubleInit Actionscript

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

RCSfile: BubbleTroubleInit.as,v  Revision: 1.2  Date: 2003/02/12 18:30:58  

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.


Init script for a single animated bubble.
author      Olaf Havnes
version     Revision: 1.2  Date: 2003/02/12 18:30:58  
since       SWFIT1.0


Are we the original clip ?

if (_name eq "bubble")
{
   _visible = false;
   stop ();
}


Hide the sub clips for now.

birth._visible = false;
burst._visible = false;
death._visible = false;

Life cycle data.


Parameters for our life cycle.

INCUBATE_MAX_LEN = 40;
GROW_MAX_LEN = 80;
DEATH_MAX_LEN = 30;

INCUBATE_MIN_LEN = 0;
GROW_MIN_LEN = 30;
DEATH_MIN_LEN = 5;

Let the burst frames be constant.

BURST_LEN = 2;

Set our specific life cycle

incubate = INCUBATE_MIN_LEN + random (INCUBATE_MAX_LEN - INCUBATE_MIN_LEN);
grow = incubate + GROW_MIN_LEN + random (GROW_MAX_LEN - GROW_MIN_LEN);
burst = grow + BURST_LEN;
death = burst + DEATH_MIN_LEN + random (DEATH_MAX_LEN - DEATH_MIN_LEN);

Start counting frames.

life = 0;

Movement data.


The basic speeds are common for all particles.

INCUBATE_SPEED = 0.5;
GROW_SPEED = 1;
BURST_SPEED = 0;
DEATH_SPEED = 0.5;

Parameters for the (cyclic) erratic movement.

AMPLITUDE_MAX = 15;
AMPLITUDE_MIN = 5;
AMPLITUDE_Y_DIVISOR = 10;

Pick a specific amplitude for the (cyclic) erratic movement.

amplitude = AMPLITUDE_MIN + random (AMPLITUDE_MAX - AMPLITUDE_MIN);


Parameters for our path through that amplitude.

AMPLITUDE_MAX_STEPS = 50;
AMPLITUDE_MIN_STEPS = 20;

Pick a specific number of steps through that amplitude.

steps = AMPLITUDE_MIN_STEPS + random (AMPLITUDE_MAX_STEPS - AMPLITUDE_MIN_STEPS);


Movement data - is empty, as we get the x/y coordinates from _parent when she clones us.



We're not going to mess with sin/cos functions here - instead we use the following iterating formula - see BubbleTroubleLoop.as for the rest of the algorithm:


s = Math.sin (Math.PI / steps);

s_0 = 0;
c_0 = amplitude;

s_1 = amplitude * s;
c_1 = amplitude * Math.cos (Math.PI / steps);

reverse_dir = random (50) > 25;