#TouhouDanmakufu
#Title[Bernkastel Nonspell 4]
#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";


	@Initialize
	{
		SetLife(3000);
		SetTimer(60);
		SetMovePosition02(GetCenterX, GetCenterY-120, 90);
		LoadUserShotData(shot);
		SetInvincibility(120);

		main;

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

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

		yield;
	}

	@DrawLoop
	{
		SetTexture(enemy);
		SetGraphicRect(0, 0, 191, 480);
		SetGraphicScale(0.2, 0.2);
		DrawGraphic(GetX, GetY);
	}

	@Finalize
	{
	}

	task main
	{
		loop(120){yield;}
		shoot;
		move;
	}

	task shoot
	{
		let shots = [146, 159, 158, 156, 153, 149];
		let angle = 0;

		loop
		{
			loop(96)
			{
				let speed = rand(1, 6);
				let ang = rand(0, 360);
				CreateShotA(0, GetX, GetY, 10);
				SetShotDataA(0, 0, speed, ang, 0, -(speed/120), 0, 225);
				SetShotDataA(0, 180, 0, ang, 3, 0.01, 1, 225);
				SetShotDataA(0, rand(200, 220), NULL, NULL, rand(-0.1, 0.1), 0.01, 1, 225);
				FireShot(0);
			}
			loop(96)
			{
				let speed = rand(1, 6);
				let ang = rand(0, 360);
				CreateShotA(0, GetX, GetY, 10);
				SetShotDataA(0, 0, speed, ang, 0, -(speed/120), 0, 226);
				SetShotDataA(0, 180, 0, ang, -3, 0.01, 1, 226);
				SetShotDataA(0, rand(200, 220), NULL, NULL, rand(-0.1, 0.1), 0.01, 1, 226);
				FireShot(0);
			}
			loop(240){yield;}
		}
	}

	task move
	{
		loop
		{
			loop(240){yield;}
			SetMovePositionRandom01(rand(80, 100), rand(20, 50), 1, GetClipMinX+100, GetClipMinY+100, GetClipMaxX-100, GetCenterY-50);
		}
	}
}