#TouhouDanmakufu
#Title[Blue Truth "Human Side Support"]
#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(80, 0);
		SetTimer(70);
		SetMovePosition02(GetCenterX, GetCenterY-120, 90);
		LoadUserShotData(shot);
		SetInvincibility(240);
		CutIn(KOUMA, "Blue Truth uHuman Side Supportv", 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
	{
		CreateItem(ITEM_BOMB, GetX, GetY);
	}

	task mainTask
	{
		loop(120){yield;}
		laser;
		blue;
	}

	task laser
	{
		loop
		{
			ascent(a in 0..8)
			{
				CreateLaserB(0, 500, 24, 218, 60);
				SetLaserDataB(0, 0, 0, 40, 0, a*45, 0.5, a*45, 0.4);
				SetShotKillTime(0, 180);
				FireShot(0);
			}
			loop(180){yield;}
			SetMovePosition02(rand(GetPlayerX-60, GetPlayerX+60), GetY, 60);
			loop(90){yield;}
			ascent(a in 0..8)
			{
				CreateLaserB(0, 500, 24, 218, 60);
				SetLaserDataB(0, 0, 0, 40, 0, a*45, -0.5, a*45, -0.4);
				SetShotKillTime(0, 180);
				FireShot(0);
			}
			loop(180){yield;}
			SetMovePosition02(rand(GetPlayerX-60, GetPlayerX+60), GetY, 60);
			loop(90){yield;}
		}
	}

	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+120*cos(shot), 0, -0.05, 2, 102);
			FireShot(0);
			CreateShotA(0, GetX+40, GetY, 10);
			SetShotDataA(0, 0, 4, 90, -6, 0, 0, 102);
			SetShotDataA(0, 60, 4, 90-120*cos(shot), 0, -0.05, 2, 102);
			FireShot(0);

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

			shot+=17;
			loop(2){yield;}
		}
	}
}