#e
#Title[gRCh}`]
#Text[gRChHTCNChH@Ⴂ킩Ƃłorz
̃XsOtĂK݂Ȃ̂]
#PlayLevel[Normal]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\Common.dnh"			// Rt@C
	#include_function ".\lib\lib_anime_Mokou.dnh"	// KMAPl̃Aj[VpRt@C
	
	let name = "TCNCh}`\eXg";
	let bossImg = CSD ~ "img\dot_mokou.png";
	let back = CSD ~ "img\back2.png";
	
	let xIni = cx;
	let yIni = GetClipMinY + 64;
	let wIni = 120;
	
	@Initialize {
		SetLife(2500);
		SetDamageRate(30, 30);
		SetScore(2500000);
		SetTimer(60);
		
		LoadUserShotData(CSD ~ "img\shot_All.dnh");
		LoadGraphic(bossImg);
		LoadGraphic(back);
		
		CutIn(YOUMU, name, "", 0, 0, 0, 0);
		
		InitializeAction;
		
		TMain;
	}

	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 64);
		yield;
	}

	@DrawLoop {
		DrawBoss(bossImg);
	}

	@Finalize {
		DeleteGraphic(bossImg);
	}

	@BackGround {
		SetGraphicRect(0, 0, 384, 448);
		SetTexture(back);
		DrawGraphic(cx, cy);
	}
	
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
	
	task TMain {
		getReady(wIni);			// ʒu(xIni, yIni)Ɉړ@Commoñt@CɋLq
		yield;
		
		shot(cx, cy, 96, 5, 2, 0, -90, 1.5, BLUE + RICE);
		
	}
	
	task shot(_x,			// ~̒ŜW
			 _y, 			// ~̒ŜW
			 _r, 			// ~̔a
			 _vertex,		// _
			 _spin,			// ]
			 _distance,		// ~̔a1ƂƂ̒e̔Ɠ~Ƃ̋@_distance=0ŉ~A0<_distance<2ŉ~̓A_distance<0,2<_distanceŉ~̊Owł
			 _baseAngle, 	// ǂ̊px`n߂邩
			 _omega, 		// px
			 _type			// ẽfUC
			 ) {
		let cx1 = _x;	// ~̒ŜW
		let cy1 = _y;	// ~̒ŜW
		let r1 = _r;	// ~̔a
		let r2 = _r * (_spin / _vertex);			// ~̔a@~̔a(]/_){΂łĂ܂B@(]/_)0`1͈̔͂ɂȂΊOTCNCh̐}`悵܂
		let dist = r2 * _distance / (_spin ^ 1.05);	// e̔Ɠ~̉~Ƃ̋B
													// 1.05ƂlɈӖ͂ȂłBs̏㒚xǂ̗płB
		
		let angle2 = _baseAngle;					// ~̒S猩Ƃ̓~̒S̊px
		let angle3 = _baseAngle;					// ~̒S猩Ƃ̒e̔̊px
		
		let omega = _omega * _spin;		// pẍ̂܂܎gƒx̂ŁAKɕ␳@ɂAǂȈ^Ă(360/_omega)frameŕ`IB
		
		let cx2;						// ~̒ŜW@[vŎg߂ɐɐ錾Ă
		let cy2;						// ~̒ŜW@
		
		let x;							// e̔̂W@
		let y;							// e̔̂W@
		
		let id = 0;						// CreateShotAp̃JE^ϐI
		let w = 400;					// ̃^XNĂ΂Ăen߂܂ł̎
										// _omega𗍂܂Ă悢̂AIɕ̂̃^XNĂԒiɂȂāA_omegaɈႤlnꂽꍇȂȂ̂Œ
		
		loop {
			cx2 = cx1 + cos(angle2) * (r1 - r2);
			cy2 = cy1 + sin(angle2) * (r1 - r2);
			
			x = cx2 + cos(angle3) * (r2 * 0.8 - dist);
			y = cy2 + sin(angle3) * (r2 * 0.8 - dist);
			
			CreateShotA(id, x, y, 5);
			SetShotDataA(id, 0, 0, angle3 + 90, 0, 0, 0, _type);
			SetShotDataA(id, w - (id / 2), 0.5, NULL, 0, 0.0001, 1, _type);
			FireShot(id);
			
			if(id % 6 == 0) {		// ~̉~`@t[ĂԂƔZȂ肷ꍇ̂œKɊԈ
				CreateShotA(id + 1, cx1 + cos(angle2) * r1, cy1 + sin(angle2) * r1, 5);
				SetShotDataA(id + 1, 0, 0, angle2, 0, 0, 0, _type);
				SetShotDataA(id + 1, w - (id / 2), 0.5, NULL, 0, 0, 1, _type);
				FireShot(id + 1);
			}
			
			angle2 += omega;
			angle3 -= omega * (_vertex/_spin - 1);
			id += 2;
			yield;
			
			if(angle2 > (360 * _spin) + _baseAngle || angle2 < -(360 * _spin) + _baseAngle) {	// (spin)疳[v痣E
				break;
			}
		}
	}
}