#TouhouDanmakufu
#Title[Manipulation Miracle "Angelica"]
#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 cutin4.png";
	let spell = gd~"img\kakera.png";

	let spella = 0;

	@Initialize
	{
		SetLife(1500);
		//SetDamageRate(15, 0);
		SetTimer(90);
		SetMovePosition02(GetCenterX, GetCenterY-120, 90);
		LoadUserShotData(shot);
		SetInvincibility(240);
		CutIn(KOUMA, "Manipulation Miracle uAngelicav", cutin, 0, 0, 442, 350);
		SetScore(600000);
		SetDurableSpellCard;
		MagicCircle(false);

		mainTask;
		CreateEnemyFromScript("ange", GetX, GetY, 0, 0, 0);
		CreateEnemyFromScript("erika", GetX, GetY, 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
	{
	}

	task mainTask
	{
		loop(120){yield;}
		SetMovePosition03(GetCenterX, GetClipMinY-50, 10, 5);
		loop(660){yield;}
		laser;
		loop(1800){yield;}
		SetMovePosition03(GetCenterX, GetCenterY-120, 10, 3);
		loop(300){yield;}
		shoot;
	}

	task laser
	{
		loop(5)
		{
			CreateLaserA(0, GetX, GetY, 900, 100, 180, 120);
			SetLaserDataA(0, 0, GetAngleToPlayer, 0, 0, 0, 0);
			SetShotKillTime(0, 360);
			FireShot(0);
			CreateLaserA(0, GetX, GetY, 900, 50, 180, 120);
			SetLaserDataA(0, 0, GetAngleToPlayer+60, 0, 0, 0, 0);
			SetShotKillTime(0, 360);
			FireShot(0);
			CreateLaserA(0, GetX, GetY, 900, 50, 180, 120);
			SetLaserDataA(0, 0, GetAngleToPlayer-60, 0, 0, 0, 0);
			SetShotKillTime(0, 360);
			FireShot(0);
			loop(360){yield;}
		}
	}

	task shoot
	{
		let ang = 0;

		loop
		{
			loop(50)
			{
				ascent(a in 0..36)
				{
					CreateShotA(0, GetX+60*cos(10*a+ang), GetY+60*sin(10*a+ang), 10);
					SetShotDataA(0, 0, 4, 10*a+ang+90, -6, 0, 0, 102);
					SetShotDataA(0, 60, NULL, 10*a+ang+90, 0, 0, 0, 102);
					FireShot(0);
				}
				ang+=0.4;
				loop(4){yield;}
			}
			loop(30){yield;}
			loop(50)
			{
				ascent(a in 0..36)
				{
					CreateShotA(0, GetX+60*cos(10*a+ang), GetY+60*sin(10*a+ang), 10);
					SetShotDataA(0, 0, 4, 10*a+ang-90, 6, 0, 0, 102);
					SetShotDataA(0, 60, NULL, 10*a+ang-90, 0, 0, 0, 102);
					FireShot(0);
				}
				ang-=0.4;
				loop(4){yield;}
			}
			loop(30){yield;}
		}
	}
}

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

	@Initialize
	{
		SetLife(1);
		SetMovePosition02(GetCenterX-80, GetCenterY-80, 60);
		LoadUserShotData(shot);

		mainTask;

		LoadGraphic(enemy);
	}

	@MainLoop{yield;}

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

	@Finalize
	{
	}

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

	task shoot
	{
		loop(3)
		{
			SetMovePosition02(rand(GetClipMinX+100, GetClipMaxX-100), rand(GetCenterY-60, GetCenterY-100), 30);
			loop(30){yield;}
			ascent(a in 0..73)
			{
				shotBounce(-90+10*a, 2);
				shotBounce(270-10*a, 2);
				if(GetEnemyLife<1500)
				{
					shotBounce(5*a, 1);
					shotBounce(180+5*a, 1);
				}
				loop(1){yield;}
			}
			loop(47){yield;}
		}
		loop(120){yield;}
		shoot2;
	}

	task shoot2
	{
		loop
		{
			loop(60){yield;}
			SetMovePosition02(rand(GetClipMinX+60, GetCenterX-60), rand(GetCenterY-140, GetCenterY-60), 60);
			loop(60){yield;}
			shoot2b;
			CreateShot01(GetX, GetY, 3, GetAngleToPlayer+30, 243, 10);
			CreateShot01(GetX, GetY, 3, GetAngleToPlayer-30, 243, 10);
			ascent(a in 0..180)
			{
				CreateShot01(GetX, GetY, 3-a*0.01, GetAngleToPlayer+30+5*sin(a*8), 34, 20);
				CreateShot01(GetX, GetY, 3-a*0.01, GetAngleToPlayer-30+5*sin(a*8), 34, 20);
			}
		}
	}

	task shoot2b
	{
		let eang = atan2(GetEnemyY-GetY, GetEnemyX-GetX);
		CreateShotA(0, GetX, GetY, 10);
		SetShotDataA(0, 0, 2, eang, 0, 0, 0, 223);  //225
		ascent(a in 0..8)
		{
			ascent(t in 0..10)
			{
				CreateShotA(1, 10*cos(eang+45*a+180), 10*sin(eang+45*a+180), 10);
				SetShotDataA(1, 0, 0, eang+45*a, 0, 0, 0, 52);  //55
				SetShotDataA(1, 60, 0, eang+45*a, 0, 0.01, 2, 51);
				AddShot(20*(t+1), 0, 1, 0);
			}
		}
		FireShot(0);

		CreateShotA(0, GetX, GetY, 10);
		SetShotDataA(0, 0, 2, 180+eang, 0, 0, 0, 223);  //225
		ascent(a in 0..8)
		{
			ascent(t in 0..10)
			{
				CreateShotA(1, 10*cos(eang+45*a+180), 10*sin(eang+45*a+180), 10);
				SetShotDataA(1, 0, 0, eang+45*a, 0, 0, 0, 52);  //55
				SetShotDataA(1, 60, 0, eang+45*a, 0, 0.01, 2, 51);
				AddShot(20*(t+1), 0, 1, 0);
			}
		}
		FireShot(0);
	}

	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;
		}
	}
}

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

	@Initialize
	{
		SetLife(1);
		SetMovePosition02(GetCenterX+80, GetCenterY-80, 60);
		LoadUserShotData(shot);

		mainTask;

		LoadGraphic(enemy);
	}

	@MainLoop{yield;}

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

	@Finalize
	{
	}

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

	task shoot
	{
		loop(3)
		{
			SetMovePosition02(GetCenterX, GetCenterY, 60);
			loop(60){yield;}
			ascent(a in 0..72)
			{
				CreateShotA(0, GetPlayerX+90*cos(a*5), GetPlayerY+100*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+100*cos(a*5), GetPlayerY+90*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+100*cos(a*5), GetPlayerY+90*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+90*cos(a*5), GetPlayerY+100*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+100*cos(a*5), GetPlayerY+100*sin(a*5), 10);
				SetShotDataA(0, 0, 0, -a*5, 0, 0, 0, 17);
				SetShotDataA(0, 60, 0, rand(0, 360), 0, 0.01, 1, 17);
				FireShot(0); 
			}
			loop(120){yield;}
		}
		loop(120){yield;}
		shoot2;
	}

	task shoot2
	{
		loop
		{
			loop(60){yield;}
			SetMovePosition02(rand(GetCenterX+60, GetClipMaxX-60), rand(GetCenterY-140, GetCenterY-60), 60);
			loop(60){yield;}
			shoot2b;
			CreateShot01(GetX, GetY, 3, GetAngleToPlayer+30, 244, 10);
			CreateShot01(GetX, GetY, 3, GetAngleToPlayer-30, 244, 10);
			ascent(a in 0..180)
			{
				CreateShot01(GetX, GetY, 3-a*0.01, GetAngleToPlayer+30+5*sin(a*8), 39, 20);
				CreateShot01(GetX, GetY, 3-a*0.01, GetAngleToPlayer-30+5*sin(a*8), 39, 20);
			}
		}
	}

	task shoot2b
	{
		let eang = atan2(GetEnemyY-GetY, GetEnemyX-GetX);
		CreateShotA(0, GetX, GetY, 10);
		SetShotDataA(0, 0, 2, eang, 0, 0, 0, 225);  //225
		ascent(a in 0..8)
		{
			ascent(t in 0..10)
			{
				CreateShotA(1, 10*cos(eang+45*a+180), 10*sin(eang+45*a+180), 10);
				SetShotDataA(1, 0, 0, eang+45*a, 0, 0, 0, 52);  //55
				SetShotDataA(1, 60, 0, eang+45*a, 0, 0.01, 2, 55);
				AddShot(20*(t+1), 0, 1, 0);
			}
		}
		FireShot(0);

		CreateShotA(0, GetX, GetY, 10);
		SetShotDataA(0, 0, 2, 180+eang, 0, 0, 0, 225);  //225
		ascent(a in 0..8)
		{
			ascent(t in 0..10)
			{
				CreateShotA(1, 10*cos(eang+45*a+180), 10*sin(eang+45*a+180), 10);
				SetShotDataA(1, 0, 0, eang+45*a, 0, 0, 0, 52);  //55
				SetShotDataA(1, 60, 0, eang+45*a, 0, 0.01, 2, 55);
				AddShot(20*(t+1), 0, 1, 0);
			}
		}
		FireShot(0);
	}
}