#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=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,160,bounus);		//カード名
		SetMovePosition03(cx,cy-100,10,10);
		SetInvincibility(60);
		SetTimer(41);
		loop(60){yield;}
	 	SetDamageRate(15,2);
		SetAction(ACT_SPELL,60);
		loop(60){yield;}
		let Pangle=0;
		alternative(Level)
		case(1){//hard
			Shot01(70);
			Shot02();
		}
		case(0){//easy
			Shot01(10);
			Shot02();
		}
	}

	task Shot01(ways){
		let angle=90;
		loop{
			PlaySE(Lazer3);
			SetAction(ACT_SHOT_A,60);
			loop(ways){
				Shot01a(angle);
				angle += 360 / ways ;
			}
			loop(180){yield;}
		}
	}

	task Shot01a(angle){
		let L = 400;	//自機からの光源までの距離
		let LL = 10; 	//レーザーの長さ
		let obj = Obj_Create(OBJ_LASER);  
		ObjShot_SetGraphic(obj,35);
       	        Obj_SetAlpha(obj,240);
		ObjLaser_SetLength(obj,LL);
		ObjLaser_SetWidth(obj,10);
		ObjLaser_SetSource(obj,false);
		Obj_SetAutoDelete(obj,false);
		loop(60){//回転しながら収束----------------------------------------------------------
			angle+=12;
			Obj_SetX(obj, GetPlayerX+L*cos(angle));
			Obj_SetY(obj, GetPlayerY+L*sin(angle));	
			if(GetPlayerX <= cmx+140){Obj_SetX(obj, cmx+140+L*cos(angle));}
			if(GetPlayerX >= cmX-140){Obj_SetX(obj, cmX-140+L*cos(angle));}
			if(GetPlayerY <= cmy+150){Obj_SetY(obj, cmy+150+L*sin(angle));}
			Obj_SetAngle(obj,angle);
			L -= 350 / 60;
			yield;
		}
		loop(60){//回転----------------------------------------------------------------------
			angle+=12;
			Obj_SetX(obj, GetPlayerX+L*cos(angle));
			Obj_SetY(obj, GetPlayerY+L*sin(angle));	
			if(GetPlayerX <= cmx+140){Obj_SetX(obj, cmx+140+L*cos(angle));}
			if(GetPlayerX >= cmX-140){Obj_SetX(obj, cmX-140+L*cos(angle));}
			if(GetPlayerY <= cmy+150){Obj_SetY(obj, cmy+150+L*sin(angle));}
			Obj_SetAngle(obj,angle);
			yield;
		}
		let X = Obj_GetX(obj);
		let Y = Obj_GetY(obj);
		let P_X = 4*cos(angle);
		let P_Y = 4*sin(angle);
		Obj_SetAutoDelete(obj,true);
		while( !Obj_BeDeleted(obj) ){//射出----------------------------------------------------
			Obj_SetPosition(obj,X,Y);	
			X += P_X;
			Y += P_Y;
			if(ObjLaser_GetEndX(obj) >= cmX+2){//反射--------
				shot01b(1,cmX,ObjLaser_GetEndY(obj),180-angle,1);
				effectshot(cmX,ObjLaser_GetEndY(obj),10,43);
				break;
			}
			if(ObjLaser_GetEndX(obj) <= cmx-2){
				shot01b(1,cmx,ObjLaser_GetEndY(obj),180-angle,1);
				effectshot(cmx,ObjLaser_GetEndY(obj),10,43);
				break;

			}
			if(ObjLaser_GetEndY(obj) <= cmy-2){
				shot01b(2,ObjLaser_GetEndX(obj),cmy,angle * -1,1);
				effectshot(ObjLaser_GetEndX(obj),cmy,10,43);
				break;
			}
			if(ObjLaser_GetEndY(obj) >= cmY+2){
				break;
			}
			yield;
		}
		loop(10){//射出----------------------------------------------------
			Obj_SetPosition(obj,X,Y);
			X += P_X;
			Y += P_Y;
			yield;
		}
		Obj_Delete(obj);
	}

	task shot01b(XorY,X,Y,angle,num){
		PlaySE(Lazer1);
		let L = 120; 	//レーザーの長さ
		let obj = Obj_Create(OBJ_LASER);  
		ObjShot_SetGraphic(obj,35);
       	        Obj_SetAlpha(obj,240);
		ObjLaser_SetLength(obj,L);
		ObjLaser_SetWidth(obj,10);
		ObjLaser_SetSource(obj,false);
		Obj_SetAutoDelete(obj,false);
		Obj_SetAngle(obj,angle+180);
		let P_X = 3*cos(angle);
		let P_Y = 3*sin(angle);
		let LP  = P_X;
		if(XorY == 2){LP  = P_Y;}
		while( !Obj_BeDeleted(obj) ){//射出----------------------------------------------------
			Obj_SetPosition(obj,X,Y);
			X += P_X;
			Y += P_Y;
			if(Obj_GetX(obj) >= cmX+2){//反射--------
				num++;
				shot01b(1,cmX,Obj_GetY(obj),180-angle,num);
				break;
			}
			if(Obj_GetX(obj) <= cmx-2){//反射--------
				num++;
				shot01b(1,cmx,Obj_GetY(obj),180-angle,num);
				break;
			}
			if(Obj_GetY(obj) <= cmy-2){
				num++;
				shot01b(1,Obj_GetX(obj),cmy,angle * -1,num);
				break;
			}
			if(ObjLaser_GetEndY(obj) >= cmY+2){
				break;
			}
			if(num == 3){
				loop(120){
					Obj_SetPosition(obj,X,Y);
					X += P_X;
					Y += P_Y;
					yield;
				}
				break;
			}
			yield;
		}
		loop(60){//射出----------------------------------------------------
			Obj_SetPosition(obj,X,Y);
			X += P_X;
			Y += P_Y;
			yield;
		}
		Obj_Delete(obj);
	}

	task Shot02(){
		loop(180){yield};
		loop{
			PlaySE(arrow01);
			CreateShot01(GetX,GetY,1.0,GetAngleToPlayer,40,10);
			loop(60){yield};
		}
	}



        task effectshot(X,Y,delay,col){
                  CreateShotA(1,X,Y,delay);
                  SetShotDataA(1,0,0,0,0,0,0,col);
                  SetShotKillTime(1,0);
                  FireShot(1);
        }

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

