#include "hostAPI.txt"

#include "global.txt"

var count;
var deflect;
var i;
var ran;
var type;
var tt;
var bx;
var by;
var px;
var py;
var color1;
var color2;
var color3;
var color4;
var color5;
var color6;
var angle;
var cx;
var cy;
var j;
var count2;
var nowx;
var nowy;
var deg;
var f;
var ff;
var fff;
var ffff;
func RF4(x, y, degree) {
ffff=0;
if (x<=175) ffff=2;
if (x>=625) ffff=2;
if (y<=0) ffff=1;
if (y>=600) ffff=1;

if (ffff != 0) {
htRemoveCurrBullet();

for(i=0; i<1; ++i) {
ran = randomfloat(0,360);
    for (j=0; j<20; ++j)
{    

			htInsertBulletVec(0, 0, x, y, 4+0.3*i, 360/20*j+ran);
                        htSetBulletGravitation	(0.05);
                    
                       
               }     

}

}


}




func RF3(x, y, degree) {
fff=0;
if (x<=175) fff=2;
if (x>=625) fff=2;
if (y<=0) fff=1;
if (y>=600) fff=1;

if (fff != 0) {
htRemoveCurrBullet();
for(i=0; i<2; ++i) {
ran = randomfloat(0,360);
    for (j=0; j<20; ++j)
{    

			htInsertBulletVec(0, 0, x, y, 4+0.3*i, 360/20*j+ran);
                        htSetBulletGravitation	(0.05);
                    
                       
               }     

}

       
        var bbbbx = x;
	var bbbby = y;
var ddddeg;

         ddddeg=180 - degree;

if (fff == 1) ddddeg= -degree;

         

         htInsertBulletVec(5,10,bbbbx+80*cos(ddddeg),bbbby+80*sin(ddddeg),10,ddddeg);
htBindScriptFuncToBullet("RF4",1,-1);
        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,10,bbbbx+80*cos(ddddeg)+3*i*cos(ddddeg-150-15),bbbby+80*sin(ddddeg)+3*i*sin(ddddeg-150-15),10,ddddeg);

            htInsertBulletVec(5,10,bbbbx+80*cos(ddddeg)+3*i*cos(ddddeg+150+15),bbbby+80*sin(ddddeg)+3*i*sin(ddddeg+150+15),10,ddddeg);

          } 


}


}








func RF2(x, y, degree) {
ff=0;
if (x<=175) ff=2;
if (x>=625) ff=2;
if (y<=0) ff=1;
if (y>=600) ff=1;

if (ff != 0) {
htRemoveCurrBullet();
for(i=0; i<3; ++i) {
ran = randomfloat(0,360);
    for (j=0; j<20; ++j)
{    

			htInsertBulletVec(0, 0, x, y, 4+0.3*i, 360/20*j+ran);
                        htSetBulletGravitation	(0.05);
                    
                       
               }     

}
       
        var bbbx = x;
	var bbby = y;
var dddeg;

         dddeg=180 - degree;

if (ff == 1) dddeg= -degree;

          htInsertBulletVec(5,4,bbbx+80*cos(dddeg),bbby+80*sin(dddeg),10,dddeg);
 htBindScriptFuncToBullet("RF3",1,-1);
        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,4,bbbx+80*cos(dddeg)+3*i*cos(-dddeg+150),bbby+80*sin(dddeg)+3*i*sin(dddeg-150),10,dddeg);
       
            htInsertBulletVec(5,4,bbbx+80*cos(dddeg)+3*i*cos(dddeg+150),bbby+80*sin(dddeg)+3*i*sin(dddeg+150),10,dddeg);
      
          }

         htInsertBulletVec(5,10,bbbx+80*cos(dddeg),bbby+80*sin(dddeg),10,dddeg);

        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,10,bbbx+80*cos(dddeg)+3*i*cos(dddeg-150-15),bbby+80*sin(dddeg)+3*i*sin(dddeg-150-15),10,dddeg);

            htInsertBulletVec(5,10,bbbx+80*cos(dddeg)+3*i*cos(dddeg+150+15),bbby+80*sin(dddeg)+3*i*sin(dddeg+150+15),10,dddeg);

          } 


}


}









