#include "hostAPI.txt"

#include "global.txt"

var count;
var deflect;
var i;
var ran;
var ran2;
var type;
var tt;
var bx;
var by;
var px;
var py;
var px2;
var py2;
var ppx2;
var ppy2;
var ppx;
var ppy;
var color1;
var color2;
var color3;
var color4;
var color5;
var color6;
var k;
var cx;
var cy;
var j;
var count2;
var nowx;
var nowy;
var deg;
var f;
var ttd;
var aangle;


func update() {
++count;
  if(count < 0)
	return;    
	
        bx = htGetBossX();
	by = htGetBossY();
        px = htGetPlayerX();
        py = htGetPlayerY();
if ((count % 450 <=30)&&(count % 2 ==0))       
for (i=0;i<=20;++i)
{
ran=randomfloat(185,615);
ran2=randomfloat(10,590);
if (sqrt((ran-px)*(ran-px)+(ran2-py)*(ran2-py))>50)
{
deg=GetDegreeBetweenTwoPoints(ran,ran2,bx,by);
htInsertBulletVec(0,randomint(0,7),ran,ran2,sqrt((ran-bx)*(ran-bx)+(ran2-by)*(ran2-by))/90,deg);
htSetBulletPause(0,60);
htSetBulletLifeTime(90+60);
}
}

if ((count % 450 <= 330)&&(count % 450 >= 150)&&(count % 10 ==0))
{ 
if (count % 450 == 150) 
{
   ppx = htGetPlayerX();
   ppy = htGetPlayerY();

}

htInsertBulletVec(5,8,ppx-100,ppy-100,5,0);
htSetBulletLifeTime(40);
htInsertBulletVec(5,8,ppx+100,ppy-100,5,90);
htSetBulletLifeTime(40);
htInsertBulletVec(5,8,ppx-100,ppy+100,5,-90);
htSetBulletLifeTime(40);
htInsertBulletVec(5,8,ppx+100,ppy+100,5,180);
htSetBulletLifeTime(40);

}

if (count % 450 == 330)
{
htPlayBossEnergyAnim(60);
        bx = htGetBossX();
	by = htGetBossY();
   
deg=GetDegreeBetweenTwoPoints(bx,by,ppx,ppy);
for (i=0;i<=500;++i)
htInsertBulletVec(5,randomint(0,15),bx,by,randomfloat(0.1,12),deg+randomfloat(-20,20));
for (i=0;i<=100;++i)
htInsertBulletVec(5,randomint(0,15),bx,by,randomfloat(0.1,2),deg+randomfloat(-20,20));


for (i=0;i<=20;++i)
for (j=0;j<=8;++j)
htInsertBulletVec(0,randomint(0,7),bx,by,1+1*j,360/20*i);
}

if (count % 450 == 400)
htMoveBossTo(randomfloat(225,575),randomfloat(50,150),50);
}

func init() {
htMoveBossTo(400,100, 30);
htSetBulletScreenRect(150-120,-25-120,650+120,625+120);
	count = -150;
         count2 =0;
	deflect = 0;
	i = 0;
	type = 0;
	color1=0;
        color2=2;
        color3=5;
	color4=8;
	color5=12;
        color6=15; 
	bx = 0;
	by = 0;
	
	htPlayBossEnergyAnim(90);
}