GroundLoop Actionscript

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

RCSfile: GroundLoop.as,v  Revision: 1.1  Date: 2003/04/20 13:13:18  

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 for a ground generator - uses values from SmoothNoiseLoop.as.
author      Olaf Havnes
version     Revision: 1.1  Date: 2003/04/20 13:13:18  
since       SWFIT1.0


We need to loop up a full landscape before we start.

if (do_init)
{
   do_init = false;

   while (clip_counter < NUM_CLIPS)
   {

Fetch another point from the noise function

       grid_counter ++;
       if (grid_counter >= GRID_SIZE)
       {
           grid_counter = 0;
           which_point++;
           if (which_point >= _level0.NOISE_NUM_POINTS) which_point = 0;
       }
       val_x = grid_counter / GRID_SIZE;

Get the pre-defined script.

       #include "../_scripts/SmoothNoiseLookup.as"
       val_y *= SCALE_FACTOR;

Which existing building block do we duplicate?

       duplicator = "level";
       if (val_y > prev_clip_y + STEP)
       {
           duplicator = "down";
           prev_clip_y += STEP;
       }
       else if (val_y < prev_clip_y - STEP)
       {
           duplicator = "up";
           prev_clip_y -= STEP;
       }

       clip_name = "clip_" add clip_counter;
       duplicateMovieClip (duplicator, clip_name, clip_counter);

       setProperty (clip_name, _x, clip_x);
       clip_x += step;
       setProperty (clip_name, _y, prev_clip_y);


       clip_counter++;
   }
   clip_counter--;

   clip_x -= step;
   _x -= clip_x;
}

Reverse scroll this clip

_x -= 1;

Take note of the scroll value,

clip_x++;

Should we draw another piece?

step_counter++;
if (step_counter >= STEP)
{

Fetch another point from the noise function

   grid_counter ++;
   if (grid_counter >= GRID_SIZE)
   {
       grid_counter = 0;
       which_point++;
       if (which_point >= _level0.NOISE_NUM_POINTS) which_point = 0;
   }
   val_x = grid_counter / GRID_SIZE;

Get the pre-defined script.

   #include "../_scripts/SmoothNoiseLookup.as"
   val_y *= SCALE_FACTOR;

Which existing building block do we duplicate?

   duplicator = "level";
   if (val_y > prev_clip_y + STEP)
   {
       duplicator = "down";
       prev_clip_y += STEP;
   }
   else if (val_y < prev_clip_y - STEP)
   {
       duplicator = "up";
       prev_clip_y -= STEP;
   }

   clip_counter++;
   if (clip_counter >= NUM_CLIPS) clip_counter = 0;
   clip_name = "clip_" add clip_counter;
   duplicateMovieClip (duplicator, clip_name, clip_counter);

   setProperty (clip_name, _x, clip_x);
   setProperty (clip_name, _y, prev_clip_y);

   step_counter = 0;
}