#TouhouDanmakufu
#Title[Throwing Master "Knife Barrage" -Lunatic-]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	let frame=-100;
	let move_count=0;
    	let BossCutIn = GetCurrentScriptDirectory~"img\sakuya_TS.png";
	#include_function ".\sakuyaanim.txt";
	#include_function ".\spellcard.txt";
task wave
{
	let angle=0;
	let x=GetClipMinX;
	let y=GetClipMinY;
	loop(50)
	{
	CreateShotA(1, x, y, 0);
	SetShotDataA(1, 0, 3, angle, 0, 0, 0, 215);
	SetShotDataA(1, 5, 0, NULL, 5, 0, 0, 215);
	SetShotDataA(1, 41, 3, NULL, 0, 0, 0, 215);
	FireShot(1);
	y+=(GetClipMaxY-GetClipMinY)/50;
	angle=0;
	yield;
	}
	loop(30)
	{
	CreateShotA(1, x, y, 0);
	SetShotDataA(1, 0, 3, angle, 0, 0, 0, 215);
	SetShotDataA(1, 5, 0, NULL, 5, 0, 0, 215);
	SetShotDataA(1, 41, 3, NULL, 0, 0, 0, 215);
	FireShot(1);
	x+=(GetClipMaxX-GetClipMinX)/30;
	angle=-90;
	yield;
	}
	loop(50)
	{
	CreateShotA(1, x, y, 0);
	SetShotDataA(1, 0, 3, angle, 0, 0, 0, 215);
	SetShotDataA(1, 5, 0, NULL, 5, 0, 0, 215);
	SetShotDataA(1, 41, 3, NULL, 0, 0, 0, 215);
	FireShot(1);
	y-=(GetClipMaxY-GetClipMinY)/50;
	angle=180;
	yield;
	}
	loop(30)
	{
	CreateShotA(1, x, y, 0);
	SetShotDataA(1, 0, 3, angle, 0, 0, 0, 215);
	SetShotDataA(1, 5, 0, NULL, 5, 0, 0, 215);
	SetShotDataA(1, 41, 3, NULL, 0, 0, 0, 215);
	FireShot(1);
	x-=(GetClipMaxX-GetClipMinX)/30;
	angle=90;
	yield;
	}
	wave;
}
task waveb
{
	let angleb=rand(0, 359);
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	ascent(i in 0..40){CreateShot01(GetClipMinX, GetClipMinY, 1, angleb+i*9, 216, 0);}
	loop(15){yield;}
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	ascent(i in 0..40){CreateShot01(GetClipMaxX, GetClipMinY, 1, angleb+i*9, 216, 0);}
	loop(15){yield;}
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	ascent(i in 0..40){CreateShot01(GetClipMinX, GetClipMaxY, 1, angleb+i*9, 216, 0);}
	loop(15){yield;}
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	ascent(i in 0..40){CreateShot01(GetClipMaxX, GetClipMaxY, 1, angleb+i*9, 216, 0);}
	loop(15){yield;}
	waveb;
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		SetDamageRate(10,10);
		LoadGraphic(BossCutIn);

		SetMovePosition02(GetCenterX,120,20);
		Concentration01(150);
		CutIn(YOUMU, "Throwing Master ''Knife Barrage'' ",BossCutIn,0,0,256,512);
		LoadUserShotData(GetCurrentScriptDirectory~"supershot.txt");

		SetCommonData("ONSPELL", "TRUE");
		spellbonus(3000000);
		timer;
		SetCommonData("timercount", 3600);
	}
	
	@MainLoop
	{
		SetDamageRate(10+floor(30-30*GetCommonData("timercount")/3600),5);
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
		frame++;
		yield;
	if(frame==0)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Eff1.wav");
		wave;
	}
	if(frame==80)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Eff1.wav");
		wave;
	}
	if(frame==100)
	{
		waveb;
	}
	move_count++;
	if(move_count == 110)
	{
	SetMovePosition03(rand(GetPlayerX-50, GetPlayerX+50), rand(50, 120), rand(8, 10), 1.5);
	move_count=0;
	}
}
	
	@Finalize
	{
		AddScore(spellbonustotal);
		if(spellbonustotal>0)
		{
		PlaySE(GetCurrentScriptDirectory~"sound\se_cardget.wav");
		loop(50)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-100,100),GetY+rand(20,100));
		}
		}else{
		loop(15)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-100,100),GetY+rand(20,100));
		}
		}
		DeleteGraphic(BossCutIn);
		SetCommonData("ONSPELL", "FALSE");
	}
	
	@DrawLoop
	{
	spellbg;
	anim2;
	}
}