#include"./Functions.txt"
#include"./ZUNShot_Const.txt"

let imgObj = GetCurrentScriptDirectory ~ "Enemy/Enemy.png";
let Fire = GetCurrentScriptDirectory ~ "Enemy/Fire Elemental.png";
let Pixie = GetCurrentScriptDirectory ~ "Enemy/Pixie.png";
let Water = GetCurrentScriptDirectory ~ "Enemy/Water Elemental.png";
let Wind = GetCurrentScriptDirectory ~ "Enemy/Wind Elemental.png";
let Aura = GetCurrentScriptDirectory ~ "Enemy/enemy_aura.png";
let MidBoss = GetCurrentScriptDirectory ~ "Enemy/Heavy-Duty Pumpkins.png";

let shot = GetCurrentScriptDirectory ~ "Enemy/Shot1.wav";
let Die = GetCurrentScriptDirectory ~ "Enemy/Die.wav";
LoadSound(shot);
LoadSound(Die);

task Fairy(spawnX,spawnY,life,goX,goY,move,attack,color,time){

	let AnimFrame = 0;
	let AnimFrame2 = 0;
	let enemyX = 0;
	let enemyY = 0;
	let enemyObj = ObjEnemy_Create(OBJ_ENEMY);
	let die = rand(0,101);
	ObjEnemy_Regist(enemyObj);
	ObjMove_SetPosition(enemyObj,spawnX,spawnY);
	ObjEnemy_SetLife(enemyObj,life);
	ObjEnemy_SetDamageRate(enemyObj,100,100);
	TDrawEnemy;
	TMoveEnemy;
	TEnemyTask;
	
	if(attack==1){ Attack1; }
	if(attack==3){ Attack2; }
	
	task TEnemyTask
	{	
		while(!Obj_IsDeleted(enemyObj))
		{
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0)
			{
				PlaySound(Die);
				if(color=="BLUE"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),20,rand(0.05,0.15),50,50,255);}
				if(color=="RED"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),20,rand(0.05,0.15),255,50,50);}
				if(color=="GREEN"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),20,rand(0.05,0.15),50,255,50);}
				if(color=="YELLOW"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),20,rand(0.05,0.15),255,255,50);}
				if(attack==2){PlaySound(shot); CreateShotA1(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),2.8,GetAngleToPlayer(enemyObj),185,10);}
				if(die<=25){CreateItemA1( ITEM_POINT,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),100);}
				Obj_Delete(enemyObj);
			}
			ObjEnemy_SetIntersectionCircleToShot(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),15);
			ObjEnemy_SetIntersectionCircleToPlayer(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),12);
			yield;
		}
	}
	
	task TDrawEnemy{
		let dir;
		let vel;
		let Y;
		let Y2;
		
		if(color=="BLUE"){Y=257;Y2=287;}
		if(color=="RED"){Y=287;Y2=317;}
		if(color=="GREEN"){Y=317;Y2=350;}
		if(color=="YELLOW"){Y=350;Y2=388;}
	
		ObjPrim_SetTexture(enemyObj,imgObj);
		ObjSprite2D_SetDestCenter(enemyObj);
		ObjSprite2D_SetSourceRect(enemyObj,0,Y,30,Y2);
		
		while(!Obj_IsDeleted(enemyObj)) {
			dir = ObjMove_GetAngle(enemyObj);
			vel = ObjMove_GetSpeed(enemyObj);	
		
		if(dir == 90) {
			ObjRender_SetAngleXYZ(enemyObj,0,0,0);
			if(AnimFrame < 15) {ObjSprite2D_SetSourceRect(enemyObj,0,Y,32,Y2);}
			if(AnimFrame >= 15 && AnimFrame < 30) {ObjSprite2D_SetSourceRect(enemyObj,32,Y,63,Y2);}
			if(AnimFrame >= 30 && AnimFrame < 45) {ObjSprite2D_SetSourceRect(enemyObj,64,Y,95,Y2);}
			if(AnimFrame >= 45 && AnimFrame < 60) {ObjSprite2D_SetSourceRect(enemyObj,95,Y,126,Y2);}
			if(AnimFrame >= 60) {ObjSprite2D_SetSourceRect(enemyObj,127,Y,160,Y2);}
			AnimFrame2 = 0;
		}else if(cos(dir) > 0) {
			ObjRender_SetAngleXYZ(enemyObj,0,0,0);
			if(AnimFrame2 < 15) {ObjSprite2D_SetSourceRect(enemyObj,160,Y,191,Y2);}
			if(AnimFrame2 >= 15 && AnimFrame2 < 30) {ObjSprite2D_SetSourceRect(enemyObj,191,Y,223,Y2);}
			if(AnimFrame2 >= 30 && AnimFrame2 < 45) {ObjSprite2D_SetSourceRect(enemyObj,223,Y,255,Y2);}
			if(AnimFrame2 >= 45 && AnimFrame2 < 60) {ObjSprite2D_SetSourceRect(enemyObj,289,Y,319,Y2);}
			if(AnimFrame2 >= 60 && AnimFrame2 < 75) {ObjSprite2D_SetSourceRect(enemyObj,319,Y,351,Y2);}
			if(AnimFrame2 >= 75) {ObjSprite2D_SetSourceRect(enemyObj,352,Y,384,Y2);}
		}else if(cos(dir) < 0) {
			ObjRender_SetAngleXYZ(enemyObj,0,180,0);
			if(AnimFrame2 < 15) {ObjSprite2D_SetSourceRect(enemyObj,160,Y,191,Y2);}
			if(AnimFrame2 >= 15 && AnimFrame2 < 30) {ObjSprite2D_SetSourceRect(enemyObj,191,Y,223,Y2);}
			if(AnimFrame2 >= 30 && AnimFrame2 < 45) {ObjSprite2D_SetSourceRect(enemyObj,223,Y,255,Y2);}
			if(AnimFrame2 >= 45 && AnimFrame2 < 60) {ObjSprite2D_SetSourceRect(enemyObj,289,Y,319,Y2);}
			if(AnimFrame2 >= 60 && AnimFrame2 < 75) {ObjSprite2D_SetSourceRect(enemyObj,319,Y,351,Y2);}
			if(AnimFrame2 >= 75) {ObjSprite2D_SetSourceRect(enemyObj,352,Y,384,Y2);}
		}
		AnimFrame+=2;
		AnimFrame2++;
		ObjSprite2D_SetDestCenter(enemyObj);
		if(AnimFrame >= 75){ AnimFrame = 0;}
		if(AnimFrame2 >= 90){ AnimFrame2 = 45;}
		yield;
		}
	}
	
	task TMoveEnemy{
		if(move==1){
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj)+150,1.5);
			wait(100);
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,1.5);
		}else if(move==2){
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,1.5);
			wait(rand(100,200));
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj)+rand(-100,100),460,1.5);
		}else if(move==3){
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,1.5);
			wait(120);
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj)+rand(-100,100),460,1.5);
		}
	}
	
	task Attack1{
		wait(rand(30,60));
		loop(rand(4,6)){
			if(!Obj_IsDeleted(enemyObj)){
				PlaySound(shot);
				CreateShotA1(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),2.8,GetAngleToPlayer(enemyObj),191,10);
			}
			wait(rand(20,71));
			yield;
		}
	}
	
	task Attack2{
		let angle=0;
		wait(rand(30,60));
		loop(rand(4,6)){
			PlaySound(shot);
			while(angle<180){
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0) {break;}
				PlaySound(shot);
				CreateShotA1(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),2.8,GetAngleToPlayer(enemyObj)+75-angle,190,10);
				angle+=180/6;
			}
			angle=0;
			wait(rand(20,71));
			yield;
		}
	}
	
	wait(time);
	Obj_Delete(enemyObj);
}

