#e
#Title[p͗͂Ȃ]
#Text[oςΎRƂȂ]
#PlayLevel[Normal]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\Common.dnh"
	#include_function ".\img\lib_honoka.dnh"
	
	let name = "uӂ҂ƒx撣ҁv";
	let bossImg = CSD ~ "img\dot_honoka.png";
	let bossCut = "";
	let back = CSD ~ "img\back02.png";
	let imgList = [bossImg, bossCut, back];
	
	xIni = cx;
	yIni = TOP + 72;
	let wIni = 180;
	
	let r = 96;
	
	@Initialize {
		SetLife(2000);
		SetDamageRate(0, 0);
		SetScore(8000000);
		SetTimer(77);
		
		ascent(let i in 0..length(imgList)) {
			LoadGraphic(imgList[i]);
		}
		
		CreateCommonDataArea("rabbit");
		CreateCommonDataArea("tortoise");
		SetCommonData("r", r);
		SetCommonData("rabbit", 0);
		SetCommonDataEx("rabbit", "disp", 0);
		SetCommonDataEx("tortoise", "disp", 0);
		LoadUserShotData(CSD ~ "img\shot_all.dnh");
		
		CutIn(YOUMU, name, bossCut, 0, 0, 0, 0);
		TMain;
	}

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

	@DrawLoop {
		DrawBoss(bossImg);
	}

	@Finalize {
		ascent(let i in 0..length(imgList)) {
			DeleteGraphic(imgList[i]);
		}
	}

	@BackGround {
		SetTexture(back);
		SetGraphicRect(0, 0, 384, 448);
		DrawGraphic(cx, cy);
	}

///////////////////////////////////////////////////////////////////////////////////////////////////

	task TMain {
		getReady(wIni);
		SetDamageRate(45, 45);
		
		loop {
			cource;
			wait(120);
			
			CreateEnemyFromScript("rabbit", GetX + 32, GetY, 2, 0, 0);
			CreateEnemyFromScript("tortoise", GetX - 32, GetY, 0.7, 0, 0);
			
			wait(30);
			while(GetCommonData("rabbit") == 1) {
				yield;
			}
		}
		
		task cource {
			let x = cx;
			let y = cy;
			let span = 5;
			let angle = 0;
			let obj = [];
			
			ascent(let i in 0..360/span) {
				obj = obj ~ [Obj_Create(OBJ_SHOT)];
				Obj_SetPosition(obj[i], GetX, GetY);
				Obj_SetAngle(obj[i], direction(Obj_GetX(obj[i]), Obj_GetY(obj[i]), x + cos(angle) * r, y + sin(angle) * r));
				Obj_SetSpeed(obj[i], distance(Obj_GetX(obj[i]), Obj_GetY(obj[i]), x + cos(angle) * r, y + sin(angle) * r) / 90);
				ObjShot_SetGraphic(obj[i], GRAIN + WHITE);
				ObjShot_SetDelay(obj[i], 10);
				angle += span;
			}
			
			wait(100);
			
			angle = 0;
			ascent(let i in 0..360/span) {
				Obj_SetSpeed(obj[i], 0);
			}
			
			wait(30);
			while(GetCommonData("rabbit") == 1) {
				yield;
			}
			
			ascent(let i in 0..360/span) {
				ObjShot_FadeDelete(obj[i]);
			}
		}
	}
}

/**************************************************************************************************

					ETM

**************************************************************************************************/

