#TouhouDanmakufu
#Title[Pawn "Furudo Erika"]
#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 cutin3.png";
	let spell = gd~"img\kakera.png";

	let spella = 0;

	@Initialize
	{
		SetLife(3000);
		SetDamageRate(60, 0);
		SetTimer(70);
		SetMovePosition02(GetCenterX+40, GetCenterY-120, 90);
		LoadUserShotData(shot);
		SetInvincibility(240);
		CutIn(KOUMA, "Pawn uFurudo Erikav", cutin, 0, 0, 421, 350);
		SetScore(600000);

		mainTask;
		CreateEnemyFromScript("erika", 0, 0, 0, 0, 0);

		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_1UP, GetX, GetY);
	}

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

	task shoot
	{
		loop
		{
			loop(120){yield;}
			SetMovePosition02(rand(GetClipMinX+100, GetClipMaxX-100), GetCenterY-140, 60);
			loop(60){yield;}
			CreateShot01(GetX, GetY, 3, GetAngleToPlayer, 244, 10);
			ascent(a in 0..180)
			{
				CreateShot01(GetX, GetY, 3-a*0.01, GetAngleToPlayer+4*sin(a*8), 39, 20);
			}
		}
	}
}

script_enemy erika
{
	let gd = GetCurrentScriptDirectory;
	let shot = gd~"lib\supershot.txt";
	let enemy = gd~"img\erika.png";

	@Initialize
	{
		SetLife(1);
		SetMovePosition02(GetCenterX-40, GetCenterY-120, 90);
		LoadUserShotData(shot);

		main;

		LoadGraphic(enemy);
	}

	@MainLoop
	{
		yield;
	}

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

	@Finalize
	{
	}

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

	task shoot
	{
		loop
		{
			SetMovePosition02(GetCenterX, GetCenterY, 60);
			loop(60){yield;}
			ascent(a in 0..72)
			{
				CreateShotA(0, GetPlayerX+150*cos(a*5), GetPlayerY+160*sin(a*5), 10);
				SetShotDataA(0, 0, 0, a*5, 0, 0, 0, 17);
				SetShotDataA(0, 60, 0, a*5+40, 0, 0.01, 4, 17);
				FireShot(0); 

				CreateShotA(0, GetPlayerX+160*cos(a*5), GetPlayerY+150*sin(a*5), 10);
				SetShotDataA(0, 0, 0, a*5, 0, 0, 0, 17);
				SetShotDataA(0, 60, 0, a*5+80, 0, 0.01, 4, 17);
				FireShot(0); 

				CreateShotA(0, GetPlayerX+160*cos(a*5), GetPlayerY+150*sin(a*5), 10);
				SetShotDataA(0, 0, 0, a*5, 0, 0, 0, 17);
				SetShotDataA(0, 60, 0, a*5-40, 0, 0.01, 4, 17);
				FireShot(0); 

				CreateShotA(0, GetPlayerX+150*cos(a*5), GetPlayerY+160*sin(a*5), 10);
				SetShotDataA(0, 0, 0, a*5, 0, 0, 0, 17);
				SetShotDataA(0, 60, 0, a*5-80, 0, 0.01, 4, 17);
				FireShot(0); 

				CreateShotA(0, GetPlayerX+160*cos(a*5), GetPlayerY+160*sin(a*5), 10);
				SetShotDataA(0, 0, 0, -a*5, 0, 0, 0, 17);
				SetShotDataA(0, 60, 0, rand(0, 360), 0, 0.01, 0.5, 17);
				FireShot(0); 
			}
			loop(120){yield;}
		}
	}

	task shotBounce(let a, let v)
	{
		let bounce = true;
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, GetX, GetY);
		Obj_SetSpeed(obj, 2);
		Obj_SetAngle(obj, a);
		ObjShot_SetGraphic(obj, 65);
		ObjShot_SetDelay(obj, 10);
		ObjShot_SetBombResist(obj, false);
		while(!Obj_BeDeleted(obj))
		{
			if(bounce==true)
			{
				if(Obj_GetY(obj)<GetClipMinY){Obj_SetAngle(obj, -a); bounce = false;}
				if(Obj_GetX(obj)<GetClipMinX||Obj_GetX(obj)>GetClipMaxX){Obj_SetAngle(obj, 180-a); bounce = false;}
			}
			yield;
		}
	}
}