task GrandFairy(spawnX,spawnY,life,goX,goY,move,attack,color,time){

	let AnimFrame = 0;
	let AnimFrame2 = 0;
	let enemyX = 0;
	let enemyY = 0;
	let A = 0;
	let enemyObj = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(enemyObj);
	ObjMove_SetPosition(enemyObj,spawnX,spawnY);
	ObjEnemy_SetLife(enemyObj,life);
	ObjEnemy_SetDamageRate(enemyObj,100,100);
	TDrawEnemy;
	TMoveEnemy;
	TEnemyTask;
	
	if(attack==1){ Attack1; }
	if(attack==3){ Attack2; }
	if(attack==4){ Attack2b; }
	
	task TEnemyTask
	{	
		while(!Obj_IsDeleted(enemyObj))
		{
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0)
			{
				PlaySound(Die);
				TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),16,rand(0.05,0.15),250,255,250);
				if(attack==2){PlaySound(shot); CreateShotA1(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),2.8,GetAngleToPlayer(enemyObj),185,10);}
				loop(10){
					CreateItemA1( ITEM_POINT,ObjMove_GetX(enemyObj)+25*sin(A), ObjMove_GetY(enemyObj)+25*cos(A),100);
					A+=360/10;
				}
				Obj_Delete(enemyObj);
			}
			ObjEnemy_SetIntersectionCircleToShot(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),15);
			ObjEnemy_SetIntersectionCircleToPlayer(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),12);
			yield;
		}
	}
	
	task TDrawEnemy{
		let dir;
		let X=0;
		let X2=48;
		
		let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
		Obj_SetRenderPriorityI(obj2,22);
		ObjPrim_SetTexture(obj2,Aura);
		ObjRender_SetScaleXYZ(obj2,1.5,1.5,0);
		if(color=="BLUE"){ObjRender_SetColor(obj2,50,50,255);}
		if(color=="RED"){ObjRender_SetColor(obj2,255,50,50);}
		if(color=="GREEN"){ObjRender_SetColor(obj2,50,255,50);}
		if(color=="YELLOW"){ObjRender_SetColor(obj2,255,230,50);}
		
		ObjPrim_SetTexture(enemyObj,imgObj);
		ObjSprite2D_SetDestCenter(enemyObj);
		
		while(!Obj_IsDeleted(enemyObj)) {
			dir = ObjMove_GetAngle(enemyObj);
		if(dir == 90) {
			ObjRender_SetAngleXYZ(enemyObj,0,0,0);
			if(AnimFrame < 15) {ObjSprite2D_SetSourceRect(enemyObj,0,390,64,442);}
			if(AnimFrame >= 15 && AnimFrame < 30) {ObjSprite2D_SetSourceRect(enemyObj,64,390,128,442);}
			if(AnimFrame >= 30 && AnimFrame < 45) {ObjSprite2D_SetSourceRect(enemyObj,128,390,192,442);}
			if(AnimFrame >= 45 && AnimFrame < 60) {ObjSprite2D_SetSourceRect(enemyObj,192,390,256,442);}
			if(AnimFrame >= 60) {ObjSprite2D_SetSourceRect(enemyObj,256,390,320,442);}
			AnimFrame2 = 0;
		}else if(cos(dir) > 0) {
			ObjRender_SetAngleXYZ(enemyObj,0,0,0);
			if(AnimFrame2 < 15) {ObjSprite2D_SetSourceRect(enemyObj,320,390,384,442);}
			if(AnimFrame2 >= 15 && AnimFrame2 < 30) {ObjSprite2D_SetSourceRect(enemyObj,384,390,448,442);}
			if(AnimFrame2 >= 30 && AnimFrame2 < 45) {ObjSprite2D_SetSourceRect(enemyObj,448,390,512,442);}
			if(AnimFrame2 >= 45 && AnimFrame2 < 60) {ObjSprite2D_SetSourceRect(enemyObj,0,445,64,495);}
			if(AnimFrame2 >= 60 && AnimFrame2 < 75) {ObjSprite2D_SetSourceRect(enemyObj,64,445,128,495);}
			if(AnimFrame2 >= 75 && AnimFrame2 < 90 ) {ObjSprite2D_SetSourceRect(enemyObj,128,445,192,495);}
			if(AnimFrame2 >= 90) {ObjSprite2D_SetSourceRect(enemyObj,192,445,256,495);}
		}else if(cos(dir) < 0) {
			ObjRender_SetAngleXYZ(enemyObj,0,180,0);
			if(AnimFrame2 < 15) {ObjSprite2D_SetSourceRect(enemyObj,320,390,384,442);}
			if(AnimFrame2 >= 15 && AnimFrame2 < 30) {ObjSprite2D_SetSourceRect(enemyObj,384,390,448,442);}
			if(AnimFrame2 >= 30 && AnimFrame2 < 45) {ObjSprite2D_SetSourceRect(enemyObj,448,390,512,442);}
			if(AnimFrame2 >= 45 && AnimFrame2 < 60) {ObjSprite2D_SetSourceRect(enemyObj,0,445,64,495);}
			if(AnimFrame2 >= 60 && AnimFrame2 < 75) {ObjSprite2D_SetSourceRect(enemyObj,64,445,128,495);}
			if(AnimFrame2 >= 75 && AnimFrame2 < 90 ) {ObjSprite2D_SetSourceRect(enemyObj,128,445,192,495);}
			if(AnimFrame2 >= 90) {ObjSprite2D_SetSourceRect(enemyObj,192,445,256,495);}
		}
			ObjSprite2D_SetSourceRect(obj2,X,0,X2,48);
		AnimFrame+=2;
		AnimFrame2++;
		X+=48;
		X2+=48;
		ObjSprite2D_SetDestCenter(enemyObj);
		ObjSprite2D_SetDestCenter(obj2);
		ObjRender_SetY(obj2,ObjMove_GetY(enemyObj)-10);
		ObjRender_SetX(obj2,ObjMove_GetX(enemyObj));
		
		if(AnimFrame >= 75){ AnimFrame = 0;}
		if(AnimFrame2 >= 105){ AnimFrame2 = 45;}
		if(X >= 380-48){ X = 0;}
		if(X2 >= 380){ X2 = 48;}
		
		yield;
		}
		
	Obj_Delete(obj2);
	}
	
	task TMoveEnemy{
		if(move==1){
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj)+160,1.5);
			wait(300);
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,1.5);
		}else if(move==2){
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,1);
		}else if(move==3){
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,1.5);
			wait(120);
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj)+rand(-100,100),460,1.5);
		}
	}
	
	task Attack1{
	let angle=0;
	let B=rand(-10,10);
		wait(60);
		loop(20){
			if(!Obj_IsDeleted(enemyObj)){
				while(angle<180){
					PlaySound(shot);
					let obj=CreateShotA2(ObjMove_GetX(enemyObj)+30*sin(angle+B-90),ObjMove_GetY(enemyObj)-30*cos(angle+B-90),3,angle+B-180,-0.03,1.8,rand(189,193),12);
					ObjMove_AddPatternB2(obj,30,NO_CHANGE,NO_CHANGE,0,0.16,5,3);
					angle+=180/6;
				}
			}
			B=rand(-30,30);
			angle=0;
			wait(12);
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0) {break;}
			yield;
		}
	}
	
	task Attack2{
		let angle=0;
		wait(60);
		let B = GetAngleToPlayer(enemyObj);
		loop{
			loop(5){
			PlaySound(shot);
			while(angle<360){
				CreateShotA2(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),0,B+angle,0.1,4,189,6);
				angle+=360/10;
			}
			B+=0.8;
			angle=0;
			wait(2);
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0) {break;}
			}
			B+=0.8*4;
			wait(4);
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0) {break;}
			yield;
		}
	}

	task Attack2b{
		let angle=0;
		wait(60);
		let B = GetAngleToPlayer(enemyObj);
		loop{
			loop(5){
			PlaySound(shot);
			while(angle<360){
				PlaySound(shot);
				CreateShotA2(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),0,B+angle,0.1,4,189,6);
				angle+=360/10;
			}
			B-=0.8;
			angle=0;
			wait(2);
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0) {break;}
			}
			B-=0.8*4;
			wait(4);
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0) {break;}
			yield;
		}
	}
	
	wait(time);
	Obj_Delete(enemyObj);
}

