#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 fulllife;
var bosslife;
var rx;
var ry;
var deg;
var degg;
var movex;
var movey;
var ran;


func fire(x,y,degree)
{
for (i=0;i<=4;++i)
for (j=0;j<=1;++j)
{
htInsertBulletVec(5, 10,x,y,1+0.5*j,360/4*i+count/5);


}



}

func fire2(x,y,degree)
{
for (i=0;i<=4;++i)
for (j=0;j<=1;++j)
{
htInsertBulletVec(5, 10,x,y,1+0.5*j,360/4*i-count/5);


}



}



func update() {

bosslife=htGetBossLife();
	bx = htGetBossX();
	by = htGetBossY();
	
	px = htGetPlayerX();
	py = htGetPlayerY();
deg=GetDegreeBetweenTwoPoints(bx, by,px,py);

if (count % 5 ==0)
{
htInsertBulletVec(5,15,175-40,160,8,0); 
htSetBulletDeflectionEx(-8.01/300/3.1415*360,0,5,90);
}
if (count % 5 ==0)
{
htInsertBulletVec(5,15,625+40,160,8,180); 
htSetBulletDeflectionEx(8.01/300/3.1415*360,0,5,90);
}

if (count % 45 ==0)
{
htInsertBulletVec(5,15,175-40,160,8,0); 
htSetBulletDeflectionEx(-8.01/300/3.1415*360,0,5,90);
htBindScriptFuncToBullet("fire",15,3);
}
if (count % 45 ==0)
{
htInsertBulletVec(5,15,625+40,160,8,180); 
htSetBulletDeflectionEx(8.01/300/3.1415*360,0,5,90);
htBindScriptFuncToBullet("fire2",15,3);
}

if (count % 5 ==0)
{
htInsertBulletVec(5,15,175+34+20,248,8,90); 
htSetBulletDeflectionEx(8.01/40/3.1415*360,0,5,20);
htSetBulletLifeTime	(20);
}
if (count % 45 ==0)
{
for (i=0;i<=4;++i)
{
htInsertBulletVec(5,5,175+34,248,2,-90/4*i); 
htSetBulletDeflectionEx(3,0,5,20);
}
}



if (count % 5 ==0)
{
htInsertBulletVec(5,15,175+112+20,236,8,90); 
htSetBulletDeflectionEx(8.01/40/3.1415*360,0,5,20);
htSetBulletLifeTime	(20);
}

if (count % 120 ==0)
{
for (i=0;i<=8;++i)
{
deg=GetDegreeBetweenTwoPoints(175+112+40*cos(360/8*i+count/10),236+40*sin(360/8*i+count/10),px,py);
htInsertBulletVec(0,2,175+112,236,2,360/8*i+count/10); 
htSetBulletSpeedDgrEx	(3,deg,20);

}
}


if (count % 5 ==0)
{
htInsertBulletVec(5,15,175+189+20,260,8,90); 
htSetBulletDeflectionEx(8.01/40/3.1415*360,0,5,20);
htSetBulletLifeTime	(20);
}

if (count % 60 ==0)
{
for (i=0;i<=4;++i)
{
for (j=0;j<=1;++j)
{
htInsertBulletVec(5,2,175+189,260,1+j*0.2,360/4*i+count/10); 
htSetBulletDeflectionEx(3,0,5,60);
}
}
}


if (count % 5 ==0)
{
htInsertBulletVec(5,15,175+406-20,248,8,90); 
htSetBulletDeflectionEx(-8.01/40/3.1415*360,0,5,20);
htSetBulletLifeTime	(20);
}

if (count % 45 ==0)
{
for (i=0;i<=4;++i)
{
htInsertBulletVec(5,5,175+406,248,2,-90-90/4*i); 
htSetBulletDeflectionEx(-3,0,5,20);
}
}

if (count % 5 ==0)
{
htInsertBulletVec(5,15,175+247-20,260,8,90); 
htSetBulletDeflectionEx(-8.01/40/3.1415*360,0,5,20);
htSetBulletLifeTime	(20);
}

if (count % 60 ==0)
{
for (i=0;i<=4;++i)
{
for (j=0;j<=1;++j)
{
htInsertBulletVec(5,2,175+247,260,1+j*0.2,360/4*i-count/10); 
htSetBulletDeflectionEx(-3,0,5,60);
}
}
}


if (count % 5 ==0)
{
htInsertBulletVec(5,15,175+326-20,236,8,90); 
htSetBulletDeflectionEx(-8.01/40/3.1415*360,0,5,20);
htSetBulletLifeTime	(20);
}


if (count % 120 ==0)
{
for (i=0;i<=8;++i)
{
deg=GetDegreeBetweenTwoPoints(175+326+40*cos(360/8*i+count/10),236+40*sin(360/8*i+count/10),px,py);
htInsertBulletVec(0,2,175+326,236,2,360/8*i+count/10); 
htSetBulletSpeedDgrEx	(3,deg,20);

}
}

	++count;
}

func init() {


htMoveBossTo(219+175,133, 30);
htSetBulletScreenRect(100, -50, 750, 700);
	count = 0;
	deflect = 0;
	i = 0;
	type = 0;
	
	bx = 0;
	by = 0;
}