#東方弾幕風
#Title[冷符「アイシクルイルミネーション」]
#Text[アイシクル。]
#ScriptVersion[2]

script_enemy_main
{
	let count=-60;
	let bg=0;
	let cx=GetCenterX();//STGシーンの中心x座標を取得
	let cy=GetCenterY();//STGシーンの中心x座標を取得
	let name        = "冷符「アイシクルイルミネーション」";
	#include_function ".\lib\lib_anime_Remilia.txt"
	let lv = GetCommonDataDefault("lv",2);
	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(60);
		SetDamageRate(100,100);
       		SetScore(5000000);
		SetMovePosition02(cx,100,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%180==0 && lv>1) || (count%180==90 && lv>3) || (count%360==0 && lv==1))
		{
			StopSE(".\script\『冷』\sound\enemy_powereffect.wav");
			PlaySE(".\script\『冷』\sound\shot2.wav");
			SetAction(ACT_SHOT_B,30);
			loop(2){IceShot;}
			if (GetLife<2000) {loop(2){IceShot;}}
			if (GetTimer<20) {loop(2){IceShot;}}
		}
		if ((count%180==60 && lv>1) || (count%180==150 && lv>3) || (count%360==0 && lv==1))
		{
			PlaySE(".\script\『冷』\sound\enemy_powereffect.wav");
			Concentration02(60);
		}
		
		if ((count%60==0 && lv>1) || (count%120==0 && lv==1) || (count%60==30 && lv>3))
		{
			PlaySE(".\script\『冷』\sound\shot1.wav");
			let angle=getAngleToPlayer(GetX,GetY);
			loop(18)
			{
				if (lv<3) {CreateShot01(GetX+cos(angle)*50,GetY+sin(angle)*50,2,angle,AQUA23,60);}
				else {CreateShot01(GetX+cos(angle)*50,GetY+sin(angle)*50,4,angle,AQUA23,60);}
				angle+=20;
			}
		}
		if (count%600==0)
		{
			SetMovePosition02(rand(50,cx*2-50),rand(50,cy-50),60);
			SetAction(ACT_MOVE,60);
		}

		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 obj=Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,GetX+rand(-50,50),GetY+rand(-50,50));
		Obj_SetAngle(obj,getAngleToPlayer(Obj_GetX(obj),Obj_GetY(obj)));
		if (lv<3) {Obj_SetSpeed(obj,2);} else {Obj_SetSpeed(obj,1);}
		let img = BLUE23+rand_int(0,1)*3;
		ObjShot_SetGraphic(obj,img);
		while(!Obj_BeDeleted(obj))
		{
			Obj_SetAngle(obj,Obj_GetAngle(obj)+rand(-3,3));
			if (count%15==0)
			{
				if (lv<3)
				{
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),1,Obj_GetAngle(obj),img,60);
				} else {
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),0.5,Obj_GetAngle(obj),img,60);
				}
			}
			if (count%60==0)
			{
				if (img==BLUE23) {img = AQUA23;}
				else if (img==AQUA23) {img = WHITE23;}
				else if (img==WHITE23) {img = BLUE23;}
				ObjShot_SetGraphic(obj,img);
			}
			yield;
		}
		
	}
	function getAngleToPlayer(x, y)
	{
  		return atan2(GetPlayerY - y, GetPlayerX - x);
 	}	
	@Finalize
	{//読みこんだファイルを削除
		loop(16){CreateItem(ITEM_SCORE,GetX+rand(-50,50),GetY+rand(-50,50));}
	}
	
}