// Initialize particle effects manager
function ParticleFx::onWake(%this)
{
   %this.HintParticleIndex = 1;   
   
   %this.particleMax = 3000;
   %this.particleInUse = -1;
   
   %this.particleRippleMax = 10;
   %this.particleRippleInUse = -1;   

   // ParticleDir
   for(%i=1; %i<5; %i++)
   {
      %obj = ("ParticleDir"@%i);
      if(isObject(%obj))
      {
         %obj.setVisible(false);
         %obj.alpha = "1";
      }
   }
   
   %this.particleIdxTable = 0;   
   
   // Create particles
   for(%i=0; %i<%this.particleMax; %i++)
   {
      %obj = ("P"@%i);
      if(!isObject(%obj))      
         %newP = new GuiPlasticBitmapCtrl(%obj);
      else
         %newP = %obj;
      %newP.useAddBlending = "1";         
      %newP.setVisible(false);
      ParticleFx.add(%newP);
   }
   
   // Create ripple particles
   for(%i=0; %i<%this.particleRippleMax; %i++)
   {
      %obj = ("PRipple"@%i);
      if(!isObject(%obj))      
         %newP = new GuiPlasticBitmapCtrl(%obj);
      else
         %newP = %obj;
      %newP.useAddBlending = "1";
      %newP.setVisible(false);
      ParticleFx.add(%newP);
   }
}

// Returns the ID of a particle
function ParticleFx::getAvailableParticle(%this)
{     
   %this.particleInUse++;
   
   return %this.particleInUse % %this.particleMax;
}

// Returns the ID of a ripple particle
function ParticleFx::getAvailableRippleParticle(%this)
{     
   %this.particleRippleInUse++;
   
   return %this.particleRippleInUse % %this.particleRippleMax;
}

// Produces a ripple effect
// %x and %y are the screen location of the particle generation
// %speed is the speed of particle update, in ms
// %scale is a scale factor of the particle
// %isCorrect TRUE for using ripple_correct files, FALSE for ripple_incorrect
function ParticleFx::RippleFx(%this, %x, %y, %speed, %scale, %isCorrect)
{
   %idx = %this.getAvailableRippleParticle();
   %obj = ("PRipple"@%idx);
   
   %path = "scriptsAndAssets/data/ui/ho/particles/";
   if(%isCorrect) 
      %path = %path @ "rcorrect/";
   else
      %path = %path @ "rwrong/";
         
   %obj.setDML(%path @ "ripple.dml");
   
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);   
   
   %sizeX = 100 * %scale * %winScaleX;   
   %sizeY = 100 * %scale * %winScaleY;
   
   %obj.stop();   
   %obj.rewind();
   %obj.setExtent(%sizeX, %sizeY);
   %obj.setPosition(%x-(%sizeX/2), %y-(%sizeY/2));
   %obj.rotation = "0";   
   %obj.deltaRotation = "0";
   %obj.aniTime = "0";
   
   %obj.setFps(0);
   %obj.play(1);

   %obj.setAlpha(1);
   %obj.setVisible(true);

   scheduleObjLCA(%this, "HO", 800, "onRippleDeath", 1, %idx);
}

