#東方弾幕風
#Title[冷霧「ホワイトコールドファグ」]
#Text[冷気。]
#ScriptVersion[2]

script_enemy_main
{
	let count=-120;
	let bg=0;
	let lv = GetCommonDataDefault("lv",3);
	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";
	@Initialize{
		CutIn(KOUMA, name, "", 0, 0, 0, 0);
		LoadGraphic(imageBoss);
		InitializeAction();
		SetLife(5000);
		SetTimer(30);
		SetDamageRate(100,100);
       		SetScore(5000000);
		SetMovePosition02(cx,cy,120);
		SetAction(ACT_SPELL,120);
		SetDurableSpellCard;
		LoadGraphic("script\『冷』\img\bg.png");
	}
	
	@MainLoop
	{
		if (GetTimer>0 && GetTimer<12 && count%60==0)
		{
			PlaySE(".\script\『冷』\sound\clock.wav");
		}
		if (count>0)
		{
		if(0 < GetHitCount)
		{
			PlaySE(".\script\『冷』\sound\enemy_damage.wav");
		}
		SetCollisionA(GetX(),GetY(),24);//当たり判定(自弾)登録
		SetCollisionB(GetX(),GetY(),12);//当たり判定(体当たり)登録

		if (count%180==120)
		{
			StopSE(".\script\『冷』\sound\enemy_powereffect.wav");
			PlaySE(".\script\『冷』\sound\enemy_vanish.wav");
			SetAction(ACT_SHOT_A,60);
			IceShot(0);
			if (lv>3) {IceShot(1);}
		}
		if (count%180==10)
		{
			PlaySE(".\script\『冷』\sound\enemy_powereffect.wav");
			Concentration02(50);
		}
		if (count%180==60 && GetTimer<10)
		{
			StopSE(".\script\『冷』\sound\enemy_powereffect.wav");
			PlaySE(".\script\『冷』\sound\enemy_vanish.wav");
			SetAction(ACT_SHOT_A,60);
			IceShot(0);
			if (lv>3) {IceShot(1);}
		}
		if (count%180==70 && GetTimer<10)
		{
			PlaySE(".\script\『冷』\sound\enemy_powereffect.wav");
			Concentration02(50);
		}
		if (count%180==0 && GetTimer<10)
		{
			StopSE(".\script\『冷』\sound\enemy_powereffect.wav");
			PlaySE(".\script\『冷』\sound\enemy_vanish.wav");
			SetAction(ACT_SHOT_A,60);
			IceShot(0);
			if (lv>3) {IceShot(1);}
		}
		if (count%180==130 && GetTimer<10)
		{
			PlaySE(".\script\『冷』\sound\enemy_powereffect.wav");
			Concentration02(50);
		}
		}
		count++;

		SetCollisionB(GetX(),GetY(),12);//当たり判定(体当たり)登録
		yield;
	}
	task IceShot(let bf)
	{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,GetX,GetY);
		ObjShot_SetGraphic(obj,BLUE03);
		let vx = (GetPlayerX-GetX)/120;
		let vy = (GetPlayerY-GetY)/120;
		if (bf) {vy=(-cy-120-GetY)/120;}
		loop(60)
		{
			if (count%10==0){fog(Obj_GetX(obj)+rand(-30,30),Obj_GetY(obj)+rand(-30,30));}
			Obj_SetPosition(obj,Obj_GetX(obj)+vx,Obj_GetY(obj)+vy);
			yield;
		}
		let angle=getAngleToPlayer(Obj_GetX(obj),Obj_GetY(obj));
		let x;
		let y;
		let d;
		if (!Obj_BeDeleted(obj)) {
		loop(6)
		{
			x=Obj_GetX(obj);
			y=Obj_GetY(obj);
			d=60;
			loop(5)
			{
				CreateShot02(x,y,0,angle,BLUE23,0.001,2,70-d);
				if (d%20==0)
				{
					let d2=10;
					loop(d/20)
					{
						CreateShot02(x+cos(angle-60)*d2,y+sin(angle-60)*d2,0,angle-60,0.002,2,BLUE23,70-d);
						CreateShot02(x+cos(angle+60)*d2,y+sin(angle+60)*d2,0,angle+60,0.002,2,BLUE23,70-d);
						d2+=10;
					}
				}
				x+=cos(angle)*10;
				y+=sin(angle)*10;
				d-=10;
			}
			angle+=60;
		}
		PlaySE(".\script\『冷』\sound\shot2.wav");
		}
		ObjShot_SetGraphic(obj,BLUE05);
		Obj_SetAlpha(obj,0);
		loop(180)
		{
			if (Obj_BeDeleted(obj)) {break;}
			if (count%5==0){fog(Obj_GetX(obj)+rand(-40,40),Obj_GetY(obj)+rand(-40,40));}
			yield;
		}
		Obj_Delete(obj);
	}
	task fog(let x,let y)
	{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj,x,y);
		ObjShot_SetGraphic(obj,WHITE01);
		Obj_SetAngle(obj,rand(0,180));
		Obj_SetSpeed(obj,0);
		ObjShot_SetDelay(obj,60);
		loop(120)
		{
			Obj_SetSpeed(obj,Obj_GetSpeed(obj)+0.02);
			if (Obj_GetAngle(obj)>91) {Obj_SetAngle(obj,Obj_GetAngle(obj)-0.2);}
			if (Obj_GetAngle(obj)<89) {Obj_SetAngle(obj,Obj_GetAngle(obj)+0.2);}
			yield;
		}
		ObjShot_FadeDelete(obj);
	}
	@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);}
	function getAngleToPlayer(x, y)
	{
  		return atan2(GetPlayerY - y, GetPlayerX - x);
 	}	
	@Finalize
	{//読みこんだファイルを削除
		loop(16){CreateItem(ITEM_SCORE,GetX+rand(-50,50),GetY+rand(-50,50));}
	}
	
}