#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"

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

    	@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(256,32,bounus);		//カード名
		SetMovePosition03(cx,cy-100,10,10);
		SetInvincibility(60);
		SetTimer(51);
		loop(60){yield;}
	 	SetDamageRate(20,1);
		SetAction(ACT_SPELL,60);
		loop(60){yield;}
		let Pangle=0;
		alternative(Level)
		case(1){//hard
			Shot01(8);
		}
		case(0){//easy
			Shot01(3);
		}
	}

	task Shot01(num){
		Tmove();
		loop{

			let angle = 0;
			PlaySE(shoot13);
			loop(num){
				Shot01b(angle);
				angle += 360 / num;
				loop(4){yield;}
			}

			loop(300){yield}
		}

		task Shot01b(angle){//誘導星
			let Speed = 5;
			let frame = 0;//スピード制御
			let obj = Obj_Create(OBJ_SHOT); 
			Obj_SetX(obj, GetX);
			Obj_SetY(obj, GetY);
			Obj_SetAngle(obj,angle);
			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;
			}
			loop(3){
				PlaySE(shoot13);
				Shot02( Obj_GetX(obj), Obj_GetY(obj), angle);
				frame = 0;
				Obj_SetAngle(obj,atan2(GetPlayerY - Obj_GetY(obj), GetPlayerX - Obj_GetX(obj) ) );
				loop(50){
					frame += 180 / 50;
					Speed = 5 * sin(frame);
					Obj_SetSpeed(obj, Speed);
					yield;
				}
				loop(60){yield}
			}
			Shot02( Obj_GetX(obj), Obj_GetY(obj), angle);
			Obj_Delete(obj);
		}
	}

	task Shot02(X,Y,angle){
			loop(9){
				CreateShot01(X, Y, 2, angle,117,10);
				angle += 360 / 9;
			}
	}

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

        task Tmove(){
		loop{
                	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 );
			loop(60){yield}
		}
        }



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

