script_enemy_main
{
	let frame=-100;
	#include_function ".\spellcard.txt";
	#include_function ".\boss2anim.txt";
	
task attack{
	let angle=rand(0, 359);
	loop{
		angle=rand(0, 359);
		PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
		PlaySEDelay(GetCurrentScriptDirectory~"sound\BulletWave.wav", 160);
		ascent(i in 0..30){
			ascent(j in 1..4){
				if(i%6<3){
					ShotA(j, angle+i*12+j*4);
				}else{
					ShotB(GetX, GetY, 0, j, angle+i*12+j*4, 0.5, 15);
				}
			}
		}
		loop(50){yield;}
		move;
		loop(100){yield;}
		angle=rand(0, 359);
		PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
		PlaySEDelay(GetCurrentScriptDirectory~"sound\BulletWave.wav", 160);
		ascent(i in 0..30){
			ascent(j in 1..4){
				if(i%6<3){
					ShotA(j, angle+i*12+j*4);
				}else{
					ShotB(GetX, GetY, 0, j, angle+i*12+j*4, -0.5, 15);
				}
			}
		}
		loop(50){yield;}
		move;
		loop(100){yield;}
	}
	
	task ShotA(v, ang){
		let counter=0;
		let obj=Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, GetX, GetY);
		Obj_SetSpeed(obj, v);
		Obj_SetAngle(obj, ang);
		ObjShot_SetGraphic(obj, 3);
		ObjShot_SetDelay(obj, 15);
		ObjShot_ToItem(obj, false);
		while(Obj_BeDeleted(obj)==false){
			if(counter==0){Obj_SetSpeed(obj, Obj_GetSpeed(obj)-v/100);}
			if(Obj_GetSpeed(obj)<=0){
				counter++;
			}
			if(counter==60){
				Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
				Obj_SetSpeed(obj, 2);
				counter=61;
			}
			yield;
		}
	}
	
	task ShotB(x, y, counter, v, ang, mov, d){
		let obj=Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, v);
		Obj_SetAngle(obj, ang);
		ObjShot_SetGraphic(obj, 52);
		ObjShot_SetDelay(obj, d);
		ObjShot_ToItem(obj, false);
		while(Obj_BeDeleted(obj)==false){
			if(counter==0){Obj_SetSpeed(obj, Obj_GetSpeed(obj)-v/100);}
			if(Obj_GetSpeed(obj)<=0){
				counter++;
			}
			if(counter==60){
				Obj_SetAngle(obj, Obj_GetAngle(obj)+mov*10);
				Obj_SetSpeed(obj, 2);
				counter=61;
				ShotB(Obj_GetX(obj), Obj_GetY(obj), 61, v, Obj_GetAngle(obj)+120, mov, 0);
				ShotB(Obj_GetX(obj), Obj_GetY(obj), 61, v, Obj_GetAngle(obj)-120, mov, 0);
			}
			if(counter==61){Obj_SetAngle(obj, Obj_GetAngle(obj)+mov/3);}
			
			yield;
		}
	}
}

sub move{
	let x=GetPlayerX+rand(-100, 100);
	let y=rand(70, 130);
	while(x>GetClipMaxX-20 || x<GetClipMinX+20){
		x=GetPlayerX+rand(-100, 100);
	}
	SetMovePosition03(x, y, 10, 4);
}

task PlaySEDelay(string, time){
	loop(time){yield;}
	PlaySE(string);
}

	@Initialize
	{
		SetInvincibility(200);
		SetLife(700);
		SetDamageRate(100,100);
		SetMovePosition02(GetCenterX,120,20);
		LoadUserShotData(GetCurrentScriptDirectory~"supershot.txt");

		timer;
		SetCommonData("timercount", 4500);
	}
	
	@MainLoop
	{
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
		frame++;
		if(frame==0){attack;}
		yield;
}
	
	@Finalize
	{
	}
	
	@DrawLoop
	{
		anim_idle;
	}
}