#東方弾幕風
#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(8000);
		SetTimer(70);
		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%240==0)
		{
			PlaySE(".\script\『冷』\sound\clock.wav");
		}
		count++;
		if (count>1200) {count++;}
		if (count>2400) {count++;}
		
		if (count>0) {
		if (count%600==180)
		{
			PlaySE(".\script\『冷』\sound\enemy_powereffect.wav");
			Concentration02(90);
		}
		if (count%600==300)
		{
			SetAction(ACT_SHOT_A,180);
			if (count>1200) {SetAction(ACT_SHOT_A,90);}
			if (count>2400) {SetAction(ACT_SHOT_A,60);}
			StopSE(".\script\『冷』\sound\enemy_powereffect.wav");
		}
		if (count%600>300 && count%600<480 && ((count%40==20 && lv>1) || (count%40==0 && lv==1) || (count%10==0 && lv>2) || (count%10==5 && lv>3)))
		{
			PlaySE(".\script\『冷』\sound\shot1.wav");
			loop(3)	{IceShot;}
			if (count>1200) {loop(3){IceShot;}}
			if (count>2400) {loop(3){IceShot;}}
		}
		if (count>60 && count%600>0 && count%600<200 && ((count%40==20 && lv>1) || (count%40==0 && lv==1) || (count%10==0 && lv>2) || (count%10==5 && lv>3)))
		{
			PlaySE(".\script\『冷』\sound\shot1.wav");
			let angle=getAngleToPlayer(GetX,GetY)-20;
			if (count>2400) {angle-=60;loop(4){CreateShot01(GetX,GetY,lv+1,angle,YELLOW02,60);angle+=20;}angle+=20;}
			if (count>1200) {angle-=20;loop(2){CreateShot01(GetX,GetY,lv+1,angle,YELLOW02,60);angle+=20;}}
			loop(3)	{CreateShot01(GetX,GetY,lv+1,angle,YELLOW02,60);angle+=20;}
		}
		

		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_SetAngle(obj,rand(180,360));
		Obj_SetSpeed(obj,rand(1,10)/(9-lv));
		if (count>1200) {Obj_SetSpeed(obj,rand(1,10)/5*2);}
		if (count>2400) {Obj_SetSpeed(obj,rand(1,10)/5*3);}
		Obj_SetPosition(obj,GetX+cos(Obj_GetAngle(obj))*30,GetY+sin(Obj_GetAngle(obj))*30);
		let img=RED04+rand_int(0,6);
		if (img==WHITE04) {img=ORANGE04;}
		ObjShot_SetGraphic(obj,img);
		ObjShot_SetDelay(obj,30);
		while(!Obj_BeDeleted(obj))
		{
			if (count%300==0)
			{
				PlaySE(".\script\『冷』\sound\shot2.wav");
				break;
			}
			yield;
		}
		ObjShot_SetGraphic(obj,WHITE04);
		let v = Obj_GetSpeed(obj)/15;
		loop(15)
		{
			if (Obj_BeDeleted(obj)) {break;}
			Obj_SetSpeed(obj,Obj_GetSpeed(obj)-v);
			yield;
		}
		loop(180)
		{
			if (Obj_BeDeleted(obj)) {break;}
			yield;
		}
		Obj_SetAngle(obj,rand(86,94));
		if (!Obj_BeDeleted(obj)) {PlaySE(".\script\『冷』\sound\enemy_vanish.wav");}
		while(!Obj_BeDeleted(obj))
		{
			if (3>Obj_GetSpeed(obj))
			{
				Obj_SetSpeed(obj,Obj_GetSpeed(obj)+0.01);
			}
			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));}
	}
	
}