#TouhouDanmakufu
#Title["The Pocket Watch of Blood"]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	let frame=100;
	let type=0;
	let angleoffset=0;
	let timestop=0;
	let angle=0;
	let angleb=2;
    	let BossCutIn = GetCurrentScriptDirectory~"img\sakuya_TS.png";
	#include_function ".\sakuyaanim.txt";
	#include_function ".\spellcard.txt";
task red_knife(x, y, v, angle, d)
{
	let counter=0;
	let knifeangle=angle;
	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;
	Obj_SetAngle(obj, knifeangle+angleoffset);
	knifeangle+=0.1;
	if(frame>700){counter=1; Obj_SetSpeed(obj, 1);}
	if(counter==1){Obj_SetSpeed(obj, Obj_GetSpeed(obj)+0.007);}
	}
}
task blue_knife(x, y, v, angle, d)
{
	let counter=0;
	let knifeangle=angle;
	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;
	Obj_SetAngle(obj, knifeangle-angleoffset);
	knifeangle-=0.1;
	if(frame>=750){counter=1; Obj_SetSpeed(obj, 1);}
	if(counter==1){Obj_SetSpeed(obj, Obj_GetSpeed(obj)+0.007);}
	}
}
task knives
{
	ascent(j in 0..20)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	if(j<=17)
	{
	ascent(i in 0..9)
	{
	red_knife(GetX+50*cos(i*40+angle), GetY+50*sin(i*40+angle), 3, i*40+45+angle, 20);
	blue_knife(GetX+50*cos(i*40+10-angle), GetY+50*sin(i*40+10-angle), 3, i*40+10-45-angle, 20);
	}
	}
	angle+=angleb;
	loop(15){yield;}
	angleb+=1;
	}
	angleb-=19;
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		SetDamageRate(10,10);
		
		LoadGraphic(BossCutIn);

		SetMovePosition02(GetCenterX,120,20);
		CutIn(YOUMU, " ''The Pocket Watch of Blood'' ",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==300)
	{
	Concentration01(100);
	}
	if(frame==400)
	{
	knives;
	}
	if(frame==575)
	{
	type=1;
	}
	if(frame==600)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Charge.wav");
	TimeStop(150, 1, 1, 0);
	timestop=1;
	}
	if(frame>=600 && frame<700){angleoffset+=angleb;}
	if(frame==750)
	{
	type=0;
	PlaySE(GetCurrentScriptDirectory~"sound\BulletWave.wav");
	timestop=0;
	frame=290;
	}
}
	
	@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)
	{
	animation3;
	}
	}
}