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

        task Tmain{
		Move;
		loop(60){yield;}
		alternative(Level)
		case(1){//hard
			let angle=-60;
			loop(5){
				Shot1(angle,-3,3,2);
				angle+=30;
			}
		}
		case(0){//easy
			Shot1(0,-2,2,1);
		}
		task Shot1(angle,min,max,speed){
			loop(40){
				PlaySE(sha00);
				CreateShot01(GetX,GetY,speed ,GetAngleToPlayer+rand(min,max)+angle,116,0);
				speed+=0.2;
				yield;
			}
		}
        }


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

      
        }
 
	

	@Finalize
	{
		if(BeVanished==true){return;}
		loop(2){
			CreateShotFromScript("I_Item",GetX+rand(-60,60),GetY+rand(-60,60),0,0,0,1);
		}
		CreateShotFromScript("I_Item",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0,0);
		loop(10){
			CreateShotFromScript("P_Item",GetX+rand(40,-40),GetY+rand(40,-40),0,0,0,0);
		}
		loop(3){
			CreateShotFromScript("TenItem",GetX+rand(40,-40),GetY+rand(40,-40),0,0,0,1);
		}	
	}
	
	@DrawLoop
	{//描画
		SetTexture(Magic);
		SetGraphicRect(64,64,128,128);
		DrawGraphic(GetX(),GetY());
		DrawBoss(imgEnemy);
		DrawGraphic(GetX(),GetY());

	}
}