#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main{
        #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);
	  SetCountDown;

	  CreateEnemyFromScript("Star",GetX,GetY,0,0,0);//ボスパートナー
	  CreateEnemyFromScript("Sunny",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
        {
		let X = GetCommonData("X");//ルナの位置を継続させる
		let Y = GetCommonData("Y");
	 	SetMovePosition02(X,Y,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
			Shot01(40);
		}
		case(0){//easy
			Shot01(80);
		}


		task Shot01(wait){//自機狙い
			loop{
				SetAction(ACT_SHOT_A,20);
				let L = 30;
				let angle = GetAngleToPlayer;
				loop(10){
					PlaySE(shoot13);
					CreateShot01(GetX + L * cos(angle+90),GetY + L * sin(angle+90),2,angle,11,10);
					CreateShot01(GetX + L * cos(angle-90),GetY + L * sin(angle-90),2,angle,11,10);
					L -= 6;
					loop(3){yield}
				}
				Tmove();
				loop(wait){yield;}
			}
		}

        }



	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 Sunny{//逃げる
	#include_function ".\lib\lib_anime_Sunnymilk.txt"
	let imgBoss=GetCurrentScriptDirectory~"img\Boss\dot_sunnymilk.png";

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

	}
	@MainLoop
	{  
                yield;
        } 
	@Finalize
	{       

	}
	@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;//削除
        }

}

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

        #include_function ".\lib\lib_Bosscommon.txt"
        #include_function ".\lib\lib_SpellBouns.txt"
        let cx=GetCenterX;
        let cy=GetCenterY;
    	@Initialize
        {
          InitializeAction();
          SetDamageRateEx(0,0,100,100);		
          LoadGraphic(imgBoss);
          SetInvincibility(90);
          SetLife(4000);
          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;}
		//弾幕-------------------------------------------------------------------------------------
		let way;
		alternative(Level)
		case(1){//hard
			way = 12;
		}
		case(0){//easy
			way = 6;
		}
		loop{
			Tmove();
			Shot01(1,way);
			loop(100){yield;}
			Tmove();
			Shot01(-1,way);
			loop(100){yield;}
		}

		task Shot01(Pangle,way){//Pangleは回転方向
			let angle = 0;
			loop(way){
				PlaySE(arrow01);
				loop(4){
					let speed = 2.8;
					loop(6){
						CreateShot01(GetX,GetY,speed,angle,158,0);
						speed -= 0.2;
					}
					angle += 90 * Pangle;
				}
				angle += 40 * Pangle;
				loop(5){yield;}
			}
		}
        }

        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 );
        }

}


