#東方弾幕風
#Title[冷界「コールドアイスワールド」]
#Text[氷。]
#ScriptVersion[2]

script_enemy_main
{
	let count=-60;
	let bg=0;
	let lv = GetCommonDataDefault("lv",2);
	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(11000);
		SetTimer(80);
		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<1800)
		{
		if ((count%180==60 && lv>1) || (count%180==150 && lv>3) || (count%360==60 && lv==1))
		{
			PlaySE(".\script\『冷』\sound\enemy_powereffect.wav");
			Concentration02(60);
		}
		if ((count%180==0 && lv>1) || (count%180==90 && lv>3) || (count%360==180 && lv==1))
		{
			SetAction(ACT_SHOT_A,60);
			StopSE(".\script\『冷』\sound\enemy_powereffect.wav");
			PlaySE(".\script\『冷』\sound\shot2.wav");
			let angle=getAngleToPlayer(GetX,GetY);
			loop(36)
			{
				CreateShot02(GetPlayerX+cos(angle)*60,GetPlayerY+sin(angle)*60,3,angle,-0.1,0.1,BLUE01,30);
				CreateShot02(GetX+cos(angle)*60,GetY+sin(angle)*60,3,angle,-0.1,0.1,BLUE01,30);
				angle+=10;
			}
		}
		if (count%360==0)
		{
			SetMovePosition02(GetPlayerX,GetPlayerY,180);
			SetAction(ACT_MOVE,180);
		}
		if (count>60 && ((count%5==0 && lv>1) || (count%10==0 && lv==1))) {IceShot;}
		} else if (count>2099){
		if ((count%150==0 && lv>1) || (count%150==75 && lv>3) || (count%300==0 && lv==1))
		{
			PlaySE(".\script\『冷』\sound\enemy_powereffect.wav");
			Concentration02(120);
		}
		if ((count%300==120 && lv>1) || (count%300==240 && lv>3) || (count%600==120 && lv==1))
		{
			SetAction(ACT_SHOT_A,60);
			StopSE(".\script\『冷』\sound\enemy_powereffect.wav");
			PlaySE(".\script\『冷』\sound\enemy_vanish.wav");
			let angle=getAngleToPlayer(GetX,GetY)+30;
			loop(6)
			{
				IceShot2(angle,1);
				IceShot2(angle,0);
				angle+=60;
			}
		}
		if ((count%600==270 && lv>1) || (count%600==390 && lv>3) || (count%1200==540 && lv==1))
		{
			SetAction(ACT_SHOT_A,60);
			StopSE(".\script\『冷』\sound\enemy_powereffect.wav");
			PlaySE(".\script\『冷』\sound\enemy_vanish.wav");
			let angle=getAngleToPlayer(GetX,GetY)+45;
			loop(6)
			{
				IceShot2(angle,1);
				angle+=60;
			}
		}
		if ((count%600==570 && lv>1) || (count%600==90 && lv>3) || (count%1200==1140 && lv==1))
		{
			SetAction(ACT_SHOT_A,60);
			StopSE(".\script\『冷』\sound\enemy_powereffect.wav");
			PlaySE(".\script\『冷』\sound\enemy_vanish.wav");
			let angle=getAngleToPlayer(GetX,GetY)-45;
			loop(6)
			{
				IceShot2(angle,0);
				angle+=60;
			}
		}
		}
		if (count==1800)
		{
			SetMovePosition02(cx,cy,180);
			SetAction(ACT_MOVE,180);
		}
		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 IceShot2(let angle,let lr)
	{
		let obj=Obj_Create(OBJ_SHOT);
		PlaySE(".\script\『冷』\sound\shot1.wav");
		Obj_SetPosition(obj,GetX+cos(angle)*30,GetY+sin(angle)*30);
		if (lv<3){Obj_SetSpeed(obj,3);} else {Obj_SetSpeed(obj,4);}
		ObjShot_SetGraphic(obj,BLUE23);
		ObjShot_SetDelay(obj,30);
		loop(30) {yield;}
		while(!Obj_BeDeleted(obj))
		{
			if (lr) {Obj_SetAngle(obj,getAngleToPlayer(GetX,GetY)+angle);}
			else {Obj_SetAngle(obj,getAngleToPlayer(GetX,GetY)+180+angle);}
			if (count%10==0)
			{
				PlaySE(".\script\『冷』\sound\shot1.wav");
				if (lv<3)
				{
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),0.5,angle+45,BLUE23,60);
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),0.5,angle-45,BLUE23,60);
				} else {
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,angle+45,BLUE23,60);
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,angle-45,BLUE23,60);
				}
			}
			yield;
		}
	}
	task IceShot
	{
		let obj=Obj_Create(OBJ_SHOT);
		Obj_SetAngle(obj,rand(0,360));
		Obj_SetPosition(obj,GetPlayerX+cos(Obj_GetAngle(obj))*60,GetPlayerY+sin(Obj_GetAngle(obj))*60);
		Obj_SetSpeed(obj,0.1);
		ObjShot_SetGraphic(obj,WHITE04);
		ObjShot_SetDelay(obj,30);
		let obj2=Obj_Create(OBJ_SHOT);
		Obj_SetAngle(obj2,rand(0,360));
		Obj_SetPosition(obj2,GetPlayerX+cos(Obj_GetAngle(obj2))*60,GetPlayerY+sin(Obj_GetAngle(obj2))*60);
		Obj_SetSpeed(obj2,0.1);
		ObjShot_SetGraphic(obj,BLUE04);
		ObjShot_SetDelay(obj,30);
		let obj3=Obj_Create(OBJ_SHOT);
		Obj_SetAngle(obj3,rand(0,360));
		Obj_SetPosition(obj3,GetPlayerX+cos(Obj_GetAngle(obj3))*60,GetPlayerY+sin(Obj_GetAngle(obj3))*60);
		Obj_SetSpeed(obj3,0.1);
		ObjShot_SetGraphic(obj3,AQUA04);
		ObjShot_SetDelay(obj3,30);
		let obj4=Obj_Create(OBJ_SHOT);
		Obj_SetAngle(obj4,rand(0,360));
		Obj_SetPosition(obj4,GetX-cos(Obj_GetAngle(obj4))*60,GetY-sin(Obj_GetAngle(obj4))*60);
		Obj_SetSpeed(obj4,0.1);
		ObjShot_SetGraphic(obj4,WHITE04);
		ObjShot_SetDelay(obj4,30);
		let obj5=Obj_Create(OBJ_SHOT);
		Obj_SetAngle(obj5,rand(0,360));
		Obj_SetPosition(obj5,GetX-cos(Obj_GetAngle(obj5))*60,GetY-sin(Obj_GetAngle(obj5))*60);
		Obj_SetSpeed(obj5,0.1);
		ObjShot_SetGraphic(obj5,BLUE04);
		ObjShot_SetDelay(obj5,30);
		let obj6=Obj_Create(OBJ_SHOT);
		Obj_SetAngle(obj6,rand(0,360));
		Obj_SetPosition(obj6,GetX-cos(Obj_GetAngle(obj6))*60,GetY-sin(Obj_GetAngle(obj6))*60);
		Obj_SetSpeed(obj6,0.1);
		ObjShot_SetGraphic(obj6,AQUA04);
		ObjShot_SetDelay(obj6,30);
		if(lv<4)
		{
			loop(30)
			{
				yield;
			}
		} else {
			loop(180)
			{
				yield;
			}
		}
		ObjShot_FadeDelete(obj);
		ObjShot_FadeDelete(obj2);
		ObjShot_FadeDelete(obj3);
		ObjShot_FadeDelete(obj4);
		ObjShot_FadeDelete(obj5);
		ObjShot_FadeDelete(obj6);
		
	}
	function getAngleToPlayer(x, y)
	{
  		return atan2(GetPlayerY - y, GetPlayerX - x);
 	}	
	@Finalize
	{//読みこんだファイルを削除
		loop(16){CreateItem(ITEM_SCORE,GetX+rand(-50,50),GetY+rand(-50,50));}
	}
	
}