task YYOrb(spawnX,spawnY,life,goX,goY,move,attack,color,time){

	let AnimFrame = 0;
	let AnimFrame2 = 0;
	let enemyX = 0;
	let enemyY = 0;
	let die = rand(0,101);
	let enemyObj = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(enemyObj);
	ObjMove_SetPosition(enemyObj,spawnX,spawnY);
	ObjEnemy_SetLife(enemyObj,life);
	ObjEnemy_SetDamageRate(enemyObj,100,100);
	TDrawEnemy;
	TMoveEnemy;
	TEnemyTask;
	
	if(attack==1){ Attack1; }
	if(attack==3){ Attack2; }
	
	task TEnemyTask{	
		while(!Obj_IsDeleted(enemyObj))
		{
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0)
			{
				PlaySound(Die);
				if(color=="BLUE"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),20,rand(0.05,0.15),50,50,255);}
				if(color=="RED"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),20,rand(0.05,0.15),255,50,50);}
				if(color=="GREEN"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),20,rand(0.05,0.15),50,255,50);}
				if(color=="VIOLET"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),20,rand(0.05,0.15),255,55,250);}
				if(attack==2){PlaySound(shot); CreateShotA1(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),2.8,GetAngleToPlayer(enemyObj),185,10);}
				if(die<=33){CreateItemA1( ITEM_POINT,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),100);}
				Obj_Delete(enemyObj);
			}
			ObjEnemy_SetIntersectionCircleToShot(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),15);
			ObjEnemy_SetIntersectionCircleToPlayer(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),12);
			yield;
		}
	}
	
	task TDrawEnemy{
		let A=0;
		let X;
		let X2;
		
		if(color=="RED"){X=385;X2=415;}
		if(color=="GREEN"){X=416;X2=449;}
		if(color=="BLUE"){X=449;X2=481;}
		if(color=="VIOLET"){X=481;X2=512;}
	
		ObjPrim_SetTexture(enemyObj,imgObj);
		ObjSprite2D_SetDestCenter(enemyObj);
		ObjSprite2D_SetSourceRect(enemyObj,X,0,X2,16);
		ObjRender_SetScaleXYZ(enemyObj,1.2,1.2,0);
		
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		Obj_SetRenderPriorityI(obj,22);
		ObjPrim_SetTexture(obj,imgObj);
		ObjSprite2D_SetSourceRect(obj,X,24,X2,56);
		ObjRender_SetScaleXYZ(obj,1.5,1.5,0);

		let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
		Obj_SetRenderPriorityI(obj2,22);
		ObjPrim_SetTexture(obj2,imgObj);
		ObjSprite2D_SetSourceRect(obj2,X,24,X2,56);
		ObjRender_SetScaleXYZ(obj2,1,1,0);
		
		while(!Obj_IsDeleted(enemyObj)) {
			ObjRender_SetAngleXYZ(enemyObj,0,0,A);
			ObjRender_SetAngleXYZ(obj,0,0,A);
			ObjRender_SetAngleXYZ(obj2,0,0,-A);
			A+=12;
			ObjSprite2D_SetDestCenter(enemyObj);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetX(obj,ObjMove_GetX(enemyObj));
			ObjRender_SetY(obj,ObjMove_GetY(enemyObj));
			ObjSprite2D_SetDestCenter(obj2);
			ObjRender_SetX(obj2,ObjMove_GetX(enemyObj));
			ObjRender_SetY(obj2,ObjMove_GetY(enemyObj));
			wait(1);
		yield;
		}
		Obj_Delete(obj);
		Obj_Delete(obj2);
	}
	
	task TMoveEnemy{
		if(move==1){
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,3.5);
		}else if(move==2){
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,1.5);
		}else if(move==3){
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,1.5);
			wait(120);
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj)+rand(-100,100),460,1.5);
		}
	}
	
	task Attack1{
		wait(30);
		loop(6)
		{
			if(!Obj_IsDeleted(enemyObj))
			{
				ascent(i in 0..11)
				{
					PlaySound(shot);
					CreateShotA2(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),6,GetAngleToPlayer(enemyObj)+(i*15)-75,-0.05,2,123,10);
				}
			}
			wait(10);
			yield;
		}
	}
	
	task Attack2{
		wait(30);
		loop{
			if(!Obj_IsDeleted(enemyObj)){
				PlaySound(shot);
				CreateShotA1(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),2.8,GetAngleToPlayer(enemyObj),128,10);
			}
			wait(60);
			yield;
		}
	}
	
	wait(time);
	Obj_Delete(enemyObj);
}

