#TouhouDanmakufu
#Title[Present "Today's History"]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	let frame=-100;
	let famangle=0;
	let move_count=0;
    	let BossCutIn = GetCurrentScriptDirectory~"img\cutinb.png";
	#include_function ".\keinebanim.txt";
	#include_function ".\spellcard.txt";
task Familiars
{
	CreateEnemyFromScript("Familiar", GetX+65, GetY+75, 0, famangle, 2);
	CreateEnemyFromScript("Familiar", GetX+65, GetY+150, 0, famangle, 2);
	if(famangle==30){famangle=-30;}
	if(famangle==45){famangle=-45;}
	CreateEnemyFromScript("Familiar", GetX-65, GetY+75, 0, famangle, -2);
	CreateEnemyFromScript("Familiar", GetX-65, GetY+150, 0, famangle, -2);
	if(famangle==-30){famangle=60;}
	if(famangle==-45){famangle=45;}
	CreateEnemyFromScript("Familiar", GetX+155, GetY+125, 0, famangle, 2);
	CreateEnemyFromScript("Familiar", GetX+155, GetY+50, 0, famangle, 2);
	if(famangle==60){famangle=-60;}
	if(famangle==45){famangle=-45;}
	CreateEnemyFromScript("Familiar", GetX-155, GetY+125, 0, famangle, -2);
	CreateEnemyFromScript("Familiar", GetX-155, GetY+50, 0, famangle, -2);
	if(famangle==0){famangle=45;}
	else if(famangle==-45){famangle=30;}
	else if(famangle==-60){famangle=0;}
}
task wave
{
	let dist=((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5;
	loop(50)
	{
	dist=((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5;
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	ascent(i in -2..3)
	{
	bullet(GetAngleToPlayer+i*15+rand(-30, 30), rand_int(30, 40), i);
	}
	loop(4){yield;}
	}
}
task bullet(angle, count, i)
{
	let dist=((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5;
	let counter=0;
	let obj=Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, GetX, GetY);
	Obj_SetSpeed(obj, 4);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, 2);
	while(Obj_BeDeleted(obj)==false)
	{
	counter++;
	if(counter==count){Obj_SetSpeed(obj, 0);}
	if(counter==100)
	{
	dist=((GetX-GetPlayerX)^2+(GetY-GetPlayerY)^2)^0.5;
	Obj_SetSpeed(obj, 3);
	Obj_SetAngle(obj, atan2(GetY+dist*sin(GetAngleToPlayer+i*15)-Obj_GetY(obj), GetX+dist*cos(GetAngleToPlayer+i*15)-Obj_GetX(obj)));
	}
	yield;
	}
}
	@Initialize
	{
		SetDamageRate(10+floor(30-30*GetCommonData("timercount")/3600),5);
		SetInvincibility(200);
		SetLife(500);
		SetDamageRate(15,15);
		LoadGraphic(BossCutIn);

		SetMovePosition02(GetCenterX,120,20);
		Concentration01(150);
		CutIn(YOUMU, "Present ''Today's History'' ",BossCutIn,0,0,256,512);
		LoadUserShotData(GetCurrentScriptDirectory~"supershot.txt");

		SetCommonData("ONSPELL", "TRUE");
		spellbonus(3000000);
		timer;
		SetCommonData("timercount", 3600);
	}
	
	@MainLoop
	{
		SetCollisionA(GetX(),GetY(),24);
		SetCollisionB(GetX(),GetY(),24);
		frame++;
		yield;
		if(frame==150)
		{
		Familiars;
		}
		if(frame==275)
		{
		wave;
		}
		if(frame==400)
		{
		frame=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;
	}
}

script_enemy Familiar {
	#include_function ".\famanim.txt";
	let frame=50;
	let angle=GetAngle;
	@Initialize
	{
	SetLife(300);
	SetDamageRateEx(70, 30, 30, 0);
}
	@MainLoop
	{
	yield;
	frame++;
	if(frame>75){angle+=GetArgument;}
	if(frame%7==0)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	ascent(i in 0..2)
	{
	CreateShot01(GetX, GetY, 1, i*180+angle+90, 47, 10);
	}
	}
	if(GetKeyState(VK_SLOWMOVE)==KEY_PULL || GetKeyState(VK_SLOWMOVE)==KEY_FREE)
	{
	SetCollisionA(GetX(),GetY(),24);
	SetCollisionB(GetX(),GetY(),24);
	}
	if(frame==200){VanishEnemy;}
}
	@DrawLoop
	{
	anim2;
}

}