#東方弾幕風
#Title[村紗通常]
#Text[]
#ScriptVersion[2]

script_enemy_main {
	let name	   = "";

	// 初期位置
	let xIni	   = GetCenterX;
	let yIni	   = GetClipMinY + 120;
	
	// ムラサ初期設定
	#include_function ".\lib\setting_murasa.txt"
	// shot_all.png
	#include_function ".\lib_usershot.txt"

	let D_RATE = 100;
	let D_WAIT = 240;

	@Initialize {
		SetLife(2500);
		SetTimer(35);
		SetDamageRate(5, 5);

		Ini_Graphic;

		TMain;
	}

	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);

		yield;
	}

	@DrawLoop {
		Draw_Murasa;
	}

	@Finalize {
		if (!IsTimeOut()) { makeTokutenItem(10); }
//		DeleteGraphic(imgBoss);
	}

	// メインタスク
	task TMain {
		yield;

		TRate;
		standBy;
		powerSave;

		//弾
		TShot;
	}

	//弾射出タスク
	task TShot()
	{
		loop
		{
			let sx = GetX-100;
			let tx = GetX+100;
			let sy = GetY+70;
			let ty = GetY+20;
			shot_movecircle(sx, sy, tx, ty, 25, 1.75,   0, -360*1.5, SHOT_WATER_AQUA, 5, 2);
			shot_movecircle(sx, sy, tx, ty, 25, 1.75, 120,     -180, SHOT_WATER_AQUA, 5, 1);
			shot_movecircle(sx, sy, tx, ty, 25, 3,   0, 360*3, SHOT_WATER_BLUE, 5, 2);
			shot_movecircle(sx, sy, tx, ty, 25, 2, 180,  -240, SHOT_WATER_BLUE, 5, 1);
			shot_sound(25);
			
			splash_hishaku(1);

			loop(25) { yield; }

			sx = GetX+90;
			tx = GetX-90;
			sy = GetY+50;
			ty = GetY+10;
			shot_movecircle(sx, sy, tx, ty, 25, 1.5,   0, 360*2, SHOT_WATER_AQUA, 5, 3);
			shot_movecircle(sx, sy, tx, ty, 25, 1.5,  40,   180, SHOT_WATER_AQUA, 5, 1);
			shot_movecircle(sx, sy, tx, ty, 25,    3,  70, -360*4.1, SHOT_WATER_BLUE, 5, 2.5);
			shot_movecircle(sx, sy, tx, ty, 25, 1.75, -30,      300, SHOT_WATER_BLUE, 5, 1);
			shot_sound(25);

			splash_hishaku(2);

			loop(25) { yield; }

			sx = GetX-80;
			tx = GetX+80;
			sy = GetY+40;
			ty = GetY+10;
			shot_movecircle(sx, sy, tx, ty, 25, 1.25,   0, -360*3, SHOT_WATER_AQUA, 5, 4);
			shot_movecircle(sx, sy, tx, ty, 25, 1.25, 120,   -360, SHOT_WATER_AQUA, 5, 1);
			shot_movecircle(sx, sy, tx, ty, 25,   3, 140, 360*5.2, SHOT_WATER_BLUE, 5, 3);
			shot_movecircle(sx, sy, tx, ty, 25, 1.5, 240,    -360, SHOT_WATER_BLUE, 5, 1);
			shot_sound(25);

			splash_hishaku(1);

			loop(50) { yield; }

			splash_hishaku(0);

			moveBoss(40, 90, 15, 40, 20, 2, 64, 20, 150);
			loop(130) { yield; }
		}
	}

	//発射位置＆発射角度を変えながら撃つ
	task shot_movecircle(sx, sy, tx, ty, timer, speed, angle, a_step, graphic, delay, count)
	{
		let x_step = (tx-sx)/timer;
		let y_step = (ty-sy)/timer;
		let i = 1; let t = 0;
		let as = a_step/(timer*count);
		
		loop(timer)
		{
			while (i > 0)
			{
				CreateShot01(sx+x_step*t/count, sy+y_step*t/count, speed, angle+as*t, graphic, delay);
				i--; t++;
			}
			i += count;
			yield;
		}
	}

	task shot_sound(timer)
	{
		let t = 0;
		while(t < timer)
		{
			StopSE(SE_SHOT2);
			PlaySE(SE_SHOT2);
			wait(2);
			t += 2;
		}
	}

}