task Hitodama(spawnX,spawnY,life,goX,goY,move,attack,color,time){
	let angle=0;
	let AnimFrame = 0;
	let AnimFrame2 = 0;
	let enemyX = 0;
	let enemyY = 0;
	let enemyObj = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(enemyObj);
	ObjMove_SetPosition(enemyObj,spawnX,spawnY);
	ObjEnemy_SetLife(enemyObj,life);
	ObjEnemy_SetDamageRate(enemyObj,100,100);
	TDrawEnemy;
	TMoveEnemy;
	TEnemyTask;
	
	task TEnemyTask{
		while(!Obj_IsDeleted(enemyObj))	{
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0){
				PlaySound(Die);
				if(color=="BLUE"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),20,rand(0.05,0.15),50,50,255);}
				if(color=="RED"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),20,rand(0.05,0.15),255,50,50);}
				if(color=="GREEN"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),20,rand(0.05,0.15),50,255,50);}
				if(color=="VIOLET"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),20,rand(0.05,0.15),255,255,50);}
				if(attack==1){
					PlaySound(shot);
					loop(2){CreateShotA2(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),0,rand(80,101),0.05,4,35,12);}
				}
				if(attack==2){
					let B=rand(0,360);
					PlaySound(shot);
					while(angle<360){
						CreateShotA2(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),0,angle+B,0.1,2,39,6);
						angle+=360/10;
					}
				}
				CreateItemA1( ITEM_POINT,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),100);
				Obj_Delete(enemyObj);
			}
			ObjEnemy_SetIntersectionCircleToShot(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),15);
			ObjEnemy_SetIntersectionCircleToPlayer(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),12);
			yield;
		}
	}
	
	task TDrawEnemy{
		loop{
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) > 0){fire;}
			wait(1);
			yield;
		}			
	}
	
	task fire{
		let A=1;
		let B=rand(-3,4);
		let Y;
		let Y2;
		let X;
		let X2;
		
		if(color=="RED"){Y=127;Y2=160;}
		if(color=="GREEN"){Y=160;Y2=192;}
		if(color=="BLUE"){Y=192;Y2=224;}
		if(color=="YELLOW"){Y=224;Y2=255;}
		
		let R = rand(0,81);
		
		if (R<10){X=255;X2=287}
		else if (R>=10&&R<20){X=287;X2=319}
		else if (R>=20&&R<30){X=319;X2=351}
		else if (R>=30&&R<40){X=351;X2=383}
		else if (R>=40&&R<50){X=383;X2=415}
		else if (R>=50&&R<60){X=415;X2=447}
		else if (R>=60&&R<70){X=447;X2=479}
		else if (R>=70){X=479;X2=512}
	
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		Obj_SetRenderPriorityI(obj,22);
		ObjPrim_SetTexture(obj,imgObj);
		ObjSprite2D_SetSourceRect(obj,X,Y,X2,Y2);
		ObjRender_SetY(obj,ObjMove_GetY(obj));
		let C = ObjMove_GetX(enemyObj);
		let C2 = ObjMove_GetY(enemyObj);
		A=1;
		loop(50){
			ObjRender_SetAlpha(obj,255*A*2);
			ObjRender_SetScaleXYZ(obj,1.2*A,1.2*A,0);
			A-=0.02;
			ObjSprite2D_SetDestCenter(obj);	
			ObjRender_SetY(obj,C2-50+A*50);
			ObjRender_SetX(obj,C+B*2*A);
			wait(1);
		}
		Obj_Delete(obj);
	}

	
	task TMoveEnemy{
		if(move==1){
			loop{
			ObjMove_SetDestAtSpeed(enemyObj,goX+rand(-10,11),ObjMove_GetY(enemyObj)+rand(25,56),1);
			wait(50);
			ObjMove_SetDestAtSpeed(enemyObj,spawnX+rand(-10,11),ObjMove_GetY(enemyObj)+rand(25,56),1);
			wait(50);
			}
		}else if(move==2){
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,1.5);
			wait(rand(100,200));
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj)+rand(-100,100),460,1.5);
		}else if(move==3){
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,1.5);
			wait(120);
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj)+rand(-100,100),460,1.5);
		}
	}
	
	task Attack2{
		loop{
			if(Obj_IsDeleted(enemyObj))
			{
				//PlaySound(shot1);
			}
			wait(1);
			yield;
		}
	}
	
	wait(time);
	Obj_Delete(enemyObj);
}

