#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main{
	#include_function ".\lib\lib_anime_Sunnymilk.txt"
	let imgBoss=GetCurrentScriptDirectory~"img\Boss\dot_sunnymilk.png";

        #include_function ".\lib\lib_Bosscommon.txt"
        #include_function ".\lib\lib_SpellBouns.txt"

    	@Initialize
        {
	  SetLife(2000);
	  SetDamageRate(0,0);
	  SetCountDown;
	  CreateEnemyFromScript("Star",GetX,GetY,0,0,0);//前キャラ描画
	  CreateEnemyFromScript("Luna",GetX,GetY,0,0,0);//ボスパートナー
          Tmain;
	}
	
	@MainLoop
	{  
                yield;
                SetCollisionA(GetX(),GetY(),32);
		SetCollisionB(GetX(),GetY(),16);
		if(GetHitCount<=0){return;}
		if(Hitframe%4==0){
			PlaySE(Hit);
		}
		Hitframe++;
        } 
	
	@Finalize{}

	@DrawLoop
	{//描画
                SetColor(255,255,255);
		SetRenderState(ALPHA);
		DrawBoss( imgBoss );
	}

        task Tmain
        {
	 	SetMovePosition02(cx+250,cy-140,0);//移動
		yield;
		//前のスペルを収得したかどうか--------------------------------------------------------------
		if(GetCommonData("GetSpell")==true){GetSpellEffect( GetCommonData("GetSpellBounus_B") );}

		loop(120){yield;}
		let IceScore = GetCommonData("GetIce");						//得点調査
		let Points=200000+GetGraze*10+IceScore+truncate(GetScore/100)-10000*GetBombCount;
		//カード名
	 	SetDamageRate(70,30);
		SetTimer(31);

		SetMovePosition03(cx-80,cy-120,10,6);//画面内移動---------------------------------------------
	 	SetAction(ACT_MOVE,60);
		loop(60){yield;}
		//弾幕-------------------------------------------------------------------------------------
		alternative(Level)
		case(1){//hard
			let ways = 36;
			loop{
				Shot01(ways, 3, 0,40);//時間差全方位弾
				Shot01(ways, 2,30,70);
				loop(20){yield;}
				Shot02(ways);//回転全方位弾
			}
		}
		case(0){//easy
			let ways = 12;
			loop{
				Shot01(ways, 3, 0,40);//時間差全方位弾
				Shot01(ways, 2,30,70);
				loop(20){yield;}
				Shot02(ways);//回転全方位弾
			}
		}

        }

	function Shot01( ways, speed, delay, delay2){//時間差全方位弾
		loop(delay){yield}
		loop(4){
			let angle = 0;
			PlaySE(arrow01);
			loop(ways){
				CreateShot01(GetX, GetY, speed, angle,33,10);
				angle += 360 / ways;
			}
			loop(20){yield;}
		}
		Tmove();
		loop(delay2){yield;}
	}

	function Shot02( ways){//回転全方位弾
		let angle = 0;
		loop(ways){
			PlaySE(arrow01);
			Shot02b( 0, angle,  2, 73);
			Shot02b(10, angle, -2, 75);
			Shot02b(20, angle,  0, 73);
			FireShot(1);
			angle += 360 / ways;
			yield;
		}
		Tmove();
		loop(90){yield}

		task Shot02b(delay, angle, Pangle, col){
			loop(delay){yield;}
			CreateShotA(1,GetX,GetY,5);
			SetShotDataA(1, 0, 3, angle, Pangle,0,3,col);
			SetShotDataA(1,50, 3, NULL,       0,0,3,col);
			FireShot(1);
		}

	}

	task Tmove(){
 		if(GetX>=GetPlayerX){SetMovePositionRandom01(30,20,2,GetX-30,cy-160,GetX-31,cy-80);}
 		if(GetX<=GetPlayerX){SetMovePositionRandom01(30,20,2,GetX+30,cy-160,GetX+31,cy-80);}
		if(GetX>=cx-20){SetMovePositionRandom01(30,20,2,GetX-30,cy-160,GetX-31,cy-80);}
		if(GetX<=cx-120){SetMovePositionRandom01(30,20,2,GetX+30,cy-160,GetX+31,cy-80);}
		SetAction( ACT_MOVE, 60 );
	}

}

