#TouhouDanmakufu
#Title[Past "Gensoyoko's Roots"]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	let frame=-100;
	let move_count=0;
    	let BossCutIn = GetCurrentScriptDirectory~"img\cutina.png";
	#include_function ".\keineanim.txt";
	#include_function ".\spellcard.txt";
task root(x, y, angle, type)
{
	let counter=0;
	let splitcount=0;
	let split=rand_int(0, 8);
	let obj=Obj_Create(OBJ_SINUATE_LASER);
	Obj_SetPosition(obj, x, y);
	Obj_SetAngle(obj, angle);
	Obj_SetSpeed(obj, 4);
	ObjShot_SetGraphic(obj, 231);
	ObjSinuateLaser_SetLength(obj, 50);
	ObjSinuateLaser_SetWidth(obj, 5);
	while(Obj_BeDeleted(obj)==false)
	{
	counter++;
	if(counter%5==0 && splitcount==0)
	{
	split++;
	if(split>8){split-=9;}
	if(split==0 && type==1)
	{
	root(Obj_GetX(obj), Obj_GetY(obj), Obj_GetAngle(obj)+rand(270, 90), 2);
	}
	Obj_SetAngle(obj, angle+rand(-40, 40));
	}
	if(counter==40)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	ascent(i in 0..20)
	{
	CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 2+2*type, Obj_GetAngle(obj)+i*18, -0.1, 1, 52, 10);
	}
	Obj_SetSpeed(obj, 0);
	splitcount++;
	}
	if(splitcount>=1){splitcount++;}
	if(splitcount>50)
	{
	Obj_Delete(obj);
	}
	yield;
	}
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		SetDamageRate(10,10);
		LoadGraphic(BossCutIn);

		SetMovePosition02(GetCenterX,120,20);
		Concentration01(150);
		CutIn(YOUMU, "Past ''Gensokoyo's Roots'' ",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%150==0)
		{
		PlaySE(GetCurrentScriptDirectory~"sound\Laser1.wav");
		ascent(i in -3..4)
		{
		root(GetX, GetY, GetAngleToPlayer+i*10, 1);
		}
		}
}
	
	@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;
	}
}