#e
#Title[ĂET]
#Text[āA̍͂܂eRfĂȂ񂾂]
#PlayLevel[Normal]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\Common.dnh"
	#include_function ".\img\lib_honoka.dnh"
	
	let name = "wuɂpSv";
	let bossImg = CSD ~ "img\dot_honoka.png";
	let bossCut = "";
	let back = CSD ~ "img\back02.png";
	let imgList = [bossImg, bossCut, back];
	
	let se = CSD ~ "se\tm2_scratch000.wav";
	
	xIni = cx;
	yIni = TOP + 72;
	let wIni = 180;
	
	let r = 96;
	
	@Initialize {
		SetLife(2100);
		SetDamageRate(0, 0);
		SetScore(8000000);
		SetTimer(77);
		
		ascent(let i in 0..length(imgList)) {
			LoadGraphic(imgList[i]);
		}
		
		LoadSE(se);
		
		CreateCommonDataArea("racoon");
		CreateCommonDataArea("rabbit");
		SetCommonData("r", r);
		SetCommonData("racoon", 0);
		SetCommonDataEx("racoon", "disp", 0);
		SetCommonDataEx("rabbit", "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 {
		SetAlpha(255);
		DrawBoss(bossImg);
	}

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

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

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

	task TMain {
		getReady(wIni);
		SetDamageRate(36, 20);
		
		loop {
			cource;
			wait(120);
			
			CreateEnemyFromScript("racoon", GetX + 32, GetY, 0.8, 0, 0);
			CreateEnemyFromScript("rabbit", GetX - 32, GetY, 1, 0, 0);
			
			wait(30);
			while(GetCommonData("racoon") == 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);
				ObjShot_SetBombResist(obj[i], true);
				angle += span;
			}
			
			wait(100);
			
			angle = 0;
			ascent(let i in 0..360/span) {
				Obj_SetSpeed(obj[i], 0);
			}
			
			wait(30);
			while(GetCommonData("racoon") == 1) {
				yield;
			}
			
			ascent(let i in 0..360/span) {
				ObjShot_FadeDelete(obj[i]);
			}
		}
	}
}

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

					K

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

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

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

	task TMain {
		standby;
		
		TMove;
		TShot;
	}
	
	sub standby {
		rac = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(rac, GetX, GetY);
		Obj_SetAngle(rac, direction(GetX, GetY, cx + cos(disp) * GetCommonData("r"), cy + sin(disp) * GetCommonData("r")));
		Obj_SetSpeed(rac, distance(GetX, GetY, cx + cos(disp) * GetCommonData("r"), cy + sin(disp) * GetCommonData("r")) / 60);
		ObjShot_SetGraphic(rac, MIDDLEEX + ORANGE);
		ObjShot_SetBombResist(rac, true);
		ObjShot_SetDelay(rac, 20);
		
		loop(80) {
			SetX(Obj_GetX(rac));
			SetY(Obj_GetY(rac));
			yield;
		}
		
		Obj_SetSpeed(rac, 0);
	}
	
	task TMove {
		omega = speed / GetCommonData("r");
		
		while(GetCommonDataEx("rabbit", "disp") < 0) {
			disp -= radToDeg(omega);
			Obj_SetPosition(rac, cx + cos(disp) * GetCommonData("r"), cy + sin(disp) * GetCommonData("r"));
			SetPosition(Obj_GetX(rac), Obj_GetY(rac));
			
			yield;
		}
		
		omega = speed / GetCommonData("r") * 3;
		
		while(disp >= -810) {
			disp -= radToDeg(omega);
			Obj_SetPosition(rac, cx + cos(disp) * GetCommonData("r"), cy + sin(disp) * GetCommonData("r"));
			SetPosition(Obj_GetX(rac), Obj_GetY(rac));
			yield;
		}
		
		ObjShot_FadeDelete(rac);
		SetLife(0);
	}
	
	task TShot {
		let way = 32;
		let angle;
		
		while(GetCommonDataEx("rabbit", "disp") < 0) {
			angle = direction(Obj_GetX(rac), Obj_GetY(rac), GetPlayerX, GetPlayerY);
			loop(way) {
				CreateShot01(Obj_GetX(rac), Obj_GetY(rac), 1.5, angle, ORANGE + RICE, 5);
				angle += 360 / way;
			}
			wait(50);
		}
		
		while(disp >= -810) {
			loop(round(omega * GetCommonData("r") / 1.7)) {
				CreateShot01(Obj_GetX(rac), Obj_GetY(rac), rand(1.2, 2.8), rand(0, 360), FIRE, 2);
			}
			yield;
		}
	}
}

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

					e

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

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

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

	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, WHITE + MIDDLEEX);
		ObjShot_SetBombResist(rab, true);
		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") * 1.8;
		
		wait(300);
		
		while(GetCommonDataEx("racoon", "disp") <= disp) {
			disp -= radToDeg(omega);
			Obj_SetPosition(rab, cx + cos(disp) * GetCommonData("r"), cy + sin(disp) * GetCommonData("r"));
			SetPosition(Obj_GetX(rab), Obj_GetY(rab));
			yield;
		}
		
		loop(110) {
			disp = GetCommonDataEx("racoon", "disp");
			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 {
		let way = 16;
		let angle;
		
		while(GetCommonDataEx("racoon", "disp") <= disp) {
			yield;
		}
		
		loop(3) {
			loop(rand_int(4, 9)) {
				CreateShot01(Obj_GetX(rab), Obj_GetY(rab), rand(1.5, 2.0), rand(0, 360), RED + KUNAI, 2);
			}
			PlaySE(se);
			wait(30);
		}
	}
}