func RF1(x, y, degree) {
f=0;
if (x<=175) f=2;
if (x>=625) f=2;
if (y<=0) f=1;
if (y>=600) f=1;

if (f != 0) {
htRemoveCurrBullet();
ran = randomfloat(0,360);
for(i=0; i<4; ++i) {
ran = randomfloat(0,360);
    for (j=0; j<20; ++j)
{    

			htInsertBulletVec(0, 0, x, y, 4+0.3*i, 360/20*j+ran);
                        htSetBulletGravitation	(0.05);
                    
                       
               }     

}   

       
        var bbx = x;
	var bby = y;
        var ddeg;


         ddeg=180-degree;
if (f == 1) ddeg= -degree;



htInsertBulletVec(5,2,bbx+90*cos(ddeg),bby+90*sin(ddeg),10,ddeg);
 htBindScriptFuncToBullet("RF2",1,2000);
        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,2,bbx+90*cos(ddeg)+3.5*i*cos(-ddeg+150),bby+90*sin(ddeg)+3.5*i*sin(ddeg-150),10,ddeg);
     
            htInsertBulletVec(5,2,bbx+90*cos(ddeg)+3.5*i*cos(ddeg+150),bby+90*sin(ddeg)+3.5*i*sin(ddeg+150),10,ddeg);
  
          }
          htInsertBulletVec(5,4,bbx+80*cos(ddeg),bby+80*sin(ddeg),10,deg);

        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,4,bbx+80*cos(ddeg)+3*i*cos(-ddeg+150),bby+80*sin(ddeg)+3*i*sin(ddeg-150),10,ddeg);
       
            htInsertBulletVec(5,4,bbx+80*cos(ddeg)+3*i*cos(ddeg+150),bby+80*sin(ddeg)+3*i*sin(ddeg+150),10,ddeg);
      
          }

         htInsertBulletVec(5,10,bbx+80*cos(ddeg),bby+80*sin(ddeg),10,deg);

        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,10,bbx+80*cos(ddeg)+3*i*cos(ddeg-150-15),bby+80*sin(ddeg)+3*i*sin(ddeg-150-15),10,ddeg);

            htInsertBulletVec(5,10,bbx+80*cos(ddeg)+3*i*cos(ddeg+150+15),bby+80*sin(ddeg)+3*i*sin(ddeg+150+15),10,ddeg);

          } 


}


}

func update() {
++count;
       if(count < 0)
		return;
	
	px = htGetPlayerX();
	py = htGetPlayerY();
        bx = htGetBossX();
	by = htGetBossY();
      

if ((count % 300>=0)&&(count % 300 <=60))
{ deg = GetDegreeBetweenTwoPoints(bx,by, px, py);
        htInsertBulletVec(5,0,bx+100*cos(deg),by+100*sin(deg),0,deg);
htSetBulletLifeTime	(1);
        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,0,bx+100*cos(deg)+4*i*cos(-deg+150),by+100*sin(deg)+4*i*sin(deg-150),0,deg);
htSetBulletLifeTime	(1);
            htInsertBulletVec(5,0,bx+100*cos(deg)+4*i*cos(deg+150),by+100*sin(deg)+4*i*sin(deg+150),0,deg);
htSetBulletLifeTime	(1);
          }
}

if ((count % 300>=20)&&(count % 300 <=60))
{
        htInsertBulletVec(5,2,bx+90*cos(deg),by+90*sin(deg),0,deg);
htSetBulletLifeTime	(1);
        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,2,bx+90*cos(deg)+3.5*i*cos(-deg+150),by+90*sin(deg)+3.5*i*sin(deg-150),0,deg);