// Produces a fireworks effect
// %x and %y are the screen location of the particle generation
// %aniTime is the total animation time, in seconds
// %scale is a scale factor of the particle
function ParticleFx::FireworksFx(%this, %x, %y, %aniTime, %scale)
{
   %scalex = %scale * (1.0 / 800 * getWord(GuiCenter.getExtent(),0));
   %scaley = %scale * (1.0 / 600 * getWord(GuiCenter.getExtent(),1));
/*   
   %file = "scriptsAndAssets/data/ui/ho/particles/particle_star_50small.png";
   
   %winScaleX = 1.0 / 800 * getWord(canvas.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(canvas.getExtent(),1);   
   
   %sizeX = 19 * %scale * %winScaleX;   
   %sizeY = 18 * %scale * %winScaleY;
   
   %origX = %x - (%sizeX / 2);
   %origY = %y - (%sizeY / 2);
   
   setRandomSeed(getRealTime());   
*/
   %this.particleIdxTable++;
   %this.particleIdxNum[%this.particleIdxTable] = 0;

   for(%i=0; %i<100; %i++) // 15
   {
      %idx = %this.getAvailableParticle();
         
      %this.particleTable[%this.particleIdxTable, %this.particleIdxNum[%this.particleIdxTable]] = %idx;
      %this.particleIdxNum[%this.particleIdxTable]++;
      
      ("P"@%idx).particleFireworks(%x, %y, %aniTime, %scalex, %scaley);      
/*         
      %obj = ("P"@%idx);
      
//      %obj.rewind();
      %obj.setExtent(%sizeX, %sizeY);
      %obj.setPosition(%origX, %origY);
      %obj.setDML(%file);
      %obj.setVisible(true);
//      %obj.alpha = "1";
      %obj.aniTime = %aniTime;
      %obj.deltaRotation = getRandom(-360,360);
         
      // Determine direction vector
      %pi = 3.14159265;
      %piHalf = %pi/2;
      %randVal1 = getRandom(1000000) / 1000000;
      %randVal2 = getRandom(1000000) / 1000000;
      %CurVecX = mSin(%randVal1 * %pi*2 - %pi);
      %CurVecY = -mAbs(mCos(%randVal2 * %pi*2 - %pi));
      
      %randVal3 = getRandom(1000000) / 1000000;
      %randVal4 = getRandom(1000000) / 1000000;
      %CurVecX += (%randVal3 - 0.5)/2;
      %CurVecY -= (%randVal4 - 0.25)/2;
      
      new ScriptObject(AniKeyPoints)  
      {  
         duration = %aniTime; // seconds  
         ease = "0 0"; // ease type
      };
       
      %AniTimeSum = 0;
      %AniSteps = 5 + getRandom(30);
      %CurT = 0;
      %Gravity = 0;
      %GravityInc = 0;
      for(%j=0; %j < %AniSteps; %j++)
      {
         %NewValX = (%CurVecX*%CurT)+%OrigX;
         %NewValY = (%CurVecY*%CurT)+%OrigY + mPow(%GravityInc,3);
         AniKeyPoints.value[%j] = %NewValX SPC %NewValY;
         AniKeyPoints.time[%j] = %AniTimeSum;
         %AniTimeSum += %aniTime / %AniSteps;
         %CurT += 8;
         if(%CurVecY > 0)
            %GravityInc += 1.5;
         else
            %GravityInc += 0.4;
      }
      %obj.animateCenterKeyPointList(AniKeyPoints,0);
      
      %colorAniTime = %aniTimeSum*1000 - getRandom(0,(%AniTimeSum*1000)/2);
      %obj.animateAlpha(0, 0, %colorAniTime, "0 0");
      %vl = getRandom(48,128);
      %obj.animateColor(128+%vl, 128+%vl, 128, 0, %colorAniTime, "0 0");
//      scheduleObjLCA(%this, "HO", %aniTimeSum*1000, "onDeath", 1, %idx);
      
      AniKeyPoints.delete();      */
   }
     
   %particleIdx = %this.particleIdxTable;
   %particleNum = %this.particleIdxNum[%this.particleIdxTable];
   scheduleObjLCA(%this, "HO", %aniTime*1000, "onDeathGroup", 2, 
      %particleIdx, %particleNum);   
}

// Hide sparkle when end of animation is reached
function ParticleFx::onDeathGroup(%this, /*%idxFirst, %idxNum*/%idxTable, %idxNum)  
{
   for(%i=0; %i<%idxNum; %i++)
//      ("P"@%this.particleTable[%idxTable, %i]).delete();
      ("P"@%this.particleTable[%idxTable, %i]).setVisible(false);

//   for(%i=0; %i<%idxNum; %i++)
//      ("P"@%idxFirst+%i).delete();   
}

