#include_script".\Item01.txt"
#include_script".\Item02.txt"
#include_script".\Item04.txt"
script_enemy_main
{//全方位回転緑鯖
	let imgEnemy=GetCurrentScriptDirectory~"img\Enemy\zako_red.png";//画像設定、赤
	#include_function".\lib\lib_common.txt"
	#include_function".\lib\lib_anime_Zako.txt"
	@Initialize
	{
		SetLife(100);
                InitializeAction();
                Tmain;
	}
	
	@MainLoop
	{
                if(GetY<cmy-32||GetY>cmY+32||GetX<cmx-32||GetX>cmX+32){VanishEnemy();}
		SetCollisionA(GetX(),GetY(),32);//当たり判定(自弾)登録
		SetCollisionB(GetX(),GetY(),12);//当たり判定(体当たり)登録
		yield;
		if(GetHitCount<=0){return;}
		if(Hitframe%4==0){
			PlaySE(Hit);
		}
		Hitframe++;
	}

        task Tmain{

		Move;
		alternative(Level)
		case(1){//hard
			Shot2(36,2,4);
		}
		case(0){//easy
			Shot2(18,2,10);
		}
		task Shot2(loops,speed,wait){
			let angle=0;
			loop{
				PlaySE(sha00);
				loop(4){
					CreateShot01(GetX,GetY,speed,angle,116,0);
					angle+=360/4;
				}
				angle+=360/loops;
				loop(wait){yield;}
			}
		}
        }

        task Move{
		let angle = GetAngle;//敵移動角度
		let speed = GetSpeed;	     //敵速度制御
		let Nspeed= GetSpeed;	     //敵移動速度
		SetAngle(90);
		SetAction(ACT_MOVE,40);
	      	loop(30){
			Nspeed-=speed/30;
			SetSpeed(Nspeed);
			yield;
		}
	      	loop(120){yield;}
		SetAngle(angle);
		SetAction(ACT_MOVE,500);
	      	loop(10){
			Nspeed+=1/10;
			SetSpeed(Nspeed);
			yield;
		}

      
        }
 
	

	@Finalize
	{
		if(BeVanished==true){return;}
		loop(4){CreateShotFromScript("I_Item",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0,1);}
		loop(2){CreateShotFromScript("I_Item",GetX+rand(-60,60),GetY+rand(-60,60),0,0,0,0);}
		loop(8){
			CreateShotFromScript("TenItem",GetX+rand(40,-40),GetY+rand(40,-40),0,0,0,0);
		}
		loop(3){
			CreateShotFromScript("P_Item",GetX+rand(40,-40),GetY+rand(40,-40),0,0,0,0);
		}

	}
	
	@DrawLoop
	{//描画
		SetTexture(Magic);
		SetGraphicRect(64,64,128,128);
		DrawGraphic(GetX(),GetY());

		DrawBoss(imgEnemy);
		DrawGraphic(GetX(),GetY());

	}
}