#include "hostAPI.txt"

#include "global.txt"

var count;
var deflect;
var i;
var j;
var type;
var tt;
var bx;
var by;
var px;
var py;
var ran;
var ran1;
var ran2;
var ran3;
var ran4;
var deg;



func L4(x,y,degree){





htRemoveCurrBullet();
ran4=randomint(0,1);
if (ran4==0) 
ran4=0-1;
var x5=x+450/64*ran;
var y5=600;
deg=GetDegreeBetweenTwoPoints(x,y,x5,y5);
htInsertBulletVec(5,8,x,y,3,deg);




}









func L3(x,y,degree){



htRemoveCurrBullet();
ran3=randomint(0,1);
if (ran3==0) 
ran3=0-1;
var x4=x+450/32*ran3;
var y4=500;
deg=GetDegreeBetweenTwoPoints(x,y,x4,y4);
htInsertBulletVec(5,59,x,y,3,deg);
htBindScriptFuncToBullet("L4",sqrt((x-x4)*(x-x4)+(y-y4)*(y-y4))/3,1);

for (i=0;i<=3;++i)
 for (j=0;j<=2;++j)
{
htInsertBulletVec(5,8,x,y,2+j*0.1,90*i+count);
htSetBulletDeflectionEx	(5*ran3,0,0,50);
}



}






func L2(x,y,degree){




htRemoveCurrBullet();
ran2=randomint(0,1);
if (ran2==0) 
ran2=0-1;
var x3=x+450/16*ran;
var y3=400;
deg=GetDegreeBetweenTwoPoints(x,y,x3,y3);
htInsertBulletVec(5,9,x,y,3,deg);
htBindScriptFuncToBullet("L3",sqrt((x-x3)*(x-x3)+(y-y3)*(y-y3))/3,1);

for (i=0;i<=3;++i)
 for (j=0;j<=2;++j)
{
htInsertBulletVec(5,8,x,y,2+j*0.1,90*i+count);
htSetBulletDeflectionEx	(5*ran2,0,0,50);
}

}



func L1(x,y,degree){


htRemoveCurrBullet();
ran1=randomint(0,1);
if (ran1==0) 
ran1=0-1;
var x2=x+450/8*ran1;
var y2=300;
deg=GetDegreeBetweenTwoPoints(x,y,x2,y2);
htInsertBulletVec(5,9,x,y,3,deg);
htBindScriptFuncToBullet("L2",sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2))/3,1);


for (i=0;i<=3;++i)
 for (j=0;j<=2;++j)
{
htInsertBulletVec(5,8,x,y,2+j*0.1,90*i+count);
htSetBulletDeflectionEx	(5*ran1,0,0,50);
}


}



func update() {

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



ran=randomint(0,1);
if (ran==0) 
ran=0-1;
var x1=bx+450/4*ran;
var y1=200;
deg=GetDegreeBetweenTwoPoints(bx,by,x1,y1);
htInsertBulletVec(5,9,bx,by,3,deg);
htBindScriptFuncToBullet("L1",sqrt((bx-x1)*(bx-x1)+(by-y1)*(by-y1))/3,1);

for (i=0;i<=3;++i)
 for (j=0;j<=2;++j)
{
htInsertBulletVec(5,8,bx,by,2+j*0.1,90*i+count);
htSetBulletDeflectionEx	(5*ran,0,0,50);
}
}

}

func init() {
htMoveBossTo(400,100, 30);
htSetBulletScreenRect(100, -50, 750, 700);

htPlayBossEnergyAnim(60);
	count = -30;
	deflect = 0;
	i = 0;
	type = 0;
	
	bx = 0;
	by = 0;
}