#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=3500000;		//Xy{_

    	@Initialize
        {
	  SetLife(500);
	  SetDamageRate(0,0);
	  SetMovePosition03(cx,cy-20,10,10);
	  SetAction(ACT_MOVE,60);
	  SetCountDown;
          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",GetX+rand(-70,70),GetY+rand(-70,70),0,0,0,1);
		}
		if(Power>=5){
			loop(10){
				CreateShotFromScript("TenItem",GetX+rand(50,-50),GetY+rand(50,-50),0,0,0,0);
			}
		}
		else if(Power>=3){
			loop(10){
				CreateShotFromScript("P_Item" ,GetX+rand(50,-50),GetY+rand(50,-50),0,0,0,0);
			}
			loop(4){
				CreateShotFromScript("TenItem",GetX+rand(50,-50),GetY+rand(50,-50),0,0,0,0);
			}
		}
		else{
			loop(20){
				CreateShotFromScript("P_Item" ,GetX+rand(50,-50),GetY+rand(50,-50),0,0,0,0);
			}
			loop(2){
				CreateShotFromScript("TenItem",GetX+rand(50,-50),GetY+rand(50,-50),0,0,0,0);
			}
		}

		SetCommonData("SpellCade",false);
		if(GetMissCountInThisSpell == 0 && GetBombCountInThisSpell == 0 && IsTimeOut == false){//Xy擾
			PlaySE("seGetSpellCardBonus.wav");			//ʉ
			SetCommonData("GetSpell",true);				//Xy擾ǂ
		}
	}

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

        task Tmain
        {
		yield;
		SpellCutName(0,224,bounus);		//J[h
		SetInvincibility(60);
		SetTimer(41);
		loop(60){yield;}
	 	SetDamageRate(20,1);
		SetAction(ACT_SPELL,60);
		loop(60){yield;}
		let Pangle=0;
		let ways;
		let speed;
		alternative(Level)
		case(1){//hard
			ways = 24;
			speed = 3.6;
		}
		case(0){//easy
			ways = 9;
			speed = 2.6;
		}
		loop{
			Shot01(ways, speed,80, 30);
			loop(60){yield;}
			Shot01(ways, speed,-80,-30);
			loop(60){yield;}
		}
	}


	function Shot01(ways, speed,angle, Pangle){
		let L = 100;
		let AorB = rand_int(0,1);
		loop(18){
			Shot01b(AorB,ways, L, speed,angle);
			angle += Pangle;
			loop(2){yield;}
		}
	}

	task Shot01b(AorB, ways, L, speed,Angle){
		PlaySE(arrow01);
		let X = cx + L * sin(Angle);
		let Y = cy -20 + L * cos(Angle);
		let angle = atan2(GetPlayerY - Y, GetPlayerX - X);
		if(AorB == 0){
			loop(ways){
				CreateShot01( X, Y,speed,angle,67,10);
				angle += 360 / ways ;
			}
		}
		else{
			loop(ways/3){
				loop(3){CreateShot01( X, Y,speed-rand(0,1),angle+rand(-7,8),67,10);}
				angle += 360 / ways * 3;
			}
		}

	}

}
#include_script".\Item01.txt"
#include_script".\Item02.txt"
#include_script".\Item04.txt"

