script_enemy_main
{
	#include_function ".\Bullet_function.txt"
	#include_function ".\Enemy function.txt"

	@Initialize{
	SetX(GetX);
	SetY(GetY);
	SetLife(1450);
	SetScore(10000);
	SetDamageRate(100,33);
	LoadGraphic(imgzako);
	SetTexture(imgzako);
	SetGraphicRect(256,128,320,192);
	Shot(GetArgument);
	Move();
	}

	@MainLoop{
	SetCollisionA(GetX,GetY,24);
	SetCollisionB(GetX,GetY,24);
	MagicPointReduce;
	ChackBonus;
	yield;
	}

	@DrawLoop{
	DrawGraphic(GetX,GetY);
	}

	@Finalize{
	if(BeVanished() == false){
	DeleteEnemyShotToItem(ALL);
	MasicPointAddNormal(4);
	loop(6 + scorebonus){
	let x = GetX + rand(-16,16);
	let y = GetY + rand(-16,16);
	CreateItem(ITEM_SCORE,x,y);
	}
	}
	}

	task Shot(level){
	function Wait(frame){loop(frame){yield;}}

	function GateShotA(x3,x5,y,level){
	let x;
	let x1 = GetClipMinX;
	let x2 = GetClipMaxX;
	let x4;
	let gate = [70,60,50,40];
	let angle = 90;
	x4 = x3 + gate[level];
	x = x1;
	while(x < x3){
	CreateShot01(x,y,2,angle,BLUE31,10);
	x += 8;
	}
	x = x4;
	x4 = x5 + gate[level];
	while(x < x5){
	CreateShot01(x,y,2,angle,BLUE31,10);
	x += 8;
	}
	x = x4;
	while(x < x2){
	CreateShot01(x,y,2,angle,BLUE31,10);
	x += 8;
	}
	}

	function GateShotB(y,level){

	task PlayerShot(x,y,speed,firstangle,bullet,delay){
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetX(obj, x);
	Obj_SetY(obj, y);
	Obj_SetSpeed(obj, speed);	
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, bullet);
	ObjShot_SetDelay(obj, delay);
	ObjShot_SetBombResist(obj,true);
	function GetGapAngle(xA,yA,xB,yB)
	{return atan2( yB - yA, xB - xA );}


	loop(50){yield;}
	Obj_SetAngle(obj,GetGapAngle(Obj_GetX(obj),Obj_GetY(obj),GetPlayerX,GetPlayerY));
	while( !Obj_BeDeleted(obj) ){yield;}

	}

	let x;
	let x1 = GetClipMinX;
	let x2 = GetClipMaxX;
	let angle = 90;
	x = x1;
	while(x < x2){
	PlayerShot(x,y,2,angle,RED31,10);
	x += 8;
	}
	}

	Wait(40);
	loop{
	GateShotA(67,259,GetY,level);
	Wait(60 - level * 10);
	GateShotA(117,356,GetY,level);
	Wait(60 - level * 10);
	GateShotA(51,245,GetY,level);
	Wait(60 - level * 10);
	GateShotB(GetY,level);
	Wait(60 - level * 10);
	GateShotA(291,366,GetY,level);
	Wait(60 - level * 10);
	GateShotA(34,107,GetY,level);
	Wait(60 - level * 10);
	GateShotA(161,245,GetY,level);
	Wait(60 - level * 10);
	GateShotB(GetY,level);
	Wait(60 - level * 10);
	GateShotA(32,366,GetY,level);
	Wait(60 - level * 10);
	GateShotA(167,238,GetY,level);
	Wait(60 - level * 10);
	GateShotA(49,304,GetY,level);
	Wait(60 - level * 10);
	GateShotB(GetY,level);
	Wait(60 - level * 10);
	}
	}

	task Move(){
	SetMovePosition02(GetCenterX,GetCenterY-120,40);
	loop(1230){yield;}
	SetMovePosition02(0,0,270);
	loop(130){yield;}
	VanishEnemy;
	}

}