#東方弾幕風
#Title[冷晶「コールドクリスタル」]
#Text[結晶。]
#ScriptVersion[2]

script_enemy_main
{
	let count=-60;
	let lv = GetCommonDataDefault("lv",2);
	let bg=0;
	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(5000);
		SetTimer(50);
		SetDamageRate(100,100);
       		SetScore(5000000);
		SetMovePosition02(cx,cy,60);
		SetAction(ACT_SPELL,180);
		LoadGraphic("script\『冷』\img\bg.png");
	}
	
	@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) {
		if (count==60)
		{
			PlaySE(".\script\『冷』\sound\enemy_powereffect.wav");
			Concentration02(60);
		}
		if (count==180)
		{
			SetAction(ACT_SHOT_A,6000);
			StopSE(".\script\『冷』\sound\enemy_powereffect.wav");
			PlaySE(".\script\『冷』\sound\shot2.wav");
			let angle=getAngleToPlayer(GetX,GetY);
			if (lv<3)
			{
				loop(6)
				{
					IceShot(angle);
					angle+=60;
				}
			} else if (lv==3) {
				loop(8)
				{
					IceShot(angle);
					angle+=45;
				}
			} else {
				loop(12)
				{
					IceShot(angle);
					angle+=30;
				}
			}
		}
		if (count==2100)
		{
			PlaySE(".\script\『冷』\sound\enemy_powereffect.wav");
			Concentration02(60);
		}
		if (count==2220)
		{
			StopSE(".\script\『冷』\sound\enemy_powereffect.wav");
			PlaySE(".\script\『冷』\sound\shot2.wav");
			let angle=getAngleToPlayer(GetX,GetY);
			if (lv<3)
			{
				loop(6)
				{
					IceShot(angle);
					angle+=60;
				}
			} else if (lv==3) {
				loop(8)
				{
					IceShot(angle);
					angle+=45;
				}
			} else {
				loop(12)
				{
					IceShot(angle);
					angle+=30;
				}
			}
		}

		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 IceShot(let angle)
	{
		let obj=Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,GetX,GetY);
		Obj_SetAngle(obj,angle);
		Obj_SetSpeed(obj,1);
		ObjShot_SetGraphic(obj,BLUE23);
		ObjShot_SetDelay(obj,60);
		let count=0;
		while(!Obj_BeDeleted(obj))
		{
			count++;
			if ((count%90==45 && lv>2) || (count%90==0 && lv>1) || (count%180==0 && lv==1))
			{	
				PlaySE(".\script\『冷』\sound\shot2.wav");
				CreateShot02(Obj_GetX(obj),Obj_GetY(obj),1,angle+45,-0.01,-2,BLUE23,60);
				CreateShot02(Obj_GetX(obj),Obj_GetY(obj),1,angle-45,-0.01,-2,BLUE23,60);
			}
			if ((count%60==30 && lv>2) || (count%60==0 && lv>1) || (count%120==0 && lv==1))
			{
				PlaySE(".\script\『冷』\sound\shot2.wav");
				CreateShot02(Obj_GetX(obj),Obj_GetY(obj),0.5,angle+45,-0.01,-1,BLUE23,60);
				CreateShot02(Obj_GetX(obj),Obj_GetY(obj),0.5,angle-45,-0.01,-1,BLUE23,60);
			}
			if ((count%150==75 && lv>2) || (count%150==0 && lv>1) || (count%300==0 && lv==1))
			{
				PlaySE(".\script\『冷』\sound\shot2.wav");
				CreateShot02(Obj_GetX(obj),Obj_GetY(obj),1.5,angle+45,-0.01,-3,BLUE23,60);
				CreateShot02(Obj_GetX(obj),Obj_GetY(obj),1.5,angle-45,-0.01,-3,BLUE23,60);
			}
			yield;
		}
		IceShot(-angle);
		
	}
	function getAngleToPlayer(x, y)
	{
  		return atan2(GetPlayerY - y, GetPlayerX - x);
 	}	
	@Finalize
	{//読みこんだファイルを削除
		loop(16){CreateItem(ITEM_SCORE,GetX+rand(-50,50),GetY+rand(-50,50));}
	}
	
}