#TouhouDanmakufu
#Title[Belief that Human Nature is Good]
#Text[]
#BackGround[User(".\img\cathedral.png", 0, 0)]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	let gd = GetCurrentScriptDirectory;
	let bgm = gd~"FinalAnswer.mp3";
	let shot = gd~"lib\supershot.txt";
	let enemy = gd~"img\bern.png";
	let cutin = gd~"img\bern cutin1.png";
	let spell = gd~"img\kakera.png";

	let spella = 0;
	let dist = 300;

	@Initialize
	{
		SetLife(1);
		SetDamageRate(0, 0);
		SetTimer(120);
		SetMovePosition02(GetCenterX, GetCenterY, 60);
		LoadUserShotData(shot);
		SetInvincibility(240);
		MagicCircle(false);
		CutIn(KOUMA, "Belief that Human Nature is Good", cutin, 0, 0, 368, 350);
		SetScore(500000);
		SetDurableSpellCard;

		mainTask;

		LoadMusic(bgm);
		LoadGraphic(enemy);
		LoadGraphic(spell);
		PlayMusic(bgm);
	}

	@MainLoop
	{
		if(spella<255){spella+=(255/90);}
		if(spella>255){spella=255;}

		if(dist>120){dist-=0.5;}

		yield;
	}

	@DrawLoop
	{
		SetTexture(spell);
		SetGraphicRect(0, 0, 640, 480);
		SetGraphicScale(1, 1);
		SetAlpha(spella);
		DrawGraphic(GetCenterX, GetCenterY);
		
		SetTexture(enemy);
		SetGraphicRect(0, 0, 191, 480);
		SetGraphicScale(0.2, 0.2);
		SetAlpha(100);
		DrawGraphic(GetX, GetY);
	}

	@Background
	{		
	}

	@Finalize
	{
	}

	task mainTask
	{
		loop(120){yield;}
		circle;
		phase1;
	}

	task circle
	{
		let angle = 0;
		loop(864)
		{
			ascent(a in 0..6)
			{
				CreateShotA(0, GetX+dist*cos(a*60+angle), GetY+dist*sin(a*60+angle), 10);
				SetShotDataA(0, 0, 1, a*60+angle, 0, 0, 0, 103);
				FireShot(0);
				CreateShotA(0, GetX+dist*cos(a*60+angle), GetY+dist*sin(a*60+angle), 10);
				SetShotDataA(0, 0, 1, a*60+angle+30, 0, 0, 0, 103);
				FireShot(0);
				CreateShotA(0, GetX+dist*cos(a*60+angle), GetY+dist*sin(a*60+angle), 10);
				SetShotDataA(0, 0, 1, a*60+angle-30, 0, 0, 0, 103);
				FireShot(0);
			}
			angle+=7;
			loop(5){yield;}
		}
	}

	task phase1
	{
		let angle = 0;
		loop(360)
		{
			ascent(a in 0..6)
			{
				CreateShot01(GetX+120*cos(angle+60*a), GetY+120*sin(angle+60*a), 0.4, 180+angle+60*a, 103, 10);
			}
			angle+=2;
			loop(5){yield};
		}
		loop(360){yield;}
		phase2;
	}

	task phase2
	{
		let ang = 0;
		loop(30)
		{
			ascent(a in 0..12)
			{
				CreateShotA(0, GetX+dist*cos(a*30+ang), GetY+dist*sin(a*30+ang), 10);
				SetShotDataA(0, 0, 0, 180+30*a+ang, 0.1*cos(ang*2), 0.01, 0.5, 103);
				FireShot(0);
			}
			ang+=7;
			loop(60){yield;}
		}
		SetMovePosition03(GetX, GetY-120, 10, 2);
		loop(720){yield;}
		SetShotColor(40, 40, 255);
		phase3a;
		phase3b;
	}

	task phase3a
	{
		loop
		{
			CreateLaser01(GetX, GetY, 4, GetAngleToPlayer+90, 200, 60, 64, 10);
			CreateLaser01(GetX, GetY, 4, GetAngleToPlayer+180, 200, 60, 64, 10);
			CreateLaser01(GetX, GetY, 4, GetAngleToPlayer, 200, 60, 64, 10);
			CreateLaser01(GetX, GetY, 4, GetAngleToPlayer-90, 200, 60, 64, 10);
			loop(120){yield;}
		}
	}

	task phase3b
	{
		let angle = 0;
		loop
		{
			CreateShot01(GetX+60*cos(2*angle), GetY+60*sin(angle/2), 3, angle, 64, 10);
			CreateShot01(GetX+60*cos(3*angle), GetY+60*sin(2*angle), 2, angle, 64, 10);
			CreateShot01(GetX+60*cos(angle), GetY+60*sin(-angle), 1, angle, 64, 10);
			angle+=7;
			yield;
		}
	}
}