#e
#Title[uz̊Cv]
#Text[test]
#ScriptVersion[2]

script_enemy_main {
	let name	   = "uz̊Cv";

	// ʒu
	let xIni	   = GetCenterX;
	let yIni	   = GetClipMinY + 120;
	
	// Tݒ
	#include_function ".\lib\setting_murasa.txt"
	// shot_all.png
	#include_function ".\lib_usershot.txt"

	let D_RATE = 100;
	let D_WAIT = 240;

	@Initialize {
		CutIn(YOUMU, name, "", 0, 0, 0, 0);

		SetLife(3000);
		SetTimer(50);
		SetScore(1500000);
		SetDamageRate(5, 5);

		Ini_Graphic;

		TMain;
	}

	@MainLoop {
		//ʒuL^
		SetCommonData("MurasaX", GetX);
		SetCommonData("MurasaY", GetY);

		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);

		yield;
	}

	@DrawLoop {
		Draw_Murasa;
	}

	@Finalize {
		finish_bakuhatu;
		if (!IsTimeOut()) { makeTokutenItem(15); }

		ClearCommonDataEx("MurasaX");
		ClearCommonDataEx("MurasaY");

//		DeleteGraphic(imgBoss);
	}

	// C^XN
	task TMain {
		yield;

		TRate;
		standBy;

		//e
		SetShotDirectionType(ABSOLUTE);
		TShot_Wave;
		wait(60);
		TShot_Ikari;
	}

	//gC_[
	task TShot_Wave()
	{
		let i = 0;
		loop
		{
			let x = rand(GetClipMinX,GetClipMaxX);
			if (rand_int(0,2) == 0)
			{
				shot_seatama(x, 0, 2+sin(x+i)+cos(x+i/4), SHOT_WATER_AQUA, 20, 1);
				shot_seatama(x, 0, 2+cos(x-i)+sin(x-i/3), SHOT_WATER_AQUA, 20, 0);
			}
			else
			{
				shot_seatama(x, 0, 2+sin(x+i)+cos(x+i/4), SHOT_WATER_BLUE, 20, 1);
				shot_seatama(x, 0, 2+cos(x-i)+sin(x-i/3), SHOT_WATER_BLUE, 20, 0);
			}
			if (i%8 == 0)
			{
				StopSE(SE_WATER);
				PlaySE(SE_WATER);
			}
			i++;
			yield;
		}
	}

	//CJ
	task TShot_Ikari()
	{
		loop
		{
			splash_hishaku(1);
			CreateShotFromScript("Ikari",GetX(),GetY(),6,GetAngleToPlayer(),60,0);
			loop(60) { yield; }
			splash_hishaku(2);
			loop(60) { yield; }
			splash_hishaku(0);

			moveBoss(40, 90, 15, 40, 30, 2, 64, 60, 150);

			loop(75) { yield; }
		}
	}
	
	//gۂC_[AP
	function shot_seatama(x, x_spd, y_spd, graphic, wt, type)
	{
		if (type == 0)
			{ CreateShot12(x, GetClipMinY, x_spd, y_spd, 0, -0.033, 0, -y_spd, graphic, wt); }
		else
			{ CreateShot12(x, GetClipMaxY, x_spd, -y_spd, 0, 0.033, 0, y_spd, graphic, wt); }
	}
}

//CJe
script_shot Ikari
{
	let SPEED_MAX = GetSpeed();	//Xs[hől
	let SPEED_REVERCE = -3;		//߂葬x
	let STOPPER = 90;		//~
	let SPEED_GAIN = SPEED_MAX/80;	//x
	let CHILD_TIMER = 9;		//eYފԊu
	let DELAY = GetDelayTime();
	let SIZE = 50;
	let reverse_flag = 0;		//isǗp

	let sx = GetX(); let sy = GetY();
	let speed = 0;
	let scale = 0;
	let ct = CHILD_TIMER/3;
	let t = 0;
	let SOUND_FLAG = 0;

	let imgShot	= GetCurrentScriptDirectory() ~ "\img\ikari.png";

	//}u
	let US_BALL_M_A_BLUE	= 46;

	#include_function ".\lib\lib_se.txt"

	@Initialize
	{
		LoadGraphic(imgShot);
		SetTexture(imgShot);
		SetGraphicRect(  0,   0, 128, 111);
	}
	
	@MainLoop
	{
		if(OnDelay()){
			scale += 2/DELAY; if (scale > 1) { scale = 1; }
			SetSpeed(0);

			if (SOUND_FLAG <= 0)
			{
				PlaySE(SE_KITEKI);
				SOUND_FLAG = 1;
			}
		}
		else
		{
			SetCollisionB(GetX, GetY, 50);	//蔻
			
			//obNI[C
			if (reverse_flag == 1)
			{
				SetAngle(atan2(GetY-GetCommonDataDefault("MurasaY", 0), GetX-GetCommonDataDefault("MurasaX", 0)));
				SetSpeed(SPEED_REVERCE);
				//ˈʒuɋ߂Â
				if (absolute(GetX()-GetCommonDataDefault("MurasaX", 0)) <= 12 && absolute(GetY()-GetCommonDataDefault("MurasaY", 0)) <= 12) { End(); }
			}
			//ʒ[Œ~
			else if (GetX() >= GetClipMaxX-SIZE || GetY() >= GetClipMaxY-SIZE || GetX() <= GetClipMinX+SIZE || GetY() <= GetClipMinY+SIZE)
			{
				if (SOUND_FLAG <= 1)
				{
					PlaySE(SE_WATER2);
					PlaySE(SE_DON19);
					SOUND_FLAG = 2;
				}

				SetSpeed(0);
				STOPPER--;
				if (STOPPER <= 0) {
					reverse_flag = 1;
				}
			}
			//̂܂
			else
			{
				speed += SPEED_GAIN; if (speed > SPEED_MAX) { speed = SPEED_MAX; }
				SetSpeed(speed);

				//~܂Œe
				if (ct <= 0)
				{
					let tmp_s = -180+GetSpeed()/SPEED_MAX*150;
					ascent(let tmp_n in 0..3)
					{
						let tmp_muki = 1;
						loop(2)
						{
							CreateShot02(GetX, GetY, 0, GetAngle+tmp_s*tmp_muki, 1/(40*(1+tmp_n)), 2, US_BALL_M_A_BLUE, 10);
							tmp_muki = -tmp_muki;
						}
					}

					ascent(let tmp_n in 0..2)
					{
						let tmp_muki = 1;
						loop(2)
						{
							CreateShot01(GetX, GetY, 0.5+tmp_n*0.3, GetAngle+tmp_s*tmp_muki, US_BALL_M_A_BLUE, 10);
							tmp_muki = -tmp_muki;
						}
					}
					ct = CHILD_TIMER;
				}
				ct--;
			}
		}
	}
	@DrawLoop
	{
		if(OnDelay()){ SetGraphicScale(scale, scale); }
		SetRenderState(ADD);
		SetGraphicAngle(0, 0, 270+GetAngle);
		DrawGraphic(GetX, GetY);
	}
	@Finalize
	{
	}
}