task Monster(spawnX,spawnY,life,goX,goY,move,attack,color,time){

	let AnimFrame = 0;
	let AnimFrame2 = 0;
	let enemyX = 0;
	let enemyY = 0;
	let enemyObj = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(enemyObj);
	ObjMove_SetPosition(enemyObj,spawnX,spawnY);
	ObjEnemy_SetLife(enemyObj,life);
	ObjEnemy_SetDamageRate(enemyObj,100,100);
	callbackboss(enemyObj);
	TDrawEnemy;
	TMoveEnemy;
	TEnemyTask;
	if(attack==1){ Attack1; }
	if(attack==2){ Attack2; }
	if(attack==3){ Attack3; }
	if(attack==4){ Attack4; }
	if(attack==5){ Attack5; }
	
	if(color=="ORANGE"){loop(100){fog(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj)+10,rand(0.2,0.3));PlaySound(GetCurrentScriptDirectory ~ "Enemy/ahaha.mp3")}}
	
	task TEnemyTask{
	let angle=0;
		while(!Obj_IsDeleted(enemyObj)){
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0){
				PlaySound(Die);
				
				if(color=="BLUE"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),15,rand(0.15,0.25),50,50,255);}
				if(color=="RED"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),15,rand(0.15,0.25),255,50,50);}
				if(color=="GREEN"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),15,rand(0.15,0.25),50,255,50);}
				if(color=="YELLOW"){TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),15,rand(0.15,0.25),255,233,0);}
				if(color=="ORANGE"){
					loop(3){
						TExplosionB(ObjMove_GetX(enemyObj)+rand(-50,50),ObjMove_GetY(enemyObj)+rand(-50,50),3,rand(0.15,0.25),255,10,255);
						wait(15);
						DeleteShotAll(TYPE_ALL,TYPE_ITEM);
					}
				}
				
				if(attack==2){
					while(angle<360){
						PlaySound(shot); CreateShotA2(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),4,angle,-0.01,2,293,10);
						angle+=360/18;
					}
				}
				let A=0;
				let B=0;
				let C=0;
					if(color=="BLUE"){
					loop(30){
						CreateItemA1( ITEM_POINT, ObjMove_GetX(enemyObj)+50*sin(A), ObjMove_GetY(enemyObj)+50*cos(A),100);
						A+=360/30;
						}
					}
					if(color=="GREEN"){
						A=rand(0,360);
						C=25;
					loop(30){
						CreateItemA1( ITEM_POINT, ObjMove_GetX(enemyObj)+C*sin(A), ObjMove_GetY(enemyObj)+C*cos(A),100);
						A+=15;
						C+=2;
						}
					}
					if(color=="RED"){
						A=-90;
						loop(15){
						CreateItemA1( ITEM_POINT, ObjMove_GetX(enemyObj)+25*sin(A), ObjMove_GetY(enemyObj)+25*cos(A)+10,100);
						A+=360/30;
						}
						A=0;
						loop(15){
						CreateItemA1( ITEM_POINT, ObjMove_GetX(enemyObj)+25*sin(A), ObjMove_GetY(enemyObj)+25*cos(A)-25,100);
						A+=360/15;
						}
					}
					if(color=="YELLOW"){
						A=180;
						B=0;
						C=55;
					loop(30){
						CreateItemA1( ITEM_POINT, ObjMove_GetX(enemyObj)+C*sin(A), ObjMove_GetY(enemyObj)+C*cos(A),100);
						A+=360/30;
						B+=8;
						C+=10*cos(B*8);
						}
					}
					if(color=="ORANGE"){
						A=0;
						loop(10){
							CreateItemA1( ITEM_POINT,ObjMove_GetX(enemyObj)+25*sin(A)+50, ObjMove_GetY(enemyObj)+25*cos(A),100);
							A+=360/10;
						}
						A=0;
						loop(10){
							CreateItemA1( ITEM_POINT,ObjMove_GetX(enemyObj)+25*sin(A)-50, ObjMove_GetY(enemyObj)+25*cos(A),100);
							A+=360/10;
						}
						A=-85;
						loop(15){
						CreateItemA1( ITEM_POINT, ObjMove_GetX(enemyObj)+60*sin(A), ObjMove_GetY(enemyObj)+50*cos(A)+40,100);
						A+=360/30;
						}
					}
				Obj_Delete(enemyObj);
			}
			ObjEnemy_SetIntersectionCircleToShot(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),15);
			ObjEnemy_SetIntersectionCircleToPlayer(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),12);
			yield;
		}
	}
	
	task TDrawEnemy{
		let Z=0;
		let X=0;
		let dir;
		
		if(color=="BLUE"){ObjPrim_SetTexture(enemyObj,Water);}
		if(color=="RED"){ObjPrim_SetTexture(enemyObj,Fire);}
		if(color=="GREEN"){ObjPrim_SetTexture(enemyObj,Wind);}
		if(color=="YELLOW"){ObjPrim_SetTexture(enemyObj,Pixie);}
		if(color=="ORANGE"){ObjPrim_SetTexture(enemyObj,MidBoss);}
	
		ObjSprite2D_SetDestCenter(enemyObj);
		ObjSprite2D_SetSourceRect(enemyObj,0,0,600,589);
		
		while(!Obj_IsDeleted(enemyObj)) {
			dir = ObjMove_GetAngle(enemyObj);
		
			if(cos(dir) <= 0) {
				loop(90){
					ObjRender_SetScaleXYZ(enemyObj,0.15+0.01*sin(Z),0.15-0.01*sin(Z),0);
					if(color=="ORANGE"){ObjRender_SetScaleXYZ(enemyObj,0.3+0.01*sin(Z),0.3-0.01*sin(Z),0);}
					Z+=3;
					ObjRender_SetAngleXYZ(enemyObj,0,X,0);
					if(X>0){X-=0.2;}
				}
			}else if(cos(dir) > 0) {
				loop(90){
					ObjRender_SetScaleXYZ(enemyObj,0.15+0.01*sin(Z),0.15-0.01*sin(Z),0);
					if(color=="ORANGE"){ObjRender_SetScaleXYZ(enemyObj,0.3+0.01*sin(Z),0.3-0.01*sin(Z),0);}
					Z+=3;
					ObjRender_SetAngleXYZ(enemyObj,0,X,0);
					if(X<180){X+=0.2;}
				}
			}
			ObjSprite2D_SetDestCenter(enemyObj);
			wait(3);
			yield;
		}
	}
	
	task TMoveEnemy{
		if(move==1){
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj)-1,ObjMove_GetY(enemyObj)+150,1.5);
			wait(200);
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,3);
		}else if(move==2){
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj)-1,ObjMove_GetY(enemyObj)+150,1.5);
			wait(400);
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,3);
		}else if(move==3){
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj)-1,ObjMove_GetY(enemyObj)+150,1.5);
			wait(600);
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,3);
		}else if(move==4){
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj)-1,ObjMove_GetY(enemyObj)+150,1.5);
			wait(600);
			loop(5){
				wait(300);
			}
			wait(600);
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,3);
		}
	}
	
	task Attack1{
	let angle=0;
		wait(60);
		loop(10){
			if(!Obj_IsDeleted(enemyObj)){
				while(angle<360){
					PlaySound(shot);
					CreateShotA2(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),5,angle+GetAngleToPlayer(enemyObj),-0.03,2.8,91,10);
					angle+=360/6;
				}
			}
			angle=0;
			wait(10);
			yield;
		}
	}
	task Attack2{
	let angle=0;
	let B=rand(-10,10);
		wait(60);
		loop(40){
			if(!Obj_IsDeleted(enemyObj)){
				while(angle<180){
					PlaySound(shot);
					let obj=CreateShotA2(ObjMove_GetX(enemyObj)+30*sin(angle+B-90),ObjMove_GetY(enemyObj)-30*cos(angle+B-90),4,angle+B-180,-0.03,2.8,288,10);
					ObjMove_AddPatternB2(obj,30,NO_CHANGE,NO_CHANGE,0,0.16,5,4);
					angle+=180/10;
				}
			}
			B=rand(-30,30);
			angle=0;
			wait(3);
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0) {break;}
			yield;
		}
	}
	task Attack3{
		let angle=0;
		let B=0;
		wait(100);
		loop(3){
			loop(40){
				if(!Obj_IsDeleted(enemyObj)){
					while(angle<360){
						PlaySound(shot);
						let obj=CreateShotA2(ObjMove_GetX(enemyObj)+30*sin(angle+B-90),ObjMove_GetY(enemyObj)-30*cos(angle+B-90),4,angle+B-180,-0.03,2.8,128,12);
						ObjMove_AddPatternA2(obj,12,NO_CHANGE,NO_CHANGE,0.1,-5,5);
						ObjMove_AddPatternA2(obj,30,NO_CHANGE,NO_CHANGE,0.1,2.5,5);
						ObjMove_AddPatternA2(obj,60,NO_CHANGE,NO_CHANGE,0.1,0,5);
						angle+=360/10;
					}
				}
			B+=18.6;
			angle=0;
			wait(1);
			}
			wait(60);
			loop(40){
				if(!Obj_IsDeleted(enemyObj)){
					while(angle<360){
						PlaySound(shot);
						let obj=CreateShotA2(ObjMove_GetX(enemyObj)+30*sin(angle+B-90),ObjMove_GetY(enemyObj)-30*cos(angle+B-90),4,angle+B-180,-0.03,2.8,128,12);
						ObjMove_AddPatternA2(obj,12,NO_CHANGE,NO_CHANGE,0.1,5,5);
						ObjMove_AddPatternA2(obj,30,NO_CHANGE,NO_CHANGE,0.1,-2.5,5);
						ObjMove_AddPatternA2(obj,60,NO_CHANGE,NO_CHANGE,0.1,0,5);
						angle+=360/10;
					}
				}
			B-=18.6;
			angle=0;
			wait(1);
			}
			wait(60);
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0) {break;}
			yield;
		}
	}
	task Attack4{
		let angle=0;
		let B=0;
		wait(60);
		loop(10){
			if(!Obj_IsDeleted(enemyObj)){
				while(angle<360){
					PlaySound(shot);
					let obj =CreateShotA2(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),5,angle+B,-0.03,2.8,220,10);
					angle+=360/20;
					ReflectSide(obj);
				}
			}
			B=rand(0,360);
			angle=0;
			wait(10);
			yield;
		}
	}
	task Attack5{
		let angle=0;
		let B=0;
		let A=0;
		let dir;
		wait(60);
		loop{
			dir = ObjMove_GetAngle(enemyObj);
			loop(50){
				if(!Obj_IsDeleted(enemyObj)){
					while(angle<360){
						PlaySound(shot);
						CreateShotA2(ObjMove_GetX(enemyObj)+35*sin(B),ObjMove_GetY(enemyObj)-30*cos(B),4,angle+B,-0.05,2,37,12);
						if(cos(dir) <= 0) {CreateShotA2(ObjMove_GetX(enemyObj)+20+35*sin(B*2),ObjMove_GetY(enemyObj)-30-30*cos(B*2),4,angle-B,-0.05,2,47,12);}
						else {CreateShotA2(ObjMove_GetX(enemyObj)-20+35*sin(B*2),ObjMove_GetY(enemyObj)-30-30*cos(B*2),4,angle-B,-0.05,2,47,12);}
						angle+=360/4;
					}
				}
				B+=8;
				angle=0;
				wait(1);
			}
			ObjMove_SetDestAtSpeed(enemyObj,rand(100,280),rand(90,150),1);
			wait(70);
			A=0;
			dir = ObjMove_GetAngle(enemyObj);
			loop(10){
				if(!Obj_IsDeleted(enemyObj)){
					while(angle<360){
						PlaySound(shot);
						CreateShotA2(ObjMove_GetX(enemyObj)+35*sin(angle),ObjMove_GetY(enemyObj)-30*cos(angle),1+A,angle+90,-0.05,1.5+A/2,97,12);
						if(cos(dir) <= 0) {CreateShotA2(ObjMove_GetX(enemyObj)+20+35*sin(angle),ObjMove_GetY(enemyObj)-30-30*cos(angle),1+A,angle-90,-0.05,1.5+A/2,105,12);}
									 else {CreateShotA2(ObjMove_GetX(enemyObj)-20+35*sin(angle),ObjMove_GetY(enemyObj)-30-30*cos(angle),1+A,angle-90,-0.05,1.5+A/2,105,12);}
						angle+=360/15;
					}
					A+=0.5;
					angle=0;
				}
			}
				ObjMove_SetDestAtSpeed(enemyObj,rand(100,280),rand(90,150),1);
			wait(60);
			yield;
		}
	}
	
	task ReflectSide(obj){
	while(ObjMove_GetX(obj)>0&&ObjMove_GetX(obj)<GetStgFrameWidth&&ObjMove_GetY(obj)>0&&ObjMove_GetY(obj)<GetStgFrameHeight){yield;}
		if(ObjMove_GetX(obj)<=0){
			if(!Obj_IsDeleted(obj)){CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),1.5,180-ObjMove_GetAngle(obj),0.01,2,222,12);}
		}else if(ObjMove_GetX(obj)>=GetStgFrameWidth){
			if(!Obj_IsDeleted(obj)){CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),1.5,180-ObjMove_GetAngle(obj),0.01,2,222,12);}
		} else if(ObjMove_GetY(obj)<=0){
			if(!Obj_IsDeleted(obj)){CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),1.5,-ObjMove_GetAngle(obj),0.01,2,222,12);}
		}
	}
	
	wait(time);

	if(color=="ORANGE"){
		if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) > 0){
			loop(100){fog(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj)+10,rand(-0.3,0.3));}
		}
	}
	
	Obj_Delete(enemyObj);
}

