#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"
	let bounus=4000000;		//スペル基本得点

    	@Initialize
        {
	  SetLife(500);
	  SetDamageRate(0,0);
	  SetMovePosition03(cx,cy-120,10,10);
	  SetAction(ACT_MOVE,60);
	  SetCountDown;

	  let X = GetCommonData("X");//ルナの位置を継続させる
	  let Y = GetCommonData("Y");
	  CreateEnemyFromScript("Luna",X,Y,0,0,0);//ボスパートナー
          Tmain;
	}
	
	@MainLoop
	{  
		if(OnEvent()==true){break;}
                yield;
                SetCollisionA(GetX(),GetY(),32);
		SetCollisionB(GetX(),GetY(),16);
		if(GetHitCount<=0){return;}
		if(Hitframe%4==0){
			PlaySE(Hit);
		}
		Hitframe++;
        } 
	
	@Finalize
	{       
		let Power=int(GetCommonData("Power")/100);
		loop(20){
			CreateShotFromScript("I_Item",cx+rand(-160,160),cy+rand(-150,0),0,0,0,1);
		}
		if(Power>=5){
			loop(14){
				CreateShotFromScript("TenItem",cx+rand(-140,140),cy+rand(-140,0),0,0,0,1);
			}
		}
		else if(Power>=3){
			loop(15){
				CreateShotFromScript("P_Item" ,cx+rand(-140,140),cy+rand(-140,0),0,0,0,0);
			}
			loop(7){
				CreateShotFromScript("TenItem",cx+rand(-140,140),cy+rand(-140,0),0,0,0,1);
			}
		}
		else{
			loop(20){
				CreateShotFromScript("P_Item" ,cx+rand(-140,140),cy+rand(-140,0),0,0,0,0);
			}
			loop(3){
				CreateShotFromScript("TenItem",cx+rand(-140,140),cy+rand(-140,0),0,0,0,1);
			}
		}

		SetCommonData("SpellCade",false);
		if(GetMissCountInThisSpell == 0 && GetBombCountInThisSpell == 0 && IsTimeOut == false){//スペル取得した時
			PlaySE("seGetSpellCardBonus.wav");			//効果音
			SetCommonData("GetSpell",true);				//スペルを取得したかどうか
		}
		SetCommonData("X",GetX);//ルナの場所を維持する
		SetCommonData("Y",GetY);
		SetCommonData("33",1);
	}

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

        task Tmain
        {
		yield;
		SpellCutName(256,96,bounus);		//カード名
		SetMovePosition03(cx,cy-140,10,10);
		SetInvincibility(60);
		SetTimer(41);
		loop(60){yield;}
	 	SetDamageRate(12,1);
		SetAction(ACT_SPELL,60);
		loop(60){yield;}
		//弾幕-------------------------------------------------------------------------------------
		loop{
			Shot01;
			loop(320){yield}
		}
	}

	task Shot01(){
		Shot01b( -30, -1);
		Shot01b( +30,  1);

		task Shot01b( angle, Pangle){
			angle += GetAngleToPlayer;
			loop(60){
				PlaySE(arrow01);
				CreateShot01(GetX,GetY,2,angle,11,5);
				angle += Pangle;
				loop(2){yield}
			}
			loop(60){//回転
				PlaySE(arrow01);
				CreateShot01(GetX,GetY,2,angle,11,5);
				angle += 14 * Pangle;
				yield;
			}		
		}
	}
}

script_enemy Luna{
        #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"

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

          Tmain;
	}
	
	@MainLoop
	{  
		if(OnEvent()==true){break;}
                yield;
                SetCollisionA(GetX(),GetY(),32);
		SetCollisionB(GetX(),GetY(),16);
		if(GetHitCount<=0){return;}
		if(Hitframe%4==0){
			PlaySE(Hit);
		}
		Hitframe++;
        } 
	
	@Finalize
	{       

		SetCommonData("X2",GetX);//スターの場所を維持する
		SetCommonData("Y2",GetY);

	}

	@DrawLoop
	{//描画
                SetColor(255,255,255);
		SetRenderState(ALPHA);
		DrawBoss( imgBoss );
	}       
        task Tmain
        {
		yield;
		SetMovePosition03(cx,cy-50,10,10);
		loop(60){yield;}
		SetAction(ACT_SPELL,60);
		loop(60){yield;}
		//弾幕-------------------------------------------------------------------------------------
		alternative(Level)
		case(1){//hard
			Shot01(50,5);
		}
		case(0){//easy
			Shot01(90,3);
		}
	}

	task Shot01(wait,nun){
		let angle=0;
		loop{
			Shot01b(angle,nun);
			angle+=180;
			Tmove();
			loop(wait){yield}
		}

		task Shot01b( angle,nun){
			PlaySE(shoot13);
			let speed = 5;
			let count = 0;//追加弾発射カウント
			let S_speed = 3;//追加弾速度
			let obj = Obj_Create(OBJ_SHOT); 
			Obj_SetX(obj, GetX);
			Obj_SetY(obj, GetY);
			Obj_SetAngle(obj,angle);
			Obj_SetSpeed(obj,speed);
			ObjShot_SetGraphic(obj,166);
			ObjShot_SetDelay(obj, 5);
			ObjShot_SetBombResist(obj,true);
			Obj_SetAutoDelete(obj,false);
			loop(30){
				speed -= 5 / 30;
				Obj_SetSpeed(obj,speed);
				yield;
			}
			Obj_SetAngle(obj,GetAngleToPlayer);
			while(!Obj_BeDeleted(obj)){
				if(count % 30 == 0){
					PlaySE(arrow01);
					S_speed = 2.7;//追加弾速度;
					loop(nun){

						CreateShot01(Obj_GetX(obj),Obj_GetY(obj),S_speed,Obj_GetAngle(obj)+90,159,20);
						CreateShot01(Obj_GetX(obj),Obj_GetY(obj),S_speed,Obj_GetAngle(obj)-90,159,20);
						S_speed -= 0.3;
					}
				}
				Obj_SetSpeed(obj,speed);
				if(speed <= 2){speed += 0.1;}
				count++;
				yield;
			}	
		}
	}

        task Tmove(){
                 if(GetX>=cx+100){SetMovePositionRandom01(70,20,2,GetX-70,cy-120,GetX-71,cy-60);}
                 else if(GetX<=cx-100){SetMovePositionRandom01(70,20,2,GetX+70,cy-120,GetX+71,cy-60);}
                 else if(GetX>=GetPlayerX){SetMovePositionRandom01(70,20,2,GetX-70,cy-120,GetX-71,cy-60);}
                 else if(GetX<=GetPlayerX){SetMovePositionRandom01(70,20,2,GetX+70,cy-120,GetX+71,cy-60);}
                 SetAction( ACT_MOVE, 60 );
        }
}
#include_script".\Item01.txt"
#include_script".\Item02.txt"
#include_script".\Item04.txt"