script_enemy rabbit {
	#include_function ".\lib\Common.dnh"
	
	let speed = GetSpeed;
	let omega = 0;
	let disp = -90;
	let rab;
	
	@Initialize {
		SetLife(2000 / (20 / 100) + 200);
		SetScore(10);
		SetDamageRateEx(100, 100, 20, 20);
		SetCommonData("rabbit", 1);
		
		TMain;
	}
	
	@MainLoop {
		SetCollisionA(GetX, GetY, 16);
		SetCommonDataEx("rabbit", "disp", disp);
		yield;
	}
	
	@DrawLoop {
	}
	
	@Finalize {
		SetCommonData("rabbit", 0);
	}

///////////////////////////////////////////////////////////////////////////////////////////////////

	task TMain {
		standby;
		
		TMove;
		TShot;
	}
	
	sub standby {
		rab = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(rab, GetX, GetY);
		Obj_SetAngle(rab, direction(GetX, GetY, cx + cos(disp) * GetCommonData("r"), cy + sin(disp) * GetCommonData("r")));
		Obj_SetSpeed(rab, distance(GetX, GetY, cx + cos(disp) * GetCommonData("r"), cy + sin(disp) * GetCommonData("r")) / 60);
		ObjShot_SetGraphic(rab, MIDDLEEX + WHITE);
		ObjShot_SetDelay(rab, 20);
		
		loop(80) {
			SetX(Obj_GetX(rab));
			SetY(Obj_GetY(rab));
			yield;
		}
		
		Obj_SetSpeed(rab, 0);
	}
	
	task TMove {
		omega = speed / GetCommonData("r");
		
		while(omega > 0) {
			disp -= radToDeg(omega);
			Obj_SetPosition(rab, cx + cos(disp) * GetCommonData("r"), cy + sin(disp) * GetCommonData("r"));
			SetPosition(Obj_GetX(rab), Obj_GetY(rab));
			
			if(GetHitCount != 0) {
				omega -= 0.03/GetCommonData("r");
			}
			yield;
		}
		
		let t = (disp + 450) / (speed / GetCommonData("r") * 1.8);
		while(GetCommonDataEx("tortoise", "disp") >= -450 + (0.7 / GetCommonData("r") * t)) {
			yield;
		}
		
		omega = speed / GetCommonData("r") * 1.5;
		
		while(disp >= -450) {
			disp -= radToDeg(omega);
			Obj_SetPosition(rab, cx + cos(disp) * GetCommonData("r"), cy + sin(disp) * GetCommonData("r"));
			SetPosition(Obj_GetX(rab), Obj_GetY(rab));
			yield;
		}
		
		ObjShot_FadeDelete(rab);
		SetLife(0);
	}
	
	task TShot {
		while(disp >= -450) {
			loop(round(omega * GetCommonData("r") * 0.7)) {
				CreateShot01(GetX, GetY, rand(0.5, 2), rand(0, 360), RED + KUNAI, 3);
			}
			yield;
		}
	}
}

/**************************************************************************************************

					J

**************************************************************************************************/

script_enemy tortoise {
	#include_function ".\lib\Common.dnh"
	
	let speed = GetSpeed;
	let omega;
	let disp = -90;
	let tor;
	
	@Initialize {
		SetLife(2000 / (10 / 100) + 200);
		SetDamageRateEx(100, 100, 10, 10);
		SetScore(10);
		
		TMain;
	}
	
	@MainLoop {
		SetCollisionA(GetX, GetY, 16);
		SetCommonDataEx("tortoise", "disp", disp);
		yield;
	}
	
	@DrawLoop {
	}
	
	@Finalize {
	}

///////////////////////////////////////////////////////////////////////////////////////////////////

	task TMain {
		standby;
		
		TMove;
		TShot;
	}
	
	sub standby {
		tor = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(tor, GetX, GetY);
		Obj_SetAngle(tor, direction(GetX, GetY, cx + cos(disp) * GetCommonData("r"), cy + sin(disp) * GetCommonData("r")));
		Obj_SetSpeed(tor, distance(GetX, GetY, cx + cos(disp) * GetCommonData("r"), cy + sin(disp) * GetCommonData("r")) / 60);
		ObjShot_SetGraphic(tor, GREEN + MIDDLEEX);
		ObjShot_SetDelay(tor, 20);
		
		loop(80) {
			SetX(Obj_GetX(tor));
			SetY(Obj_GetY(tor));
			yield;
		}
		
		Obj_SetSpeed(tor, 0);
	}
	
	task TMove {
		omega = speed / GetCommonData("r");
		
		while(disp >= -450) {
			disp -= radToDeg(omega);
			Obj_SetPosition(tor, cx + cos(disp) * GetCommonData("r"), cy + sin(disp) * GetCommonData("r"));
			SetPosition(Obj_GetX(tor), Obj_GetY(tor));
			yield;
		}
		
		while(GetCommonDataEx("rabbit", "disp") > -450) {
			yield;
		}
		
		ObjShot_FadeDelete(tor);
		SetLife(0);
	}
	
	task TShot {
		let way = 16;
		let angle;
		loop {
			angle = direction(GetX, GetY, GetPlayerX, GetPlayerY);
			loop(way) {
				CreateShot01(GetX, GetY, 1, angle, GREEN + WEDGE, 2);
				angle += 360 / way;
			}
			
			wait(70);
		}
	}
}