task Spawn(spawnX,spawnY,life,goX,goY,move,attack,color,time){
	
	let enemyX = 0;
	let enemyY = 0;
	let enemyObj = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(enemyObj);
	ObjMove_SetPosition(enemyObj,spawnX,spawnY);
	ObjEnemy_SetLife(enemyObj,life);
	ObjEnemy_SetDamageRate(enemyObj,100,100);
	TDrawEnemy;
	TMoveEnemy;
	TEnemyTask;
	
	if(attack==1){ Attack1; }
	if(attack==2){ Attack2; }
	if(attack==3){ Attack3; }
	if(attack==4){ Attack4; }
	
	task TEnemyTask
	{	
		while(!Obj_IsDeleted(enemyObj))
		{
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0)
			{
				PlaySound(Die);
				TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),16,rand(0.05,0.15),250,255,250);
				Obj_Delete(enemyObj);
			}
			yield;
		}
	}
	
	task TDrawEnemy{
		let A=0;
	
		ObjPrim_SetTexture(enemyObj,imgObj);
		ObjSprite2D_SetDestCenter(enemyObj);
		ObjSprite2D_SetSourceRect(enemyObj,385,260,510,385);
		ObjSprite2D_SetDestCenter(enemyObj);
		ObjRender_SetScaleXYZ(enemyObj,0.5,0.5,0);
		
		while(!Obj_IsDeleted(enemyObj)) {
			ObjRender_SetAlpha(enemyObj,A);
			ObjRender_SetScaleXYZ(enemyObj,0+A/500,0+A/500,0);
			A+=10;
			wait(1);
			yield;
		}
	}
	
	task TMoveEnemy{
		if(move==1){
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj)+150,1.5);
			wait(100);
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,1.5);
		}else if(move==2){
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,1.5);
			wait(rand(100,200));
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj)+rand(-100,100),460,1.5);
		}else if(move==3){
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,1.5);
			wait(120);
			ObjMove_SetDestAtSpeed(enemyObj,ObjMove_GetX(enemyObj)+rand(-100,100),460,1.5);
		}
	}
	
	task Attack1{
		let angle=0;
		wait(60);
		while(angle<10){
		if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0) {break;}
			CreateShotA1(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),2.8,GetAngleToPlayer(enemyObj)+angle-5,190,10);
			angle+=10/10;
		}
			angle=0;
			
	ObjEnemy_SetLife(enemyObj,0);
	}
	
	task Attack2{
		let angle=0;
		wait(60);
		while(angle<45){
		if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0) {break;}
			CreateShotA1(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),2.8,GetAngleToPlayer(enemyObj)+angle-45/2,190,10);
			angle+=45/10;
		}
			angle=0;
			
	ObjEnemy_SetLife(enemyObj,0);
	}

	task Attack3{
		let angle=0;
		wait(60);
		while(angle<10){
		if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0) {break;}
			CreateShotA1(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),1.8,GetAngleToPlayer(enemyObj)+angle-5,190,10);
			angle+=10/10;
		}
			angle=0;
			
	ObjEnemy_SetLife(enemyObj,0);
	}

	task Attack4{
		let angle=0;
		wait(60);
		while(angle<360){
		if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0) {break;}
			CreateShotA2(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),6,angle,-0.1,1,190,10);
			angle+=360/25;
		}
			angle=0;
			
	ObjEnemy_SetLife(enemyObj,0);
	}
	
	wait(time);
	Obj_Delete(enemyObj);
}

