#TouhouDanmakufu
#Title[Illusion Image "Devil Clock" -Lunatic-]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	let type=0;
	let frame=-100;
	let timestop=0;
    	let BossCutIn = GetCurrentScriptDirectory~"img\sakuya_TS.png";
	#include_function ".\sakuyaanim.txt";
	#include_function ".\spellcard.txt";
task wave
{
	let angle=GetAngleToPlayer+180;
	ascent(i in 0..60)
	{
	ascent(j in -3..4)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	CreateShotA(1, GetX+50*cos(angle+j*25), GetY+50*sin(angle+j*25), i);
	SetShotDataA(1, 0, 0, 0, 0, 0, 0, 218);
	SetShotKillTime(1, 0);
	FireShot(1);
	}
	yield;
	}
	ascent(i in 1..9)
	{
	ascent(j in -3..4)
	{
	ascent(k in -2..3)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	knife(GetX+50*cos(angle+j*25), GetY+50*sin(angle+j*25), i, atan2(GetPlayerY-GetY-50*sin(angle+j*25), GetPlayerX-GetX-50*cos(angle+j*25))+k*40, i*3);
	}
	}
	yield;
	}
	loop(75){yield;}
	type=1;
	loop(25){yield;}
	TimeStop(100, 1, 1, 0);
	timestop=1;
	loop(100){yield;}
	type=0;
	PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");
	timestop=0;
	loop(200){yield;}
	Concentration01(100);
	loop(100){yield;}
	wave;
}
task knife(x, y, v, angle, d)
{
	let counter=0;
	let obj=Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, v);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, 218);
	ObjShot_SetDelay(obj, d);
	while(Obj_BeDeleted(obj)==false)
	{
	yield;
	if(timestop==1)
	{
	counter++;
	if(counter==v*2)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	Obj_SetSpeed(obj, 0);
	knifeb(Obj_GetX(obj), Obj_GetY(obj), 2, Obj_GetAngle(obj)+90, 0);
	knifeb(Obj_GetX(obj), Obj_GetY(obj), 2, Obj_GetAngle(obj)-90, 0);
	}
	}
	if(timestop==0)
	{
	Obj_SetSpeed(obj, v);
	}
	}
}
task knifeb(x, y, v, angle, d)
{
	let counter=0;
	let obj=Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetSpeed(obj, v);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, 216);
	ObjShot_SetDelay(obj, d);
	while(Obj_BeDeleted(obj)==false)
	{
	yield;
	if(counter==0)
	{
	if(Obj_GetX(obj)>GetClipMaxX+10 || Obj_GetX(obj)<GetClipMinX-10){Obj_SetAngle(obj, 180-Obj_GetAngle(obj)); counter++;PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");}
	if(Obj_GetY(obj)>GetClipMaxY+10 || Obj_GetY(obj)<GetClipMinY-10){Obj_SetAngle(obj, 0-Obj_GetAngle(obj)); counter++;PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");}
	}
	if(timestop==1)
	{
	Obj_SetSpeed(obj, 0);
	}
	if(timestop==0)
	{
	Obj_SetSpeed(obj, v);
	}
	}
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		SetDamageRate(10,10);
		
		LoadGraphic(BossCutIn);

		SetMovePosition02(GetCenterX,120,20);
		Concentration01(150);
		CutIn(YOUMU, "Illusion Image ''Devil Clock'' ",BossCutIn,0,0,256,512);
		LoadUserShotData(GetCurrentScriptDirectory~"supershot.txt");

		SetCommonData("ONSPELL", "TRUE");
		spellbonus(3000000);
		timer;
		SetCommonData("timercount", 5400);
	}
	
	@MainLoop
	{
		SetDamageRate(10+floor(30-30*GetCommonData("timercount")/5400),5);
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
		frame++;
		yield;
	if(frame==0)
	{
		wave;
	}
}
	
	@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;
	if(type==0)
	{
	anim2;
	}
	if(type==1)
	{
	animation2;
	}
	}
}