// Produces a comet effect going from (%x,%y) to the
// director meter
// %x and %y are the screen location of the particle fx start position
// %aniTime is the total animation time, in seconds
// %scale is a scale factor of the particle
// %fileType: 0 for star, 1 for cheese
function ParticleFx::CometDirectorFx(%this, %x, %y, %aniTime, %scale, %fileType)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   %scale2 = %scale;
   if(%fileType > 0)
      %scale2 = 1.25;
   
   // Compute vector V
   if($pref::MeterPositionRight $= "true" || $pref::MeterPositionRight $= 1)
      %direcX = 645;
   else
      %direcX = 34;   

   %obj = DirectorMeter.getObject(SceneGui.directorMeterCur);
   %direcY = getWord(%obj.getPosition(),1) + 10;

   %direcX *= %winScaleX;
   
   %vecX = %direcX - %x;
   %vecY = %direcY - %y;
   
   %vecLen = mSqrt(%vecX*%vecX + %vecY*%vecY);
   
   %steps = %vecLen / 40;
   %stepsize = 1 / %steps;
   for(%t=0; %t<=1;)
   {
      %curX = (%vecX*%t)+%x;
      %curY = (%vecY*%t)+%y;
      
      %time = %aniTime*1000*%t;
      scheduleObjLCA(%this, "HO", %time, "CometDirectorFxHelper", 6, 
         %vecX, %vecY, %curX, %curY, %scale2, %fileType);   

      %stepsize = 1 / (%steps + getRandom(50));
      %t+=%stepsize;
   }
   
   %idx = %this.getAvailableParticle();
   %obj = ("P"@%idx);      
 
   %sizeX = 19 * %scale2 * %winScaleX;   
   %sizeY = 18 * %scale2 * %winScaleY;
   
   %origX = %x - (%sizeX / 2);
   %origY = %y - (%sizeY / 2);
   
   %obj.rewind();
   %obj.setExtent(%sizeX, %sizeY);
   %obj.setPosition(%origX, %origY);
   
	switch(%fileType)
	{
	case 0: %obj.setDML("scriptsAndAssets/data/ui/ho/particles/spark/small_spark.png");
	case 1: %obj.setDML("scriptsAndAssets/data/videos/sparkle/particle_cheese.png");
	case 2: %obj.setDML("scriptsAndAssets/data/ui/ho/particles/spark/spark.png");
	}

   %obj.setVisible(true);
   %obj.alpha = "1";
   %obj.aniTime = %aniTime;

   %obj.animateCenter(%direcX+%sizeX/2, %direcY+%sizeY/2, 0, %aniTime*1000, "0 0");
   scheduleObjLCA(%this, "HO", %aniTime*1000, "onDeath", 1, %idx);
   
//   scheduleObjLCA(%this, "HO", %aniTime*1000, "CometHitMeterFx", 5, 
//      %direcX, %direcY, %aniTime*2, %scale);   
}

// Produces a comet effect going from (%x,%y) to (%destX, %destY) 
// %aniTime is the total animation time, in seconds
// %scale is a scale factor of the particle
function ParticleFx::CometGenericFx(%this, %origX, %origY, %destX, %destY, %aniTime, %scale)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
        
   %vecX = %destX - %origX;
   %vecY = %destY - %origY;
   
   %vecLen = mSqrt(%vecX*%vecX + %vecY*%vecY);
   
   %steps = %vecLen / 40;
   %stepsize = 1 / %steps;
   for(%t=0; %t<=1;)
   {
      %curX = (%vecX*%t)+%origX;
      %curY = (%vecY*%t)+%origY;
      
      %time = %aniTime*1000*%t;
      scheduleObjLCA(%this, "HO", %time, "CometDirectorFxHelper", 6, 
         %vecX, %vecY, %curX, %curY, %scale, 0);   

      %stepsize = 1 / (%steps + getRandom(50));
      %t+=%stepsize;
   }
