#include"script/default_system/Default_ShotConst.txt"
#include"script/default_system/Default_Effect.txt"
//#include"script/lib/UsefulFunctions.txt"
//#include"script/DonkeyKong/DonkeyCommon.txt"

task SpinBarrelEnemy(X,Y)
{
	let objEnemy = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_SetLife(objEnemy,50);
    ObjEnemy_SetDamageRate(objEnemy,100,100);
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy,X-1.5,Y+1.5,51);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy,X-1.5,Y+1.5,54);
	//DrawEnemy(objEnemy,BlueFairy,1);
	//EnemyResist(objEnemy,X,Y);

	Shot;
	Move;
	//Item;
	//Explode;
	//VanishClip(objEnemy,-16,-64,400,464);
	task Move
	{
		let barrelWidth = 64;
		let barrelTop = 975;//65*15
		let barrelLeft = 65 * truncate(rand(0,16));
		let barrelDir = -1^(truncate(rand(1,3)));
		let spinSpeed = rand(10,30);
		wait(60);
		while(!Obj_IsDeleted(objEnemy))
		{
			wait(spinSpeed);
			barrelLeft = (barrelLeft+(barrelDir*barrelWidth))%1040;
			ObjSprite2D_SetSourceRect(objEnemy,barrelLeft,barrelTop,barrelLeft+barrelWidth,barrelTop+barrelWidth);
			yield;
		}
	}
	task Shot
	{
		let t=floor(rand(0,30));
		wait(30);
		wait(t);
		while(!Obj_IsDeleted(objEnemy))
		{
			CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),4,GetAngleToPlayer(objEnemy),9,0);
			wait(60);
		}
	}
/*
	task Item
	{
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0 && Obj_GetValue(objEnemy, "Vanished")==false)
	{
		yield;
	}
	if(Obj_GetValue(objEnemy, "Vanished")==false)
	{
		CreateItem(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),1);
	}
	}
*/

/*
	task Explode
	{
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0 && Obj_GetValue(objEnemy, "Vanished")==false)
	{
		yield;
	}
	if(Obj_GetValue(objEnemy, "Vanished")==false)
	{
		EnemyExplosion(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),1,50,50,255);
	}
	}
}*/


/*
task CreateEnemy_1(X,Y)
{
	let objEnemy = ObjEnemy_Create(OBJ_ENEMY);
	SetLife(objEnemy,50);
        SetDamageRate(objEnemy,100,100);
	SetCollisionA(objEnemy,0,0,24);
	SetCollisionB(objEnemy,0,0,8);
	DrawEnemy(objEnemy,BlueFairy,1);
	EnemyResist(objEnemy,X,Y);

	Shot;
	Move;
	Item;
	Explode;
	VanishClip(objEnemy,-16,-64,400,464);
	task Move
	{
		let MoveSpeed=2.5;
		let MoveAngle=95;
		ObjMove_SetSpeed(objEnemy,MoveSpeed);
		ObjMove_SetAngle(objEnemy,MoveAngle);
		wait(30);
		loop(30)
		{
			ObjMove_SetSpeed(objEnemy,MoveSpeed);
			ObjMove_SetAngle(objEnemy,MoveAngle);
			MoveSpeed-=1.25/30;
			MoveAngle+=0.5;
			yield;
		}
		loop(30)
		{
			ObjMove_SetSpeed(objEnemy,MoveSpeed);
			ObjMove_SetAngle(objEnemy,MoveAngle);
			//MoveSpeed+=1.5/30;
			MoveAngle+=2.8;
			yield;
		}
		loop(30)
		{
			ObjMove_SetSpeed(objEnemy,MoveSpeed);
			ObjMove_SetAngle(objEnemy,MoveAngle);
			MoveSpeed+=1.0/30;
			MoveAngle+=0.1;
			yield;
		}
	}
	task Shot
	{
		let t=floor(rand(0,30));
		wait(30);
		wait(t);
		while(EnemyAlive(objEnemy))
		{
			CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),4,GetAngleToPlayer(objEnemy),9,0);
			wait(60);
		}
	}

	task Item
	{
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0 && Obj_GetValue(objEnemy, "Vanished")==false)
	{
		yield;
	}
	if(Obj_GetValue(objEnemy, "Vanished")==false)
	{
		CreateItem(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),1);
	}
	}

	task Explode
	{
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0 && Obj_GetValue(objEnemy, "Vanished")==false)
	{
		yield;
	}
	if(Obj_GetValue(objEnemy, "Vanished")==false)
	{
		EnemyExplosion(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),1,50,50,255);
	}
	}
}*/
