#東方弾幕風
#Title[冷淡「コールドプリンセス」]
#Text[姫。]
#ScriptVersion[2]

script_enemy_main
{
	let count=-60;
	let bg=0;
	let cirno=0;
	let lv = GetCommonDataDefault("lv",2);
	let cx=GetCenterX();//STGシーンの中心x座標を取得
	let cy=GetCenterY();//STGシーンの中心x座標を取得
	let name        = "冷淡「コールドプリンセス」";
	#include_function ".\lib\lib_anime_Remilia.txt"
	let imageBoss = ".\script\『冷』\img\dot_cirno.png";
	if (lv>2) {name = "冷酷「コールドクイーン」";}
	@Initialize{
		CutIn(KOUMA, name, "", 0, 0, 0, 0);
		LoadGraphic(imageBoss);
		InitializeAction();
		SetLife(3000);
		SetTimer(25);
		SetDamageRate(100,100);
       		SetScore(5000000);
		SetMovePosition02(cx,50,60);
		SetAction(ACT_SPELL,180);
		LoadGraphic("script\『冷』\img\bg.png");
		LoadUserShotData("script\『冷』\heart_bullet.txt");
	}
	
	@MainLoop
	{
		if(0 < GetHitCount)
		{
			PlaySE(".\script\『冷』\sound\enemy_damage.wav");
		}
		if (GetTimer>0 && GetTimer<12 && count%60==0)
		{
			PlaySE(".\script\『冷』\sound\clock.wav");
		}
		count++;
		
		if (count>0) {
		Cirno;
		if ((count%60==0 && lv>1) || (count%120==0 && lv==1) || (count%60==30 && lv>3))
		{
			PlaySE(".\script\『冷』\sound\shot1.wav");
			let angle=0;
			loop(5)
			{
				IceShot(angle,1);
				angle+=72;
			}
		}
		if ((count%60==30 && lv>1) || (count%120==60 && lv==1) || (count%60==0 && lv>3))
		{
			PlaySE(".\script\『冷』\sound\shot1.wav");
			let angle=36;
			loop(5)
			{
				IceShot(angle,2);
				angle+=72;
			}
		}
		if (count%180==120)
		{
			SetMovePosition02(GetPlayerX,50,60);
			SetAction(ACT_MOVE,60);
		}
		if ((count%120==0 && lv>1) || (count%120==60 && lv>2))
		{
			let angle=getAngleToPlayer(GetX,GetY);
			loop(18)
			{
				CreateShot01(GetX+cos(angle)*30,GetY+sin(angle)*30,3,angle,BLUE23,60);
				angle+=40;
			}
		}
		SetCollisionA(GetX(),GetY(),24);//当たり判定(自弾)登録
		SetCollisionB(GetX(),GetY(),12);//当たり判定(体当たり)登録
		}
		yield;
	}
	@DrawLoop{DrawBoss( imageBoss);}
	@BackGround{SetTexture("script\『冷』\img\bg.png");SetAlpha(64);SetGraphicRect(bg,bg,cx*2+bg,cy*2+bg);bg++;DrawGraphic(cx,cy);SetGraphicRect(-bg,-bg,cx*2-bg,cy*2-bg);DrawGraphic(cx,cy);SetGraphicRect(bg,-bg,cx*2+bg,cy*2-bg);DrawGraphic(cx,cy);SetGraphicRect(-bg,bg,cx*2-bg,cy*2+bg);DrawGraphic(cx,cy);}
	task Cirno
	{
		cirno = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(cirno,GetX,GetY);
		ObjShot_SetGraphic(cirno,RED03);
		Obj_SetAlpha(cirno,0);
		yield;
		Obj_Delete(cirno);
	}
	task IceShot(let angle,let img)
	{
		let obj=Obj_Create(OBJ_SHOT);
		Obj_SetAngle(obj,angle);
		Obj_SetPosition(obj,GetPlayerX+cos(angle)*60,GetPlayerY+sin(angle)*60);
		if (lv>2) {Obj_SetSpeed(obj,2);} else {Obj_SetSpeed(obj,1);}
		ObjShot_SetGraphic(obj,img);
		ObjShot_SetDelay(obj,30);
		while(!Obj_BeDeleted(obj) && !Collision_Obj_Obj(obj,cirno) && Obj_GetX(obj)>GetClipMinX && Obj_GetX(obj)<GetClipMaxX && Obj_GetY(obj)>GetClipMinY && Obj_GetY(obj)<GetClipMaxY)
		{
			yield;
		}
		angle = atan2(GetY - Obj_GetY(obj), GetX - Obj_GetX(obj));
		Obj_SetAngle(obj,angle);
		while(!Obj_BeDeleted(obj) && !Collision_Obj_Obj(obj,cirno))
		{
			yield;
		}
		ObjShot_SetGraphic(obj,img+2);
		PlaySE(".\script\『冷』\sound\shot2.wav");
		if (img==1)
		{
			angle=getAngleToPlayer(Obj_GetX(obj),Obj_GetY(obj));
			img=180;
		}
		if (img==2)
		{
			angle=rand(30,150);
			img=0;
		}
		let lr;
		if (angle<0) {angle+=360;}
		if (Obj_GetAngle(obj)<0) {Obj_SetAngle(obj,Obj_GetAngle(obj)+360);}
		let l=angle-Obj_GetAngle(obj);
		let r=angle-(Obj_GetAngle(obj)-360);
		if (absolute(l) < absolute(r)) {lr=-1;} else {lr=1;}
		Obj_SetAngle(obj,trunc(Obj_GetAngle(obj)));
		angle = trunc(angle);
		while(!Obj_BeDeleted(obj))
		{
			img--;
			if (img>0)
			{
				angle=trunc(getAngleToPlayer(Obj_GetX(obj),Obj_GetY(obj)));
				if (angle<0) {angle+=360;}
			}
			if (angle!=Obj_GetAngle(obj))
			{
				Obj_SetAngle(obj,Obj_GetAngle(obj)+lr);
				if (Obj_GetAngle(obj)>360) {Obj_SetAngle(obj,Obj_GetAngle(obj)-360);}
			}
			yield;
		}
		ObjShot_FadeDelete(obj);
		
	}
	function getAngleToPlayer(x, y)
	{
  		return atan2(GetPlayerY - y, GetPlayerX - x);
 	}	
	@Finalize
	{//読みこんだファイルを削除
		loop(16){CreateItem(ITEM_SCORE,GetX+rand(-50,50),GetY+rand(-50,50));}
	}
	
}