/*   
   %idx = %this.getAvailableParticle();
   %obj = ("P"@%idx);      
 
   %sizeX = 19 * %scale * %winScaleX;   
   %sizeY = 18 * %scale * %winScaleY;
   
   %origX = %x - (%sizeX / 2);
   %origY = %y - (%sizeY / 2);
   
   %obj.rewind();
   %obj.setExtent(%sizeX, %sizeY);
   %obj.setPosition(%origX, %origY);
	%obj.setDML("scriptsAndAssets/data/ui/ho/particles/spark/small_spark.png");
   %obj.setVisible(true);
   %obj.alpha = "1";
   %obj.aniTime = %aniTime;

   %obj.animateCenter(%destX+%sizeX/2, %destY+%sizeY/2, 0, %aniTime*1000, "0 0");
   scheduleObjLCA(%this, "HO", %aniTime*1000, "onDeath", 1, %idx); */
}

// Produces a cascading effect from (%x,%y) to the right side of the screen
// %x and %y are the screen location of the particle fx start position
// %aniTime is the total animation time, in seconds
// %scale is a scale factor of the particle
function ParticleFx::CometHitMeterFx(%this, %x, %y, %aniTime, %scale)
{   
   %scalex = %scale * (1.0 / 800 * getWord(GuiCenter.getExtent(),0));
   %scaley = %scale * (1.0 / 600 * getWord(GuiCenter.getExtent(),1));
   
/*   %file = "scriptsAndAssets/data/ui/ho/particles/particle_star_50small.png";
   
   %winScaleX = 1.0 / 800 * getWord(canvas.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(canvas.getExtent(),1);   
   
   %sizeX = 19 * %scale * %winScaleX;   
   %sizeY = 18 * %scale * %winScaleY;
   
   %origX = %x - (%sizeX / 2);
   %origY = %y - (%sizeY / 2);
*/
   // Profiling start
//   %startTime = getRealTime();

   setRandomSeed(getRealTime());   
   
   %this.particleIdxTable++;
   %this.particleIdxNum[%this.particleIdxTable] = 0;   
     
   for(%i=0; %i<70; %i++)
   {
      %idx = %this.getAvailableParticle();
         
      %this.particleTable[%this.particleIdxTable, %this.particleIdxNum[%this.particleIdxTable]] = %idx;
      %this.particleIdxNum[%this.particleIdxTable]++;         
         
      ("P"@%idx).particleHitMeter(%x, %y, %aniTime, %scalex, %scaley);
/*
      %obj = ("P"@%idx);
//      %obj.rewind();
      %obj.setExtent(%sizeX, %sizeY);
      %obj.setPosition(%origX, %origY);
      %obj.setDML(%file);
      %obj.setVisible(true);
//      %obj.alpha = "1";
      %obj.aniTime = %aniTime;
      %obj.deltaRotation = getRandom(-360,360);
               
      // Determine direction vector
      %pi = 3.14159265;
      %piHalf = %pi/2;
      %randVal1 = getRandom(1000000) / 1000000;
      %randVal2 = getRandom(1000000) / 1000000;
      %CurVecX  = mAbs(mSin(%randVal1 * %pi*2 - %pi));
      %CurVecY  = -mAbs(mCos(%randVal2 * %pi*2 - %pi));
      
      new ScriptObject(AniKeyPoints)  
      {  
         duration = %aniTime; // seconds  
      };
       
      %AniTimeSum = 0;
      %AniSteps = 5 + getRandom(10);
      %CurT = 0;
      %Gravity = 0;
      %GravityInc = 0;
      for(%j=0; %j < %AniSteps; %j++)
      {
         %NewValX = (%CurVecX*%CurT)+%OrigX;
         %NewValY = (%CurVecY*%CurT)+%OrigY + mPow(%GravityInc,2.5);
         AniKeyPoints.value[%j] = %NewValX SPC %NewValY;
         AniKeyPoints.time[%j] = %AniTimeSum;
         %AniTimeSum += %aniTime / %AniSteps;
         %CurT += 15;
         %GravityInc += 0.7;
      } 
      %obj.animateCenterKeyPointList(AniKeyPoints,0);
      %colorAniTime = %aniTimeSum*1000 - getRandom(0,(%AniTimeSum*1000)/2);      
      %obj.animateAlpha(0, 0, %colorAniTime, "0 0");
      %vl = getRandom(48,128);      
      %obj.animateColor(128+%vl, 128+%vl, 128, 0, %colorAniTime, "0 0");      
//      scheduleObjLCA(%this, "HO", %aniTimeSum*1000, "onDeath", 1, %idx);
      
      AniKeyPoints.delete(); */
   }
   
   %particleIdx = %this.particleIdxTable;
   %particleNum = %this.particleIdxNum[%this.particleIdxTable];

   scheduleObjLCA(%this, "HO", %aniTime*1000, "onDeathGroup", 2, %particleIdx, %particleNum);
   
   // Profiling end   
//   %endTime = getRealTime();
//   echo("Time elapsed for effect: "@%endTime - %startTime);      
}

