#TouhouDanmakufu
#Title[Red Truth "Logic Error"]
#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;

	@Initialize
	{
		SetLife(6000);
		SetDamageRate(60, 0);
		SetTimer(70);
		SetMovePosition02(GetCenterX, GetCenterY-120, 90);
		LoadUserShotData(shot);
		SetInvincibility(240);
		CutIn(KOUMA, "Red Truth uLogic Errorv", cutin, 0, 0, 368, 350);
		SetScore(600000);

		mainTask;

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

	@MainLoop
	{
		SetCollisionA(GetX, GetY, 64);
		SetCollisionB(GetX, GetY, 48);

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

		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(255);
		DrawGraphic(GetX, GetY);
	}

	@Background
	{		
	}

	@Finalize
	{
	}

	task mainTask
	{
		loop(120){yield;}
		red;
		blue;
		blue2;
		move;
	}

	task red
	{
		let time = 0;
		let shot = 0;

		loop
		{
			CreateShot01(GetPlayerX-40-(105-0.125*shot)+20*cos(shot*22), GetClipMinY, 2, 90, 50, 10);
			CreateShot01(GetPlayerX+40+(105-0.125*shot)+20*cos(shot*22), GetClipMaxY, 2, -90, 50, 10);
			CreateShot01(GetClipMinX, GetPlayerY+40+(105-0.125*shot)+20*sin(shot*22), 2, 0, 50, 10);
			CreateShot01(GetClipMaxX, GetPlayerY-40-(105-0.125*shot)+20*sin(shot*22), 2, 180, 50, 10);
			loop(5){yield;}
			shot++;
		}
	}

	task blue
	{
		let shot = 0;
		
		loop
		{
			CreateShotA(0, GetX-40, GetY, 10);
			SetShotDataA(0, 0, 4, 90, 6, 0, 0, 102);
			SetShotDataA(0, 60, 4, 90+30*cos(shot), 0, -0.05, 1, 102);
			FireShot(0);
			CreateShotA(0, GetX+40, GetY, 10);
			SetShotDataA(0, 0, 4, 90, -6, 0, 0, 102);
			SetShotDataA(0, 60, 4, 90-30*cos(shot), 0, -0.05, 1.2, 102);
			FireShot(0);

			CreateShotA(0, GetX-40, GetY, 10);
			SetShotDataA(0, 0, 4, 90, 6, 0, 0, 102);
			SetShotDataA(0, 60, 4, 90-30*cos(shot), 0, -0.05, 1.2, 102);
			FireShot(0);
			CreateShotA(0, GetX+40, GetY, 10);
			SetShotDataA(0, 0, 4, 90, -6, 0, 0, 102);
			SetShotDataA(0, 60, 4, 90+30*cos(shot), 0, -0.05, 1, 102);
			FireShot(0);

			shot+=19;
			loop(4){yield;}
		}
	}

	task blue2
	{
		loop
		{
			loop(90){yield;}
			CreateShot02(GetX, GetY, 8, GetAngleToPlayer, -0.2, 2, 244, 10);
		}
	}

	task move
	{
		loop
		{
			loop(240){yield;}
			SetMovePosition03(rand(GetPlayerX-60, GetPlayerX+60), GetY, 10, 5);
		}
	}
}