
script_enemy_main {
    let GCSD=GetCurrentScriptDirectory;
    #include_function ".\..\ShotSheet\shot_replace.dnh"
    #include_function ".\..\functions.txt"
    #include_function ".\iddyea_functions.txt"

    SpellID=507;

    @Initialize {
	Randomize;
        SetLife(2200);
        SetTimer2(55);
	SetDamageRate(80,40);
	MagicCircle(false);
	SetEnemyMarker(true);
	IddyeaInit;
	MainTask;
	shotinit;

	StartFunctions(1,0,0);
	SetBG(20);

	SpellCircle2(6,1,4,200);
    }


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

let moveiddyea=0;

task MainTask{
	CutIn2(3,"[Web of Emotions]");


	DelayBombTask;
//	CutIn2(3,"");

	SetMovePositionNew(GetCenterX,100,60);
	Wait(80);
	let angle=rand(0,120);

	MainTask2;
	let k=0;
	loop{
		MainShot(GetX,GetY,45,-1);
		Wait(171);
		MoveRandom(50,20,GetClipMinX+150,100,GetClipMaxX-150,150,1000,171);
		MainShot(GetX,GetY,180-45,1);
		Wait(171);
		MoveRandom(50,20,GetClipMinX+150,100,GetClipMaxX-150,150,1000,171);
	}
}
task MainTask2{
	let angle;
	loop{
		MainShot2(GetX,GetY,4,1,NULL,BLUE03,64);
		SE("shot2");
		loop(12){
			angle=rand(0,360);
			MainShot2(GetX+cos(angle)*100,GetY+sin(angle)*100,3,rand(1,1.5),GetAngleToPlayer+rand(-20,20),SP04,20);
			SE("shot1");
			Wait(12);
		}
	}

}

task MainShot2(x,y,v1,v2,angle,graphic,size){
	let angletype=false;
	if(angle==NULL){
		angle=GetAngleToPlayer;
		angletype=true;
	}
	DelayNew(x,y,angle,120,size,graphic,30,50);
	Wait(30);

	if(angletype){
		angle=GetAngleToPlayer;
	}
	CreateShot02(x,y,v1,angle,(v2-v1)/50,v2,graphic,0);
}

task MainShot(x,y,moveangle,dir){
	let angle=rand(-10,10);
	while(!OffScreen(x,y,250)){
		angle+=dir*4;
		loop(3){
			FollowLaser(x,y,moveangle,angle,60);
			angle+=120;
		}
		x+=cos(moveangle)*19;
		y+=sin(moveangle)*19;
		Wait(9);
	}
}
task FollowLaser(x,y,moveangle,shootangle,time){
	let obj=Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,x,y);
	ObjShot_SetGraphic(obj,WHITE60);
	Obj_SetAutoDelete(obj,false);
	ObjLaser_SetWidth(obj,4);
	Obj_SetAlpha(obj,160);
	ObjLaser_SetLength(obj,800);
	Obj_SetCollisionToPlayer(obj,false);
	ObjLaser_SetSource(obj,false);
	Obj_SetAngle(obj,shootangle);
	loop(time){
		yield;
	}
	Obj_SetAlpha(obj,255);

	let graphics=[RED60,WHITE60,PURPLE60,WHITE60];

	let width=4;
	loop(5){
		width+=2;
		ObjLaser_SetWidth(obj,width);
		yield;
	}
	Obj_SetCollisionToPlayer(obj,true);
	if(GetPointToLineSegment(GetPlayerX, GetPlayerY, x, y, x+cos(shootangle)*800, y+sin(shootangle)*800)<100){
		SE("laser1");
	}

	let frame=0;
	loop(30){
		if(frame%3==0){
			ObjLaser_SetWidth(obj,rand(10,15));
		}
		ObjShot_SetGraphic(obj,graphics[trunc(frame/3%4)]);
		frame++;
		Wait(1);
	}
	ObjShot_FadeDelete(obj);
}

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

	if(moveiddyea==1){
		SetX(GetX+(GetPlayerX-GetX)/300);
	}

	IddyeaDrawLogic;

	yield;

}

@DrawLoop {
	IddyeaDrawLoop;
}

@Finalize {
	EndingFunc(6);
	IddyeaFinalize;
	PointItems(GetX,GetY,7,1);
}

}