// Helper function of CometDirectorFx
// Creates a new particle and trail at %x and %y
// %vecX and %vecY define the direction vector of the comet
function ParticleFx::CometDirectorFxHelper(%this, %vecX, %vecY, %x, %y, %scale, %fileType)
{
   %scalex = %scale * (1.0 / 800 * getWord(GuiCenter.getExtent(),0));
   %scaley = %scale * (1.0 / 600 * getWord(GuiCenter.getExtent(),1));
     
//   setRandomSeed(getRealTime());   
   
   %this.particleIdxTable++;
   %this.particleIdxNum[%this.particleIdxTable] = 0;
   
   %aniTime = 1;
     
   for(%i=0; %i<5; %i++)
   {
      %idx = %this.getAvailableParticle();
         
      %this.particleTable[%this.particleIdxTable, %this.particleIdxNum[%this.particleIdxTable]] = %idx;
      %this.particleIdxNum[%this.particleIdxTable]++;
      ("P"@%idx).particleComet(%vecX, %vecY, %x, %y, %scalex, %scaley, %fileType, %aniTime);
   }

   %particleIdx = %this.particleIdxTable;
   %particleNum = %this.particleIdxNum[%this.particleIdxTable];
   scheduleObjLCA(%this, "HO", %aniTime*1000, "onDeathGroup", 2, 
      %particleIdx, %particleNum);   
   
   return;
/*   
   %pi = 3.14159265;
   %piHalf = %pi/2;
      
   %winScaleX = 1.0 / 800 * getWord(canvas.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(canvas.getExtent(),1);
   
   %sizeX = 19 * %scale * %winScaleX;   
   %sizeY = 18 * %scale * %winScaleY;
   
   %origX = %x - (%sizeX / 2);
   %origY = %y - (%sizeY / 2);
   
   setRandomSeed(getRealTime());

   // From this point, generate N particles travelling
   // in the opposite direction +90 degs and -90 degs
   %aniTime = 1;
   %aniSteps = 5 + getRandom(10);
  
   for(%i=0; %i<1; %i++) // 1
   {
      // Compute direction vector
      %curVecX = -%vecX;
      %curVecY = -%vecY;

      // Normalize direction vector      
      %vecLen = mSqrt(%curVecX*%curVecX + %curVecY*%curVecY);
      %curVecX /= %vecLen;
      %curVecY /= %vecLen;      
      
      // Apply deviation      
      %randAng = -%piHalf + (getRandom(1000000) / 1000000) * %pi;
      %randAng /= 1.5;
      %curVecX = %curVecX*mCos(%randAng)-%curVecY*mSin(%randAng);
      %curVecY = %curVecX*mSin(%randAng)+%curVecY*mCos(%randAng);

      %idx = %this.getAvailableParticle();
      
      %obj = ("P"@%idx);      
      
      %obj.rewind();
      %obj.setExtent(%sizeX, %sizeY);
      %obj.setPosition(%origX, %origY);
      %obj.setDML(%file);
      %obj.setVisible(true);
      %obj.alpha = "1";
      %obj.aniTime = %aniTime;
//      %obj.deltaRotation = getRandom(-360,360);
      
      %curX = %curVecX*(20+getRandom(100))+%origX;
      %curY = %curVecY*(20+getRandom(100))+%origY;
      %obj.animateCenter(%curX+%sizeX/2, %curY+%sizeY/2, 0, %aniTime*1000, "0 0");      
      %obj.animateAlpha(0, 0, %aniTime*1000, "0 0");
      scheduleObjLCA(%this, "HO", (%aniTime+1)*1000, "onDeath", 1, %idx);
   } */
}

