script_enemy_main{
	#include_function ".\drawenemy.txt";
 	let ThisShot = GetCurrentScriptDirectory~"ZUN's shotdata.txt";
	let CSD = GetCurrentScriptDirectory;
	let imgFam = CSD ~ "pic\enemy.png";
	let s = 0;
	let switch = 1;
	let count = 0;
	let r = 120;
	let famangle = GetArgument;
	let spin = 0;
@Initialize{
	LoadUserShotData(ThisShot);
	SetLife(15);
	LoadGraphic(imgFam);
	maintask;
}

@MainLoop{

SetCollisionA(GetX, GetY, 8);
SetCollisionB(GetX, GetY, 8);

yield;


}
	
@DrawLoop{
drawenemy(1);
}
@Finalize{
		loop(1){
		CreateItem(ITEM_SCORE,GetX()+rand(-20,20),GetY()+rand(-20,20));
		}

}

task maintask{
	movement;
	fire;
	fire2;
	yield;
	}

task fire{
	let ve = 0;
	let angle = 0;
	angle = rand_int(0,71);
	ve = rand(3.5,5);
	wait(rand_int(30,60));
	if(famangle<2){
	loop(4){
	PlaySE(CSD~"sound\shot1.wav");
	ascent(i in 0..4){
	CreateShotA(0,GetX,GetY,0);
	SetShotDataA(0,0,ve,i*90+angle,0,-0.1,1.5,3);
	FireShot(0);
	}
	wait(8);
	}
	}
	else{
	angle = rand_int(0,71);
	ve = rand(3.5,5);
	PlaySE(CSD~"sound\shot1.wav");
	ascent(i in 0..4){
	CreateShotA(0,GetX,GetY,0);
	SetShotDataA(0,0,ve,i*90+angle,0,-0.1,1.5,3);
	FireShot(0);
	}
	}
	}

task fire2{
	wait(rand_int(0,19));
	if(famangle<2){
	ascent(i in 0..2){
	CreateShotA(0,GetX,GetY,0);
	SetShotDataA(0,0,1+i/3,90,0,0,0,51);
	FireShot(0);
	wait(20);
	}
	}
	else{
	CreateShotA(0,GetX,GetY,0);
	SetShotDataA(0,0,rand_int(1,2),90,0,0,0,67);
	FireShot(0);
	}
	}

task movement{
	alternative(famangle)
	case(0){SetMovePosition03(GetClipMinX-50, GetCenterY-rand_int(80,200), 10, 4);}
	case(1){SetMovePosition03(GetClipMaxX+50, GetCenterY-rand_int(80,200), 10, 4);}
	case(2){
	SetMovePosition03(GetX, GetCenterY-rand_int(50,100), 10, 2);
	wait(120);
	SetMovePosition03(GetX, -50, 10, 3);
	}
	wait(180);
	VanishEnemy;
	}

task tailbullet(x, y, v, dir, graphic, delay,check) 
	{
    	 let obj = Obj_Create(OBJ_SHOT);
	 let c = 0;
    	 Obj_SetPosition   (obj, x, y);
    	 Obj_SetSpeed      (obj, v);
    	 Obj_SetAngle      (obj, dir);
    	 ObjShot_SetGraphic(obj, graphic);
    	 ObjShot_SetDelay  (obj, delay);
	 ObjShot_SetBombResist(obj, true);
		 while(! Obj_BeDeleted(obj)) 
		{
		 yield;
		}
	}

	function wait(w){
		loop(w){yield;}
			}

}