#東方弾幕風
#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        = "冷符「リフリジュレイター」";
	let n=0;
	#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(8000);
		SetTimer(70);
		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%600==180)
		{
			PlaySE(".\script\『冷』\sound\enemy_powereffect.wav");
			Concentration02(90);
		}
		
		if (count%600==300)
		{
			StopSE(".\script\『冷』\sound\enemy_powereffect.wav");
			PlaySE(".\script\『冷』\sound\enemy_vanish.wav");
			let angle=getAngleToPlayer(GetX,GetY);
			let x=0;
			let y=0;
			loop(2)
			{
				y=0;
				loop(9)
				{
					IceShot(x,y);
					y+=cy/4.5;
				}
				x=cx*2;
			}
			y=0;
			loop(2)
			{
				x=0;
				loop(9)
				{
					IceShot(x,y);
					x+=cy/4.5;
				}
				y=cy*2;
			}
			x=0;
			loop(n)
			{
				x+=cx*2/(n+1);
				y=0;
				loop(9)
				{
					IceShot(x,y);
					y+=cy/4.5;
				}
			}
			y=0;
			loop(n)
			{
				x=0;
				y+=cy*2/(n+1);
				loop(9)
				{
					IceShot(x,y);
					x+=cx/4.5;
				}
			}
			n++;
		}
		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 x,let y)
	{
		let obj=Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,x,y);
		ObjShot_SetBombResist(obj,true);
		ObjShot_SetGraphic(obj,WHITE03);
		ObjShot_SetDelay(obj,60);
		loop(600)
		{
			if ((count%180==90 && lv==2) || (count%360==90 && lv==1) || (count%180==0 && lv>2))
			{
				PlaySE(".\script\『冷』\sound\shot1.wav");
				if (lv<4) {CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,count/2+45,WHITE04,60);} else {CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,count/2+45+rand(-5,5),WHITE04,60);}
			}
			if (Obj_BeDeleted(obj)) {break;}
			yield;
		}
		Obj_Delete(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));}
	}
	
}