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

    	@Initialize
        {
	  SetLife(2000);
	  SetDamageRate(0,0);
	  SetCountDown;
	  CreateEnemyFromScript("Sunny",GetX,GetY,0,0,0);//前キャラ描画
          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
	{       

	}

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

        task Tmain
        {
	 	SetMovePosition02(cx+250,cy-140,0);
		yield;
		//前のスペルを収得したかどうか--------------------------------------------------------------
		if(GetCommonData("GetSpell")==true){GetSpellEffect( GetCommonData("GetSpellBounus_B") );}

		loop(120){yield;}
		let IceScore = GetCommonData("GetIce");						//得点調査
		let Points=200000+GetGraze*10+IceScore+truncate(GetScore/100)-10000*GetBombCount;
		//カード名
	 	SetDamageRate(70,30);
		SetTimer(31);
		yield;

		SetMovePosition03(cx,cy-120,10,6);//画面内移動---------------------------------------------
	 	SetAction(ACT_MOVE,60);
		loop(60){yield;}
		
	 	SetAction(ACT_SHOT_B,60);//音消しモーション-----------------------------------------------------
		loop(10){yield;}
		Explosion01(GetX-10,GetY+5,4,0.1,64);
		loop(70){yield;}
		//弾幕-------------------------------------------------------------------------------------
		alternative(Level)
		case(1){//hard
			let ways = 24;
			Shot01(ways);
		}
		case(0){//easy
			let ways = 6;
			Shot01(ways);
		}
	}

	task Shot01(ways){//全方位
		loop{
			let P_M = 1;
			let PX = 120;
			let Y = GetY + 300;
			loop(6){
				let X = GetX + PX * P_M;
				PlaySE(arrow01);
				let angle=rand_int(0,360);
				loop(ways){
					CreateShot01(X,Y,1,angle,35,10);
					angle += 360 / ways ;
				}
				PX -= 20 ;
				Y -= 40;
				P_M *= -1;
				loop(30){yield;}
			}
			SetAction(ACT_SHOT_A,60);
			let angle = GetAngleToPlayer;
			loop(3){
				loop(ways*3){
					CreateShot01(GetX,GetY,8,angle,67,30);
					angle += 360 / ways/3 ;
				}
				loop(10){yield;}
			}
			loop(30){yield;}
			TMove();
			loop(60){yield;}
		}
	}

	task TMove(){
 		if(GetX>=GetPlayerX){SetMovePositionRandom01(40,30,2,GetX-40,cy-160,GetX-41,cy-80);}
 		if(GetX<=GetPlayerX){SetMovePositionRandom01(40,30,2,GetX+40,cy-160,GetX+41,cy-80);}
		if(GetX>=cx+50){SetMovePositionRandom01(40,30,2,GetX-40,cy-160,GetX-41,cy-80);}
		if(GetX<=cx-50){SetMovePositionRandom01(40,30,2,GetX+40,cy-160,GetX+41,cy-80);}
		SetAction( ACT_MOVE, 60 );
	}

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

script_enemy Sunny{
        #include_function ".\lib\lib_anime_Starsapphire.txt"
	let imgBoss=GetCurrentScriptDirectory~"img\Boss\dot_starsapphire.png";
	let Item  	=GetCurrentScriptDirectory~"\img\effect_tiny.png";
	#include_function ".\lib\lib_EnemyMarker.txt"
	EnemyMarker;
        let cx=GetCenterX;
        let cy=GetCenterY;
    	@Initialize
        {
          InitializeAction();
          LoadGraphic(imgBoss);
          SetInvincibility(90);
          SetLife(4000);
          Tmain;

	}

	@MainLoop
	{  
                yield;
        } 
	@Finalize
	{       

	}
	@DrawLoop
	{//描画
                SetColor(255,255,255);
		SetRenderState(ALPHA);
		DrawBoss( imgBoss );
	}
        
        task Tmain
        {
                SetAction( ACT_MOVE, 60 );
		SetMovePosition03(cx-300,cy-150,10,6);//画面外移動
		loop(60){yield;}
		VanishEnemy;//削除

        }
        task Tmove(){
                 if(GetX>=cx+100){SetMovePositionRandom01(70,20,2,GetX-70,cy-120,GetX-71,cy-60);}
                 else if(GetX<=cx-100){SetMovePositionRandom01(70,20,2,GetX+70,cy-120,GetX+71,cy-60);}
                 else if(GetX>=GetPlayerX){SetMovePositionRandom01(70,20,2,GetX-70,cy-120,GetX-71,cy-60);}
                 else if(GetX<=GetPlayerX){SetMovePositionRandom01(70,20,2,GetX+70,cy-120,GetX+71,cy-60);}
                 SetAction( ACT_MOVE, 60 );
        }
}
