#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"
	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
	{  
                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);				//スペルを取得したかどうか
		}
	}

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

        task Tmain
        {
		yield;
		SpellCutName(256,64,bounus);		//カード名
		SetMovePosition03(cx-80,cy-120,10,6);
		SetInvincibility(300);
		SetTimer(41);
		loop(60){yield;}
	 	SetDamageRate(11,1);
		SetAction(ACT_SPELL,60);
		loop(60){yield;}
		//弾幕-------------------------------------------------------------------------------------
		let Pangle;
		let wait;
		alternative(Level)
		case(1){//hard
			Pangle = 0.2;
			wait = 120;
		}
		case(0){//easy
			Pangle = 0.1;
			wait = 300;
		}
		Shot01(Pangle,wait);
		loop(180){yield;}
		loop{
			if(GetPlayerY <= cy){//上方ペナルティ
				let angle = 0;
				loop(36){
					CreateShot01(GetX,GetY,8,angle,9,0);
					CreateShot01(GetX,GetY,6,angle,9,0);
					CreateShot01(GetX,GetY,5,angle,9,0);
					CreateShot01(GetX,GetY,4,angle,9,0);
					CreateShot01(GetX,GetY,3,angle,9,0);

					angle += 10;
				}
			}
			Tmove();
			loop(120){yield;}
		}
	}

	task Shot01(Pangle,wait){
		let Y = cmy + 40;
		loop{
			Shot01_a( 74, Y, Pangle,0);
			Shot01_a(224, Y, Pangle,1);
			Shot01_a(374, Y, Pangle,0);
			PlaySE(shoot13);
			loop(wait){yield;}
			Shot01_a( 149, Y, Pangle,1);
			Shot01_a( 299, Y, Pangle,1);
			PlaySE(shoot13);
			loop(wait){yield;}
			Shot01_a( 74, Y, Pangle,1);
			Shot01_a(224, Y, Pangle,0);
			Shot01_a(374, Y, Pangle,1);
			PlaySE(shoot13);
			loop(wait){yield;}
			Shot01_a( 149, Y, Pangle,1);
			Shot01_a( 299, Y, Pangle,1);
			PlaySE(shoot13);
			loop(wait){yield;}
		}
	}

	task Shot01_a( X, Y, Pangle,pat){
		let PY= 6;
		let obj = Obj_Create(OBJ_SHOT); 
		Obj_SetX(obj, X);
		Obj_SetY(obj, Y);
		Obj_SetSpeed(obj,0);
		ObjShot_SetGraphic(obj,34);
		ObjShot_SetDelay(obj, 15);
		ObjShot_SetBombResist(obj,true);
		Obj_SetAutoDelete(obj,false);
		Shot01_b(pat);//周辺の弾
		loop(60){
				Obj_SetY(obj, Y);
				Y += PY;
				PY-=0.1;
				yield;
		}
		loop(800){
				Obj_SetY(obj, Y);
				Y += 0.5;
				yield;
		}
		ObjShot_FadeDelete(obj);

		task Shot01_b(pat){//回りの弾配置
			let angle = 0;//回転用変数
			let loops = 6;
			let col = 51;
			let L = 60;
			if(pat){
				loops = 8;
				col = 11;
				L = 50;
			}
			loop(loops){
				Shot01_c(col,L,angle);
				angle += 360 / loops;
			}
		}

		task Shot01_c(col,L,angle){
			let SetAngle = 6;
			let obj2 = Obj_Create(OBJ_SHOT); 
			Obj_SetSpeed(obj2,0);
			ObjShot_SetGraphic(obj2,col);
			ObjShot_SetDelay(obj2, 15);
			loop(60){
					Obj_SetX(obj2, Obj_GetX(obj) + L * cos(angle) );
					Obj_SetY(obj2, Obj_GetY(obj) + L * sin(angle) );
					Obj_SetAngle(obj,angle);
					angle += Pangle + SetAngle;
					SetAngle -= 6 / 60;
					yield;
			}
			loop(800){
					Obj_SetX(obj2, Obj_GetX(obj) + L * cos(angle) );
					Obj_SetY(obj2, Obj_GetY(obj) + L * sin(angle) );
					Obj_SetAngle(obj2,angle);
					angle += Pangle;
					yield;
			}	
			Obj_Delete(obj2);
		}	
	}

	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
	{  
		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("X",GetX);//ルナの場所を維持する
		SetCommonData("Y",GetY);

	}

	@DrawLoop
	{//描画
                SetColor(255,255,255);
		SetRenderState(ALPHA);
		DrawBoss( imgBoss );
	}       
        task Tmain
        {
		yield;
		SetMovePosition03(cx+80,cy-120,10,6);
		loop(60){yield;}
		SetAction(ACT_SPELL,60);
		//弾幕-------------------------------------------------------------------------------------
		loop(180){yield;}
		loop{
			Tmove();
			if(GetPlayerY <= cy){//上方ペナルティ
				let angle = 0;
				loop(36){
					CreateShot01(GetX,GetY,6,angle,11 ,0);
					CreateShot01(GetX,GetY,5,angle,11 ,0);
					CreateShot01(GetX,GetY,4,angle,11 ,0);
					CreateShot01(GetX,GetY,3,angle,11 ,0);
					CreateShot01(GetX,GetY,2,angle,11 ,0);
					angle += 10;
				}
			}
			loop(120){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 );
        }
}
#include_script".\Item01.txt"
#include_script".\Item02.txt"
#include_script".\Item04.txt"