// Hide particle when end of animation is reached
function ParticleFx::onDeath(%this, %idx)  
{
   ("P"@%idx).setVisible(false);//delete();
}

// Hide ripple particle when end of animation is reached
function ParticleFx::onRippleDeath(%this, %idx)  
{
   ("PRipple"@%idx).animateAlpha(0, 0, 100, "0 0");
}

function ParticleFx::DirectorParticles(%this, %particlePath, %scale, %aniTime)
{
   if(SceneGui.directorBehaviorBusy)
      return;
      
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);         
      
   for(%i=1; %i<=4; %i++)
   {
      if($pref::MeterPositionRight $= "true" || $pref::MeterPositionRight $= 1)
         %origX = getRandom(625, 650) * %winScaleX;
      else
         %origX = getRandom(-20, 70) * %winScaleX;

      %origY = getRandom(340, 300) * %winScaleY;
      %sizeX = 45*%scale * %winScaleX;
      %sizeY = 45*%scale * %winScaleY;
      
      %obj = ("ParticleDir"@%i);
      %obj.stop();
      %obj.rewind();
      %obj.setExtent(%sizeX, %sizeY);
      %obj.setPosition(%origX, %origY);
      %obj.setDML(%particlePath);      
      %obj.setVisible(false);
      %obj.alpha = "1";
      
      scheduleObjLCA(%this, "HO", getRandom(%aniTime*1000), "DirectorParticlesHelper", 1, %i);
   }
}

function ParticleFx::DirectorParticlesHelper(%this, %particleIdx)
{
   %obj = ("ParticleDir"@%particleIdx);
   %obj.setVisible(true);
   
   %origX = getWord(%obj.Position,0);
   %origY = getWord(%obj.Position,1);
   %sizeX = getWord(%obj.Extent,0);
   %sizeY = getWord(%obj.Extent,0);
   
   %obj.animateCenter(%origX+%sizeX/2, %origY+%sizeY/2-100, 0, 2000, "0 0");      
   %obj.animateAlpha(0, 0, 2000, "0 0"); 
}

function ParticleFx::HintParticles(%this, %particlePath, %scale, %aniTime)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);         

   for(%i=1; %i<=5; %i++)
   {
      %origX = getRandom(690,780) * %winScaleX;

      %origY = getRandom(50, 53) * %winScaleY;
      %sizeX = 45*%scale * %winScaleX;
      %sizeY = 45*%scale * %winScaleY;
      
      %obj = ("HintGlowEffectParticle"@%i);
      %obj.stop();
      %obj.rewind();
      %obj.setExtent(%sizeX, %sizeY);
      %obj.setPosition(%origX, %origY);
      %obj.setDML(%particlePath);      
      %obj.setVisible(false);
      %obj.alpha = "1";
   }
   
   scheduleObjLCA(%this, "HO", getRandom(500)+500, "HintParticlesHelper", 1);
}

