#include_script".\Item02.txt"
#include_script".\Item04.txt"
script_enemy_main
{//魔方陣
	let imgEnemy=GetCurrentScriptDirectory~"img\Enemy\familiar.png";//画像設定、青
	#include_function".\lib\lib_common.txt"
	@Initialize
	{
		SetLife(70);
                Tmain;
	}
	
	@MainLoop
	{
		yield;
		if(GetHitCount<=0){return;}
		if(Hitframe%4==0){
			PlaySE(Hit);
		}
		Hitframe++;
	}

        task Tmain{
		EnemyG();
		loop(40){yield;}
		Collision();
		PlaySE(warp02);
		SetMovePosition03(GetX,GetY-40,8,4);
		loop(30){yield;}
		alternative(Level)
		case(0){//easy
			Shot1(3,3);
		}
		case(1){//hard
			Shot1(4,6);
		}
		loop(90){yield;}
		PlaySE(sha04);
		Explosion01(GetX,GetY,10,0.1,40);
		VanishEnemy;

        }

	task Collision{
		loop{
			SetCollisionA(GetX(),GetY(),32);//当たり判定(自弾)登録
			SetCollisionB(GetX(),GetY(),12);//当たり判定(体当たり)登録			
			yield;
		}
	}

        task Shot1(Nspeed,loops){
		loop(3){
			let speed = Nspeed;
			loop(loops){
				CreateShot01(GetX,GetY,speed,GetAngleToPlayer,158,0);
				speed-=0.4;	
			}
			PlaySE(arrow01);
			loop(10){yield}
		}
        }

	task EnemyG{
		EnemyG02;
		EnemyG01;

		task EnemyG01{
			let a=0;
			let obj = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetTexture(obj ,imgEnemy);
			ObjEffect_SetPrimitiveType(obj ,PRIMITIVE_TRIANGLESTRIP);
			ObjEffect_SetRenderState(obj ,ALPHA);
			ObjEffect_CreateVertex(obj ,4);
			ObjEffect_SetVertexXY(obj, 0,-24,-24);
			ObjEffect_SetVertexXY(obj, 1, 24,-24);
			ObjEffect_SetVertexXY(obj, 2,-24, 24);
			ObjEffect_SetVertexXY(obj, 3, 24, 24);
			ObjEffect_SetVertexUV(obj, 0,  1,  1);
			ObjEffect_SetVertexUV(obj, 1, 47,  1);
			ObjEffect_SetVertexUV(obj, 2,  1, 47);
			ObjEffect_SetVertexUV(obj, 3, 47, 47);
			ObjEffect_SetLayer(obj,1);
			loop(40){
				let i=0;
				a+=255/40;
				loop(4){ 
					ObjEffect_SetVertexColor(obj ,i,a,255,255,255);
					i++;
				}
				Obj_SetPosition(obj,GetX,GetY);
				yield
			}
			ObjEffect_SetLayer(obj,2);
			while( !Obj_BeDeleted(obj) ){
				Obj_SetPosition(obj,GetX,GetY);
				yield;
			}
		}
		task EnemyG02{
			let a=0;
			let obj = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetTexture(obj ,imgEnemy);
			ObjEffect_SetPrimitiveType(obj ,PRIMITIVE_TRIANGLESTRIP);
			ObjEffect_SetRenderState(obj ,ALPHA);
			ObjEffect_CreateVertex(obj ,4);
			ObjEffect_SetVertexXY(obj, 0,-24,-24);
			ObjEffect_SetVertexXY(obj, 1, 24,-24);
			ObjEffect_SetVertexXY(obj, 2,-24, 24);
			ObjEffect_SetVertexXY(obj, 3, 24, 24);
			ObjEffect_SetVertexUV(obj, 0,  0, 48);
			ObjEffect_SetVertexUV(obj, 1, 48, 48);
			ObjEffect_SetVertexUV(obj, 2,  0, 96);
			ObjEffect_SetVertexUV(obj, 3, 48, 96);
			ObjEffect_SetLayer(obj,1);
			loop(40){
				let i=0;
				a+=255/40;
				loop(4){ 
					ObjEffect_SetVertexColor(obj ,i,a,255,255,255);
					i++;
				}
				Obj_SetPosition(obj,GetX,GetY);
				yield
			}
			ObjEffect_SetLayer(obj,2);
			while( !Obj_BeDeleted(obj) ){
				Obj_SetPosition(obj,GetX,GetY);
				yield;
			}
		}
	
	}
 

	@Finalize
	{
		if(BeVanished==false){
			CreateShotFromScript("TenItem",GetX+rand(20,-20),GetY+rand(20,-20),0,0,0,0);
			CreateShotFromScript("TenItem",GetX+rand(20,-20),GetY+rand(20,-20),0,0,0,0);
		}
		else{
			let angle=0;
			loop(12){
				CreateShotFromScript("I_Item",GetX+40*cos(angle),GetY+40*sin(angle),0,0,0,1);
				angle+=30;
			}
		}
	}
	
	@DrawLoop
	{//描画

	}
}