#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main{
        #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"
        #include_function ".\lib\lib_HoutouEx.txt"

	let bounus=3000000;		//スペル基本得点

    	@Initialize
        {
	  SetLife(500);
	  SetDamageRate(0,0);
	  SetMovePosition03(cx,cy-120,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){//スペル取得した時
			PlaySE("seGetSpellCardBonus.wav");			//効果音
			SetCommonData("GetSpell",true);				//スペルを取得したかどうか
		}
	}

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

        task Tmain
        {
		yield;
		SpellCutName(0,192,bounus);		//カード名
		SetMovePosition03(cx,cy-100,10,10);
		SetInvincibility(60);
		SetTimer(41);
		loop(60){yield;}
	 	SetDamageRate(12,1);
		SetAction(ACT_SPELL,60);
		loop(60){yield;}
		let Pangle=0;
		alternative(Level)
		case(1){//hard
			Shot01(17);
		}
		case(0){//easy
			Shot01(7);
		}
	}

	task Shot01(num){
		loop{
			Concentration01(60);
			loop(60){yield;}
			PlaySE(Lazer3);
			SetAction(ACT_SHOT_B,60);
			let angle = GetAngleToPlayer;
			loop(6){
				let H_Obj = Houtou(GetX,GetY, angle, 40, 5, 60, 90, 1, true);
				ObjEffect_SetLayer(H_Obj,5);
				Shot02(angle,num);
				angle += 360 / 6 ;
				loop(4){yield;}
			}
			loop(120){yield;}
			Tmove();
			loop(90){yield;}
		}
	}

	task Shot02(angle,num){
		loop(70){yield;}
		let X = 10;
		let Y = 10;
		loop(num){
			shot02b(GetX+X*cos(angle),GetY+Y*sin(angle),  0, 0.1);
			shot02b(GetX+X*cos(angle),GetY+Y*sin(angle),180,-0.1);
			X += 340 / num;
			Y += 340 / num;
			yield;
		}
	}

        task shot02b(X,Y,angle,Pangle){
                  CreateShotA(1,X,Y,0);
                  SetShotDataA(1, 0,  0,angle,Pangle,0.1,0.4,158);
                  FireShot(1);
        }

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



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