task fog(x,y,size){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GetCurrentScriptDirectory ~ "/Orin.png";
	let xspd = 0;
	let yspd = 0;
	let s= rand(-10,10);
	let alpha = 300;
	let Z = 0;
	let xspeed = rand(-size*s,-0.2*size);
	let yspeed = rand(-size*2,size);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjRender_SetScaleXYZ(obj,size,size,0);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetAngleXYZ(obj,rand(0,360),rand(0,360),rand(0,360));
	ObjRender_SetColor(obj,rand(100,255),rand(100,255),rand(100,255));
	Obj_SetRenderPriorityI(obj,60);
	loop(150){
	ObjRender_SetPosition(obj,x+yspd,y-xspd*0.8,0);
	yspd += yspeed*-s;
	xspd += xspeed*s/2;
	ObjRender_SetAngleXYZ(obj,-0,-0,xspd+yspd);
	
	ObjRender_SetAlpha(obj,alpha);
	alpha-=2;
	
	ObjRender_SetScaleXYZ(obj,size-Z,size-Z,0);
	Z+=0.001;
	wait(1);
	yield;
	}
	Obj_Delete(obj);
	}

task callbackboss(obj){
	let objMarker;
	let imgMarker = CSD~"./Texture/EnemyMarker.png";
	objMarker = CreateEffectObject(ObjMove_GetX(obj)+42*(4/5),GetStgFrameHeight+32,imgMarker,"ALPHA",0,0,42,16);
	EnemyMarker(obj);
	
	task EnemyMarker(boss){
		while(!Obj_IsDeleted(boss)){
			ObjRender_SetPosition(objMarker,ObjMove_GetX(boss)+42*(4/5),GetStgFrameHeight+32*(4/5),0);
			Obj_SetRenderPriorityI(objMarker,100);
		yield;
		}
	Obj_Delete(objMarker);
	}
}
	
