script_enemy_main {
	#include_function ".\..\ShotSheet\shot_replace.dnh"
	#include_function ".\..\functions.txt"
	#include_function ".\..\s3\y_functions.txt"

	SpellID=57;

	let i=0;
	let frame=0;

    @Initialize {
	StartFunctions(1,0,0);
	Randomize;
        SetLife(3000);
        SetTimer2(55);
	SetDamageRate(100,100);
	MagicCircle(false);
	SetEnemyMarker(true);
	YumemiInit;
	SetBG(4);

	shotinit;

	CutIn2(4,"Star Science [Matrix of the Red Heavens]");
	SpellCircle2(4,1,4,250);
	SetShotAutoDeleteClip(10,10,10,10);

	MainTask;
    }


function Wait(frames){loop(frames){yield;}}

task MainTask{
	SetMovePosition03(GetCenterX,100,10,5);
	DelayBombTask;
	Wait(120);
	MainTask2;

	let k=0;
	loop(4){
		MainCross(GetCenterX+cos(k)*120,GetCenterY+sin(k)*120,120,100);
		k-=180/3;
		Wait(5);
	}
	Wait(240);

	loop{
		loop(6){
			MainCross(GetCenterX+prand(-180,180),GetCenterY+prand(-230,230),120,100);
			Wait(10);
		}
		Wait(200);
	}
}
task MainTask2{
	let angle=0;
	let dir=1;
	let colors=[WHITE58,0,BLUE58];
	let colors2=[BLUE58,0,WHITE58];
	loop{
		YumemiMove(50);
		MoveRandom(100,50, GetClipMinX+50,130,GetClipMaxX-50,200, 100, 50);
		loop(7){
			Wait(4);
			SE("shot1");
			angle=rand(0,360);
			loop(6){
				TurnShot(GetX,GetY,rand(2,5),50,1.8,angle,90*dir,RED50,colors[dir+1]);
				TurnShot(GetX,GetY,rand(1,4),50,2.5,angle,-90*dir,RED50,colors2[dir+1]);
				angle+=360/6;
			}
		}
		dir=-dir;
		Wait(80);
	}
}
task TurnShot(x,y,v1,decel,v2,angle,angleadd,g1,g2){
	CreateShotA(0,x,y,0);
	SetShotDataA(0,0,v1,angle,0,-v1/decel,0,g1);
	SetShotDataA(0,50,v2,angle+angleadd,0,0,0,g2);
	AddShotDelay(0,50,g2,20);
	FireShot(0);
}

task MainCross(x,y,time,delay){
//	Line(GetClipMinX,y,GetClipMaxX,y,24,20,time,2,ADD,[255,128,128]);
//	Line(x,GetClipMinY,x,GetClipMaxY,24,20,time,2,ADD,[255,128,128]);
	LessenCrossEffect;
	Cross(x,y,time,delay);
	Wait(delay);

	CreateLaser01(x,y,3.5,0   ,200,30,RED52,0);
	CreateLaser01(x,y,3.5,90  ,200,30,RED52,0);
	CreateLaser01(x,y,3.5,180 ,200,30,RED52,0);
	CreateLaser01(x,y,3.5,270 ,200,30,RED52,0);
	CreateExplosionFlatEX(3,x,y,0.1,[70,20,20],0.3,120);
}
task DelayLine(x,y,width,alpha,time,layer,renderstate,color,delay){
	Wait(delay);
	Line(GetX,GetY,x,y,width,alpha,time,layer,renderstate,color);
}

    @MainLoop {
        SetCollisionA(GetX, GetY, 40);
	SetCollisionB(GetX, GetY, 20);

	YumemiDrawLogic;
	yield;
}
    @DrawLoop {
	YumemiDrawLoop;
}


    @Finalize {
	SetShotAutoDeleteClip(64,64,64,64);
	YumemiFinalize;
	PointItems(GetX,GetY,3,1);
	EndingFunc(3);
    }
}