script_enemy Luna{
        #include_function ".\lib\lib_anime_Lunachild.txt"
	let imgBoss=GetCurrentScriptDirectory~"img\Boss\dot_lunachild.png";

        #include_function ".\lib\lib_Bosscommon.txt"
        #include_function ".\lib\lib_SpellBouns.txt"

    	@Initialize
        {
	  SetLife(2000);
	  SetDamageRate(0,0);
          SetInvincibility(90);
	  SetDamageRateEx(0,0,100,100);
          Tmain;

	}
	@MainLoop
	{ 
		
                yield; 
                SetCollisionA(GetX(),GetY(),32);
		SetCollisionB(GetX(),GetY(),16);

		if(GetHitCount<=0){return;}
		if(Hitframe%4==0){
			PlaySE(Hit);
		}
		Hitframe++;
        } 

	@Finalize
	{       
		SetCommonData("X",GetX);//ボスの場所を維持する
		SetCommonData("Y",GetY);
	}
	@DrawLoop
	{//描画
                SetColor(255,255,255);
		SetRenderState(ALPHA);
		DrawBoss( imgBoss );
	}
        
        task Tmain
        {
	 	SetMovePosition02(cx+250,cy-140,0);//移動
		loop(120){yield;}
	 	SetDamageRate(70,30);
		SetTimer(61);
		SetMovePosition03(cx+80,cy-120,10,6);//画面内移動---------------------------------------------
	 	SetAction(ACT_MOVE,60);
		loop(60){yield;}
		//弾幕-------------------------------------------------------------------------------------
		alternative(Level)
		case(1){//hard
			let ways = 36;
			loop{
				Shot01(ways, 2, 0,70);//時間差全方位弾
				Shot01(ways, 3, 0,40);
				loop(20){yield;}
				Shot02(ways);//回転全方位弾
			}
		}
		case(0){//easy
			let ways = 12;
			loop{
				Shot01(ways, 2, 0,70);//時間差全方位弾
				Shot01(ways, 3, 0,40);
				loop(20){yield;}
				Shot02(ways);//回転全方位弾
			}
		}

        }

	function Shot01( ways, speed, delay, delay2){//全方位
		loop(delay){yield}
		loop(4){
			let angle = 0;
			loop(ways){
				CreateShot01(GetX, GetY, speed, angle,35,10);
				angle += 360 / ways;
			}
			loop(20){yield;}
		}
		Tmove();
		loop(delay2){yield;}
	}

	function Shot02( ways){//回転全方位弾
		let angle = 180;
		loop(ways){
			PlaySE(arrow01);
			Shot02b( 0, angle, -2, 75);
			Shot02b(10, angle,  2, 73);
			Shot02b(20, angle,  0, 75);
			angle += 360 / ways;
			yield;
		}
		Tmove();
		loop(120){yield}

		task Shot02b(delay, angle, Pangle,col){
			loop(delay){yield;}
			CreateShotA(1,GetX,GetY,5);
			SetShotDataA(1, 0, 3, angle, Pangle,0,3,col);
			SetShotDataA(1,50, 3, NULL,       0,0,3,col);
			FireShot(1);
		}

	}

        task Tmove(){
                 if(GetX>=cx+120){SetMovePositionRandom01(30,20,2,GetX-30,cy-160,GetX-31,cy-80);}
                 else if(GetX<=cx+20){SetMovePositionRandom01(30,20,2,GetX+30,cy-160,GetX+31,cy-80);}
                 else if(GetX>=GetPlayerX){SetMovePositionRandom01(30,20,2,GetX-30,cy-160,GetX-31,cy-80);}
                 else if(GetX<=GetPlayerX){SetMovePositionRandom01(30,20,2,GetX+30,cy-160,GetX+31,cy-80);}
                 SetAction( ACT_MOVE, 60 );
        }
}

script_enemy Star{
        #include_function ".\lib\lib_anime_Starsapphire.txt"
	let imgBoss=GetCurrentScriptDirectory~"img\Boss\dot_starsapphire.png";

        let cx=GetCenterX;
        let cy=GetCenterY;
    	@Initialize
        {
          InitializeAction();
          LoadGraphic(imgBoss);
          SetInvincibility(90);
          SetLife(4000);
          Tmain;

	}

	@MainLoop
	{  
                yield;
        } 

	@DrawLoop
	{//描画
                SetColor(255,255,255);
		SetRenderState(ALPHA);
		DrawBoss( imgBoss );
	}
        
        task Tmain
        {
                SetAction( ACT_MOVE, 60 );
		SetMovePosition03(cx-300,cy-150,10,6);//画面外移動
		loop(60){yield;}
		VanishEnemy;//削除

        }

}
