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

    SpellID=508;

    @Initialize {
	Randomize;
        SetLife(2600);
        SetTimer2(40);
	SetDamageRate(100,50);
	MagicCircle(false);
	SetEnemyMarker(true);
	IddyeaInit;
	MainTask;
	shotinit;

	StartFunctions(1,0,0);
//	SpellCircle2(6,1,4,200);
	SetShotAutoDeleteClip(64,10,64,64);
    }


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

task MainTask{
	DelayBombTask;
	SetMovePositionNew(GetCenterX,100,60);
	Wait(60);

	let angle;
	let angle2;
	let frame=0;
	let dist=0;
	let k=0;
	let color=rand_int(0,3);
	let coloroffset;
	let x;
	let y;
	let dir=1;
	loop{
		angle=rand(0,360);
		dist=50;
		SE("shot3");
		SE("laser4");
		angle=rand(0,360);
		angle2=angle;
		dist=0;
		coloroffset=rand(0,360);
		loop(7){
			CreateExplosionEX(3,GetX,GetY,0.1,RainbowArray(coloroffset,140,100),rand(0.2,0.4),rand_int(20,50));
			coloroffset+=360/7;
		}
		loop(500){
			x=GetX+cos(angle)*dist;
			y=GetY+sin(angle)*dist;
			if(OnScreen(x,y,60)){
				MainShot(x,y,angle,90*dir,dist,0,coloroffset, trunc(dist/8));
			}
			x=GetX+cos(angle2)*dist;
			y=GetY+sin(angle2)*dist;
			if(OnScreen(x,y,60)){
				MainShot(x,y,angle2,90*dir,dist,0,coloroffset, 65-trunc(dist/8));
			}
			angle+=91;
			angle2-=91;
			dist++;
		}
		Wait(280);
		dir=-dir;
		frame++;
	}
}

task MainShot(x,y,angle,angle2,dist,color,coloroffset, waittime){
	Wait(waittime);
	if(distance(x,y,GetPlayerX,GetPlayerY)>60*60||dist<90){
		while(angle+coloroffset<0){angle+=360;}
		while(angle+coloroffset>=360){angle-=360;}
		let color=trunc(((angle+coloroffset)/360)*14)%7;
		DelayNew(x,y,angle+angle2,50,18,RED21+color,20,0);
		Wait(20);
		let obj=Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,x,y);
		Obj_SetAngle(obj,angle+angle2);
		ObjShot_SetGraphic(obj,RED21+color);
		Wait((65)-waittime);
		let v=rand(1,2);
		let frame=0;
		loop(100){
			yield;
			frame++;
			Obj_SetSpeed(obj,(sin(frame*(90/100)+270)+1)*v);
		}
	}
}

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

	IddyeaDrawLogic;

	yield;
}

@DrawLoop {
	IddyeaDrawLoop;
}

@Finalize {
	EndingFunc(6);
	IddyeaFinalize;
	SetShotAutoDeleteClip(64,64,64,64);
	PointItems(GetX,GetY,7,0);
}

}