task Crow(spawnX,spawnY,life,goX,goY,move,attack,color,time){

	let AnimFrame = 0;
	let AnimFrame2 = 0;
	let enemyX = 0;
	let enemyY = 0;
	let enemyObj = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(enemyObj);
	ObjMove_SetPosition(enemyObj,spawnX,spawnY);
	ObjEnemy_SetLife(enemyObj,life);
	ObjEnemy_SetDamageRate(enemyObj,100,100);
	TDrawEnemy;
	TMoveEnemy;
	TEnemyTask;
	Attack1;
	
	if(attack==1){ Attack1; }
	loop(1){fog(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj)+10,rand(0.2,0.3));}
	
	task TEnemyTask{
		while(!Obj_IsDeleted(enemyObj))
		{
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0)
			{
				PlaySound(Die);
				if(attack==2){
					let angle=0;
					PlaySound(shot);
					while(angle<360){
						CreateShotA1(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),2.5,angle+GetAngleToPlayer(enemyObj),108,12);
						CreateShotA1(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),2.5,angle+GetAngleToPlayer(enemyObj)+180,108,6);
						angle+=360/5;
					}
				}
				TExplosionB(ObjMove_GetX(enemyObj)+rand(-10,10),ObjMove_GetY(enemyObj)+rand(-10,10),15,rand(0.05,0.15),50,50,50);
				
				CreateItemA1( ITEM_POINT,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),100);
				Obj_Delete(enemyObj);
			}
			ObjEnemy_SetIntersectionCircleToShot(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),10);
			ObjEnemy_SetIntersectionCircleToPlayer(enemyObj,ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),5);
			yield;
		}
	}
	
	task TDrawEnemy{
		let dir;
		let vel;
		let X;
		let X2;
		
		ObjPrim_SetTexture(enemyObj,imgObj);
		ObjSprite2D_SetDestCenter(enemyObj);
			ObjRender_SetScaleXYZ(enemyObj,1.2,1.2,0);
		
		while(!Obj_IsDeleted(enemyObj)) {
			dir = ObjMove_GetAngle(enemyObj);
			vel = ObjMove_GetSpeed(enemyObj);	
		
		if(dir == 90) {
			ObjRender_SetAngleXYZ(enemyObj,0,0,0);
			if(AnimFrame < 15) {ObjSprite2D_SetSourceRect(enemyObj,127,99,159,122);}
			if(AnimFrame >= 15 && AnimFrame < 30) {ObjSprite2D_SetSourceRect(enemyObj,159,99,192,122);}
			if(AnimFrame >= 30 && AnimFrame < 45) {ObjSprite2D_SetSourceRect(enemyObj,192,99,224,122);}
			if(AnimFrame >= 45) {ObjSprite2D_SetSourceRect(enemyObj,224,99,257,122);}
			AnimFrame2 = 0;
		}else if(cos(dir) > 0) {
			ObjRender_SetAngleXYZ(enemyObj,0,180,0);
			if(AnimFrame2 < 15) {ObjSprite2D_SetSourceRect(enemyObj,0,99,33,122);}
			if(AnimFrame2 >= 15 && AnimFrame2 < 30) {ObjSprite2D_SetSourceRect(enemyObj,33,99,64,122);}
			if(AnimFrame2 >= 30 && AnimFrame2 < 45) {ObjSprite2D_SetSourceRect(enemyObj,64,99,96,122);}
			if(AnimFrame2 >= 45) {ObjSprite2D_SetSourceRect(enemyObj,96,99,127,122);}
		}else if(cos(dir) < 0) {
			ObjRender_SetAngleXYZ(enemyObj,0,0,0);
			if(AnimFrame2 < 15) {ObjSprite2D_SetSourceRect(enemyObj,0,99,33,122);}
			if(AnimFrame2 >= 15 && AnimFrame2 < 30) {ObjSprite2D_SetSourceRect(enemyObj,33,99,64,122);}
			if(AnimFrame2 >= 30 && AnimFrame2 < 45) {ObjSprite2D_SetSourceRect(enemyObj,64,99,96,122);}
			if(AnimFrame2 >= 45) {ObjSprite2D_SetSourceRect(enemyObj,96,99,127,122);}
		}
		AnimFrame+=2;
		AnimFrame2+=2;
		ObjSprite2D_SetDestCenter(enemyObj);
		if(AnimFrame >= 69){ AnimFrame = 0;}
		if(AnimFrame2 >= 60){ AnimFrame2 = 0;}
		yield;
		}
	}
	
	task TMoveEnemy{
		if(move==1){
			ObjMove_SetDestAtSpeed(enemyObj,goX,goY,3);
		}
	}
	
	task Attack1{
		loop(rand(1,3)){
			if(!Obj_IsDeleted(enemyObj)){
				PlaySound(shot);
				CreateShotA1(ObjMove_GetX(enemyObj),ObjMove_GetY(enemyObj),2,GetAngleToPlayer(enemyObj),80,6);
			}
			wait(rand(20,61));
			if(ObjEnemy_GetInfo(enemyObj,INFO_LIFE) <= 0) {break;	}
			yield;
		}
	}
	
	wait(time);
	Obj_Delete(enemyObj);
}