function ParticleFx::HintParticlesHelper(%this)
{
   

   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);      
   
   for(%i=1; %i<=3; %i++)
   {
      %this.HintParticleIndex++;
      
      %origX = getRandom(690,780) * %winScaleX;
      %origY = getRandom(50, 53) * %winScaleY;
      %sizeX = 45*1 * %winScaleX;
      %sizeY = 45*1 * %winScaleY;
      
      %obj = ("HintGlowEffectParticle"@%this.HintParticleIndex);
      %obj.setVisible(true);
      %obj.alpha = "1";

      %obj.animateAlpha(0, 0, 500, "0 0"); 
      
      if(%this.HintParticleIndex == 4){
         %this.HintParticleIndex = 0;
      }
   }

   scheduleObjLCA(%this, "HO", getRandom(500)+500, "HintParticlesHelper", 1);
}

function ParticleFx::HintParticlesHelper2(%this,%index)
{
   
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);      
   
   for(%i=1; %i<=3; %i++)
   {
      %this.HintParticleIndex++;
      
      %origX = getRandom(690,780) * %winScaleX;
      %origY = getRandom(50, 53) * %winScaleY;
      %sizeX = 45*1 * %winScaleX;
      %sizeY = 45*1 * %winScaleY;
      
      %obj = ("HintGlowEffectParticle"@%this.HintParticleIndex);
      %obj.setVisible(true);
      %obj.alpha = "1";

      %obj.animateAlpha(0, 0, 500, "0 0"); 
      
      if(%this.HintParticleIndex == 4){
         %this.HintParticleIndex = 0;
      }
   }

   scheduleObjLCA(%this, "HO", getRandom(500)+500, "HintParticlesHelper", 1);
}

function ParticleFx::SparkFx(%this, %x, %y, %speed, %scale)
{
   %idx = %this.getAvailableRippleParticle();
   %obj = ("PRipple"@%idx);
   
   %path = "scriptsAndAssets/data/ui/ho/particles/";
         
   %obj.setDML(%path @ "ripple.dml");
   
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);   
   
   %sizeX = 100 * %scale * %winScaleX;   
   %sizeY = 100 * %scale * %winScaleY;
   
   %obj.stop();   
   %obj.rewind();
   %obj.setExtent(%sizeX, %sizeY);
   %obj.setPosition(%x-(%sizeX/2), %y-(%sizeY/2));
   %obj.rotation = "0";   
   %obj.deltaRotation = "0";
   %obj.aniTime = "0";
   
   %obj.setFps(0);
   %obj.play(1);

   %obj.setAlpha(1);
   %obj.setVisible(true);

   scheduleObjLCA(%this, "HO", 800, "onRippleDeath", 1, %idx);
}
// Hide ripple particle when end of animation is reached
function ParticleFx::onSparkDeath(%this, %idx)  
{
   ("PRipple"@%idx).animateAlpha(0, 0, 100, "0 0");
}

// Produces a fireworks effect in the score screen
// %x and %y are the screen location of the particle generation
// %aniTime is the total animation time, in seconds
// %scale is a scale factor of the particle
function ParticleFx::ScoreFx(%this, %x, %y, %aniTime, %scale)
{
   %scalex = %scale * (1.0 / 800 * getWord(GuiCenter.getExtent(),0));
   %scaley = %scale * (1.0 / 600 * getWord(GuiCenter.getExtent(),1));

   %this.particleIdxTable++;
   %this.particleIdxNum[%this.particleIdxTable] = 0;

   for(%i=0; %i<150; %i++)
   {
      %idx = %this.getAvailableParticle();
         
      %this.particleTable[%this.particleIdxTable, %this.particleIdxNum[%this.particleIdxTable]] = %idx;
      %this.particleIdxNum[%this.particleIdxTable]++;
      
      ("P"@%idx).particleScore(%x, %y, %aniTime, %scalex, %scaley);      
   }
     
   %particleIdx = %this.particleIdxTable;
   %particleNum = %this.particleIdxNum[%this.particleIdxTable];
   scheduleObjLCA(%this, "HO", %aniTime*1000, "onDeathGroup", 2, 
      %particleIdx, %particleNum);   
}