htSetBulletLifeTime	(1);
     
            htInsertBulletVec(5,2,bx+90*cos(deg)+3.5*i*cos(deg+150),by+90*sin(deg)+3.5*i*sin(deg+150),0,deg);
  htSetBulletLifeTime	(1);
          }
}
if ((count % 300>=30)&&(count % 300 <=60))
{
          htInsertBulletVec(5,4,bx+80*cos(deg),by+80*sin(deg),0,deg);
htSetBulletLifeTime	(1);
        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,4,bx+80*cos(deg)+3*i*cos(-deg+150),by+80*sin(deg)+3*i*sin(deg-150),0,deg);
       htSetBulletLifeTime	(1);
            htInsertBulletVec(5,4,bx+80*cos(deg)+3*i*cos(deg+150),by+80*sin(deg)+3*i*sin(deg+150),0,deg);
      htSetBulletLifeTime	(1);
          }
}
if ((count % 300>=40)&&(count % 300 <=60))
{
 htInsertBulletVec(5,10,bx+80*cos(deg),by+80*sin(deg),0,deg);
htSetBulletLifeTime	(1);
        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,10,bx+80*cos(deg)+3*i*cos(deg-150-15),by+80*sin(deg)+3*i*sin(deg-150-15),0,deg);
       htSetBulletLifeTime	(1);
            htInsertBulletVec(5,10,bx+80*cos(deg)+3*i*cos(deg+150+15),by+80*sin(deg)+3*i*sin(deg+150+15),0,deg);
      htSetBulletLifeTime	(1);
          }

}
if (count % 300 == 61)
{ 
tt= 40;
htPlayBossEnergyAnim(60);
deg = GetDegreeBetweenTwoPoints(bx,by, px, py);
        htInsertBulletVec(5,0,bx+100*cos(deg),by+100*sin(deg),10,deg);
htSetBulletPause(0,tt);
        htBindScriptFuncToBullet("RF1",1,2000);
        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,0,bx+100*cos(deg)+4*i*cos(-deg+150),by+100*sin(deg)+4*i*sin(deg-150),10,deg);
htSetBulletPause(0,tt);
            htInsertBulletVec(5,0,bx+100*cos(deg)+4*i*cos(deg+150),by+100*sin(deg)+4*i*sin(deg+150),10,deg);
htSetBulletPause(0,tt);
          }
        htInsertBulletVec(5,2,bx+90*cos(deg),by+90*sin(deg),10,deg);
htSetBulletPause(0,tt);
        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,2,bx+90*cos(deg)+3.5*i*cos(-deg+150),by+90*sin(deg)+3.5*i*sin(deg-150),10,deg);
     htSetBulletPause(0,tt);
            htInsertBulletVec(5,2,bx+90*cos(deg)+3.5*i*cos(deg+150),by+90*sin(deg)+3.5*i*sin(deg+150),10,deg);
  htSetBulletPause(0,tt);
          }
          htInsertBulletVec(5,4,bx+80*cos(deg),by+80*sin(deg),10,deg);
htSetBulletPause(0,tt);
        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,4,bx+80*cos(deg)+3*i*cos(-deg+150),by+80*sin(deg)+3*i*sin(deg-150),10,deg);
       htSetBulletPause(0,tt);
            htInsertBulletVec(5,4,bx+80*cos(deg)+3*i*cos(deg+150),by+80*sin(deg)+3*i*sin(deg+150),10,deg);
      htSetBulletPause(0,tt);
          }

         htInsertBulletVec(5,10,bx+80*cos(deg),by+80*sin(deg),10,deg);
htSetBulletPause(0,tt);
        for (i=0; i<30; ++i)
         {  htInsertBulletVec(5,10,bx+80*cos(deg)+3*i*cos(deg-150-15),by+80*sin(deg)+3*i*sin(deg-150-15),10,deg);
htSetBulletPause(0,tt);
            htInsertBulletVec(5,10,bx+80*cos(deg)+3*i*cos(deg+150+15),by+80*sin(deg)+3*i*sin(deg+150+15),10,deg);
htSetBulletPause(0,tt);
          }

htMoveBossTo(px+randomfloat(-100,100),randomfloat(100,200),200);
}
}

func init() {
htMoveBossTo(400,100, 30);
htSetBulletScreenRect(-300,-300,900,900);
	count = -60;
	htPlayBossEnergyAnim(90);
         count2 =0;
	deflect = 0;
	i = 0;
	type = 0;
	color1=0;
        color2=2;
        color3=5;
	color4=8;
	color5=12;
        color6=15; 
	bx = 0;
	by = 0;
	htStopSCBackground();
	htEnable2DFog1(true, 5);
}