#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;


func exxx(x, y, degree) {


htRemoveCurrBullet();
ran = randomfloat(0,360);
for(i=0; i<15; ++i) {
    for (j=0; j<3; ++j)
{

			htInsertBulletVec(5, 2, x, y, 4+0.3*j, 360/15*i+ran);
                        htSetBulletDeflectionEx	(3,1,0,30);
                        htInsertBulletVec(5, 2, x, y, 4+0.3*j, -360/15*i-ran);
                        htSetBulletDeflectionEx	(-3,1,0,30);
                       
               }      

}
}

func update() {
++count;
      if(count < 0)
		return;
	
	px = htGetPlayerX();
	py = htGetPlayerY();
        bx = htGetBossX();
	by = htGetBossY();
        cx = 400 ;
        cy = 385 ;
  if (count == 100)
   {  
htSetBulletScreenRect(-100,-300,800,850);
for (i=0; i<=60;++i)
       { angle=360/60*i;
 htInsertBulletVec(5,8, cx+300*cos(angle), cy+300*sin(angle),4,angle+90);
         htSetBulletDeflectionEx(4/240/3.1415926*360,0,0,1000);
         htSetBulletLifeTime	(97);
        }
      for (i=0; i<=60;++i)
       { angle=360/60*i;
 htInsertBulletVec(5,8, cx+300*cos(-angle), cy+300*sin(-angle),4,-angle-90);
         htSetBulletDeflectionEx(-4.0/240/3.1415926*360,0,0,1000);
htSetBulletLifeTime	(97);
        }
     }
    if (count == 194)
   {  
   htPlayBossEnergyAnim(60);
htSetBulletScreenRect(150, -25, 650, 625);
for (i=0; i<=60;++i)
       { angle=360/60*i;
 htInsertBulletVec(5,8, cx+60*cos(angle), cy+60*sin(angle),4,angle+90);
         htSetBulletDeflectionEx(4.0/100/3.1415926*360,0,0,1000);
         htSetBulletLifeTime	(30);
        }
      for (i=0; i<=60;++i)
       { angle=360/60*i;
 htInsertBulletVec(5,8, cx+60*cos(-angle), cy+60*sin(-angle),4,-angle-90);
         htSetBulletDeflectionEx(-4.0/100/3.1415926*360,0,0,1000);
htSetBulletLifeTime	(30);
        }
      for (i=0; i<=6;++i)
      {
       for (j=0; j<=8;++j)
       { htInsertBulletVec(5,8,i*220/3+217.5,52.5+j*220/3-5.5,0,90);
	 htSetBulletImmortal(true);
         htInsertBulletVec(5,8,i*220/3+217.5,52.5+j*220/3+5.5,0,90);
	htSetBulletImmortal(true);
         htInsertBulletVec(5,8,i*220/3+217.5-5.5,52.5+j*220/3,0,0);
	htSetBulletImmortal(true);
         htInsertBulletVec(5,8,i*220/3+217.5+5.5,52.5+j*220/3,0,0); 
	htSetBulletImmortal(true);
        } 
       }
      count2=0;
     }
    if (count>=194)
      {  if (count2 == 0)
            { nowx=randomint(0,5);
              nowy=1;
             }
          if ((count2 >= 0) && (count2 % 10 == 5))
             { htInsertBulletVec(5,0,(nowx)*220/3+217.5,52.5+(nowy-1)*220/3,0,90);
               htSetBulletLifeTime(90);
               htInsertBulletVec(5,0,(nowx)*220/3+217.5,52.5+(nowy-1)*220/3,0,0);
               htBindScriptFuncToBullet("exxx",90,1);
               htInsertBulletVec(5,0,(nowx)*220/3+217.5+15,52.5+(nowy-1)*220/3,3,90);
               htSetBulletDeflectionEx(3.01/30/3.1415926*360,0,0,1000); 
               htSetBulletLifeTime	(90);
               htInsertBulletVec(5,0,(nowx)*220/3+217.5-15,52.5+(nowy-1)*220/3,3,90);
               htSetBulletDeflectionEx(-3.01/30/3.1415926*360,0,0,1000); 
               htSetBulletLifeTime	(90);
               htInsertBulletVec(5,0,(nowx)*220/3+217.5+15,52.5+(nowy-1)*220/3,3,-90);
               htSetBulletDeflectionEx(-3.01/30/3.1415926*360,0,0,1000); 
               htSetBulletLifeTime	(90);
               htInsertBulletVec(5,0,(nowx)*220/3+217.5-15,52.5+(nowy-1)*220/3,3,-90);
               htSetBulletDeflectionEx(3.01/30/3.1415926*360,0,0,1000); 
               htSetBulletLifeTime	(90);        
               nowy=nowy+1;
               nowx=nowx+randomint(-1,1);
               if (nowx == -1) nowx = 0;
               if (nowx == 6) nowx = 5;  
              }   

           if (count2 == 90) count2 = -200;





         ++count2;
       }   
}

func init() {
htMoveBossTo(400, 200, 30);
htSetBulletScreenRect(-100,-300,800,850);
	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;
}