#TouhouDanmakufu
#Title[Mystic Power "Blue Arrow"]
#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(3000);
		SetDamageRate(60, 0);
		SetTimer(70);
		SetMovePosition02(GetCenterX, GetCenterY-120, 90);
		LoadUserShotData(shot);
		SetInvincibility(240);
		CutIn(KOUMA, "Mystic Power uBlue Arrowv", 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
	{
		SetShotColor(255, 255, 255);
	}

	task mainTask
	{
		loop(120){yield;}
		shoot;
		shoot2;
	}

	task shoot
	{
		loop
		{
			loop(50)
			{
				SetShotColor(150, 150, 255);
				shotHoming;
				loop(5){yield;}
				SetShotColor(255, 255, 255);
			}
			loop(120){yield;}
		}
	}

	task shoot2
	{
		loop
		{
			ascent(a in 0..12)
			{
				ascent(b in 0..4)
				{
					CreateShot01(GetX+40*cos(a*30+GetAngleToPlayer), GetY+40*sin(a*30+GetAngleToPlayer), 1.5-0.2*b, a*30+20+10*b+GetAngleToPlayer, 173, 10);
					CreateShot01(GetX+40*cos(a*30+GetAngleToPlayer), GetY+40*sin(a*30+GetAngleToPlayer), 1.5-0.2*b, a*30-20-10*b+GetAngleToPlayer, 173, 10);
				}
			}
			loop(120){yield;}
		}
	}

	task shotHoming
	{
		let timer = 120;
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, GetEnemyX+rand(20, 120)*cos(rand(0, 360)), GetEnemyY+rand(20, 120)*sin(rand(0, 360)));
		Obj_SetSpeed(obj, 0);
		Obj_SetAngle(obj, 0);
		ObjShot_SetGraphic(obj, 229);
		ObjShot_SetDelay(obj, 10);
		ObjShot_SetBombResist(obj, false);
		while(!Obj_BeDeleted(obj))
		{
			timer--;

			if(timer<0)
			{
				Obj_SetSpeed(obj, 3);
			}
			else
			{
				Obj_SetAngle(obj, atan2(GetPlayerY-Obj_GetY(obj), GetPlayerX-Obj_GetX(obj)));
			}

			yield;
		}
	}
}