#TouhouDanmakufu
#Title[Reincarnation "Bridge to the Heavens" -Lunatic-]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	let frame=-100;
	let angle=0;
	let move_count=0;
    	let BossCutIn = GetCurrentScriptDirectory~"img\cutinb.png";
	#include_function ".\keinebanim.txt";
	#include_function ".\spellcard.txt";
task wave
{
	let x=GetX;
	let y=GetY;
	while(x<GetClipMaxX+20 && x>GetClipMinX-20 && y<GetClipMaxY+20 && y>GetClipMinY-20)
	{
	PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
	x+=15*cos(GetAngleToPlayer);
	y+=15*sin(GetAngleToPlayer);
	bullet(x+40*cos(GetAngleToPlayer+90), y+40*sin(GetAngleToPlayer+90), GetAngleToPlayer+90);
	bullet(x+40*cos(GetAngleToPlayer-90), y+40*sin(GetAngleToPlayer-90), GetAngleToPlayer-90);
	loop(2){yield;}
	}
	loop(60){yield;}
	SetMovePosition02(GetPlayerX+rand(-25, 25), rand(50, 120), 30);
	loop(30){yield;}
	wave;
}
function bullet(x, y, angle)
{
	CreateShotA(1, x, y, 20);
	SetShotDataA(1, 0, 0, 0, 0, 0, 0, 201);
	ascent(i in 0..20)
	{
	CreateShotA(2, 0, 0, 20);
	SetShotDataA(2, 0, 2, angle+i*18, 0, 0, 0, 54);
	SetShotKillTime(2, 45);
	AddShot(0, 1, 2, 0);
	}
	SetShotKillTime(1, 30);
	FireShot(1);
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		SetDamageRate(15,15);
		LoadGraphic(BossCutIn);

		SetMovePosition02(GetCenterX,120,20);
		Concentration01(150);
		CutIn(YOUMU, " Reincarnation ''Bridge to the Heavens'' ",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==50)
		{
		wave;
		}
		if(frame>50 && frame%7==0)
		{
		angle=rand(0, 359);
		PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
		ascent(i in 0..20)
		{
		CreateShot01(GetX, GetY, 3, angle+i*18, 47, 20);
		}
		}
}
	
	@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;
	}
}