function EnemyBall(x, y, health, armor, color){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);

ObjEnemy_SetLife(obj, health+50);
ObjEnemy_SetDamageRate(obj, armor[0], armor[1]);
ObjMove_SetPosition(obj, x, y);

Render(obj, health);
return obj;

	task Render(obj, health){
	let scale = 1;
	let X = 128;
	let Y = 128;
	let count = 0;
	
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/enemy.png");
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		Obj_SetRenderPriorityI(obj, 45);
		ObjSprite2D_SetSourceRect(obj,0+(32*color-1),256,32+(32*color-1),256+32);
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
	
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjPrim_SetTexture(obj2, GetCurrentScriptDirectory ~ "img/Ingame/enemy.png");
		ObjRender_SetScaleXYZ(obj2,scale,scale,0);
		Obj_SetRenderPriorityI(obj2, 45);
		ObjSprite2D_SetSourceRect(obj2,0+(32*color),256+32,32+(32*color),256+64);
		ObjSprite2D_SetDestCenter(obj2);	
		ObjRender_SetBlendType(obj2, BLEND_ALPHA);
		
		Boundary(obj, obj2);
	
		while(ObjEnemy_GetInfo(obj, INFO_LIFE)>50){
		ObjRender_SetAngleZ(obj, count);
		ObjRender_SetAngleZ(obj2, -count);
		ObjRender_SetPosition(obj2, ObjMove_GetX(obj), ObjMove_GetY(obj), 0);
		ObjEnemy_SetIntersectionCircleToPlayer(obj, ObjMove_GetX(obj), ObjMove_GetY(obj), 9);
		ObjEnemy_SetIntersectionCircleToShot(obj, ObjMove_GetX(obj), ObjMove_GetY(obj), 16);
			if(ObjEnemy_GetInfo(obj,INFO_SHOT_HIT_COUNT)>0&&ObjEnemy_GetInfo(obj,INFO_LIFE)>health/3){
			PlaySound(GetCurrentScriptDirectory ~ "se/damage1.wav", 80, 0);}
			if(ObjEnemy_GetInfo(obj,INFO_SHOT_HIT_COUNT)>0&&ObjEnemy_GetInfo(obj,INFO_LIFE)<health/3){
			PlaySound(GetCurrentScriptDirectory ~ "se/damage2.wav", 80, 0);}
		if(ObjEnemy_GetInfo(obj, INFO_LIFE)==0){
		Obj_Delete(obj);
		Obj_Delete(obj2);
		}
		count++;
		yield;
		}
		let coloring = [0,0,0];
		if(color == 0){coloring=[170, 10, 10]}
		if(color == 1){coloring=[10, 170, 10]}
		if(color == 2){coloring=[10, 10, 170]}
		if(color == 3){coloring=[135, 10, 170]}
		if(ObjEnemy_GetInfo(obj, INFO_LIFE)<=50 && ObjEnemy_GetInfo(obj, INFO_LIFE) >= 1){
		DeathCircle(obj, color);
		loop(4){Particle(obj, rand(4,5), rand(0, 360), 0.5, rand(0,360), "Cherry", coloring, 10);}
		loop(5){
		CreateItemU1(1, ObjMove_GetX(obj)+rand(-50, 50), ObjMove_GetY(obj)+rand(-50, 50), 1000);
		}
		PlaySound(GetCurrentScriptDirectory ~ "se/explode.wav", 80, 0);
		Obj_Delete(obj);
		Obj_Delete(obj2);
		}
	}
}

function SmallFairy(x, y, health, armor, color){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);

ObjEnemy_SetLife(obj, health+50);
ObjEnemy_SetDamageRate(obj, armor[0], armor[1]);
ObjMove_SetPosition(obj, x, y);

Render(obj, health);
return obj;

	task Render(obj, health){
	let scale = 1;
	let X = 32;
	let Y = 32;
	let count = 0;
	let frame = 0;
	let mframe = 0;
	let mframe2 = 0;
	let moving = false;
	let moving2 = false;
	
	let color2 = 32*color;
	
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/enemy.png");
		ObjSprite2D_SetSourceRect(obj,0,320,X,320+Y);
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		Obj_SetRenderPriorityI(obj, 45);
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetBlendType(obj, BLEND_ALPHA);	
		Boundary(obj, obj);
	
		while(ObjEnemy_GetInfo(obj, INFO_LIFE)>50){
		ObjEnemy_SetIntersectionCircleToPlayer(obj, ObjMove_GetX(obj), ObjMove_GetY(obj), 9);
		ObjEnemy_SetIntersectionCircleToShot(obj, ObjMove_GetX(obj), ObjMove_GetY(obj), 16);
		if(ObjEnemy_GetInfo(obj,INFO_SHOT_HIT_COUNT)>0&&ObjEnemy_GetInfo(obj,INFO_LIFE)>health/3){
		PlaySound(GetCurrentScriptDirectory ~ "se/damage1.wav", 80, 0);}
		if(ObjEnemy_GetInfo(obj,INFO_SHOT_HIT_COUNT)>0&&ObjEnemy_GetInfo(obj,INFO_LIFE)<health/3){
		PlaySound(GetCurrentScriptDirectory ~ "se/damage2.wav", 80, 0);}
		if(ObjEnemy_GetInfo(obj, INFO_LIFE)==0){
		Obj_Delete(obj);
		}
		
		let dir = ObjMove_GetAngle(obj);
		let speed = ObjMove_GetSpeed(obj);
		
		if(moving == false && moving2 == false){ObjRender_SetAngleXYZ(obj,0,0,0);
		if(frame<8){ObjSprite2D_SetSourceRect(obj,0,320+color2,X,320+Y+color2);}
		if(frame>=8 && frame<16){ObjSprite2D_SetSourceRect(obj,X,320+color2,X*2,320+Y+color2);}
		if(frame>=16 && frame<24){ObjSprite2D_SetSourceRect(obj,X*2,320+color2,X*3,320+Y+color2);}
		if(frame>=24 && frame<32){ObjSprite2D_SetSourceRect(obj,X*3,320+color2,X*4,320+Y+color2);}
		mframe = 0;
		mframe2 = 0;
		}
		
		if(dir < 45 && dir > 315){moving=true;}
		if(dir > 45 && dir < 315){moving=false;}
		if(dir > 135 && dir < 225){moving2=true;}
		if(dir < 135 && dir > 225){moving2=false;}
		
		else if(moving2) {mframe++;
		ObjRender_SetAngleXYZ(obj,0,180,0);
        if(mframe <= 8) {ObjSprite2D_SetSourceRect(obj,X*4,320+color2,X*5,320+Y+color2);}
        if(mframe >= 8) {ObjSprite2D_SetSourceRect(obj,X*5,320+color2,X*6,320+Y+color2);}
		if(mframe >= 16) {ObjSprite2D_SetSourceRect(obj,X*6,320+color2,X*7,320+Y+color2);}
		if(mframe >= 24) {ObjSprite2D_SetSourceRect(obj,X*7,320+color2,X*8,320+Y+color2);}
        if(mframe <= 32) {ObjSprite2D_SetSourceRect(obj,X*8,320+color2,X*9,320+Y+color2);}
        if(mframe >= 40) {ObjSprite2D_SetSourceRect(obj,X*9,320+color2,X*10,320+Y+color2);}
		if(mframe >= 48) {ObjSprite2D_SetSourceRect(obj,X*10,320+color2,X*11,320+Y+color2);}
		if(mframe >= 52) {ObjSprite2D_SetSourceRect(obj,X*11,320+color2,X*12,320+Y+color2);}
		if(mframe >= 52) {mframe-=32;}
        }
		
		else if(moving) {mframe2++;
		ObjRender_SetAngleXYZ(obj,0,0,0);
        if(mframe2 <= 8) {ObjSprite2D_SetSourceRect(obj,X*4,320+color2,X*5,320+Y+color2);}
        if(mframe2 >= 8) {ObjSprite2D_SetSourceRect(obj,X*5,320+color2,X*6,320+Y+color2);}
		if(mframe2 >= 16) {ObjSprite2D_SetSourceRect(obj,X*6,320+color2,X*7,320+Y+color2);}
		if(mframe2 >= 24) {ObjSprite2D_SetSourceRect(obj,X*7,320+color2,X*8,320+Y+color2);}
		if(mframe2 <= 32) {ObjSprite2D_SetSourceRect(obj,X*8,320+color2,X*9,320+Y+color2);}
        if(mframe2 >= 40) {ObjSprite2D_SetSourceRect(obj,X*9,320+color2,X*10,320+Y+color2);}
		if(mframe2 >= 48) {ObjSprite2D_SetSourceRect(obj,X*10,320+color2,X*11,320+Y+color2);}
		if(mframe2 >= 52) {ObjSprite2D_SetSourceRect(obj,X*11,320+color2,X*12,320+Y+color2);}
		if(mframe2 >= 52) {mframe2-=32;}
        }	
		
		
		frame++;
		if(frame==32){frame=0;}	
		count++;
		yield;
		}
		let coloring = [0,0,0];
		if(ObjEnemy_GetInfo(obj, INFO_LIFE)<=50 && ObjEnemy_GetInfo(obj, INFO_LIFE) >= 1){
		if(color == 0){	
		coloring=[10, 10, 170];
		DeathCircle(obj, 2);
		loop(4){Particle(obj, rand(4,5), rand(0, 360), 0.5, rand(0,360), "Cherry", coloring, 10);}}
		if(color == 1){
		coloring=[170, 10, 10];
		DeathCircle(obj, 1);
		loop(4){Particle(obj, rand(4,5), rand(0, 360), 0.5, rand(0,360), "Cherry", coloring, 10);}}
		if(color == 2){
		coloring=[10, 170, 10];
		DeathCircle(obj, 4);
		loop(4){Particle(obj, rand(4,5), rand(0, 360), 0.5, rand(0,360), "Cherry", coloring, 10);}}
		if(color == 3){
		coloring=[185, 155, 0];
		DeathCircle(obj, 3);
		loop(4){Particle(obj, rand(4,5), rand(0, 360), 0.5, rand(0,360), "Cherry", coloring, 10);}}
		loop(5){
		CreateItemU1(1, ObjMove_GetX(obj)+rand(-50, 50), ObjMove_GetY(obj)+rand(-50, 50), 1000);
		}
		PlaySound(GetCurrentScriptDirectory ~ "se/explode.wav", 80, 0);
		Obj_Delete(obj);
		}
	}
}

function BigFairy(x, y, health, armor){
let obj = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(obj);

ObjEnemy_SetLife(obj, health+50);
ObjEnemy_SetDamageRate(obj, armor[0], armor[1]);
ObjMove_SetPosition(obj, x, y);

Render(obj, health);
return obj;

	task Render(obj, health){
	let scale = 1;
	let X = 64;
	let Y = 64;
	let count = 0;
	let frame = 0;
	let mframe = 0;
	let mframe2 = 0;
	let moving = false;
	let moving2 = false;
	
		ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "img/Ingame/enemy.png");
		ObjSprite2D_SetSourceRect(obj,0,320,X,320+Y);
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		Obj_SetRenderPriorityI(obj, 45);
		ObjSprite2D_SetDestCenter(obj);	
		ObjRender_SetBlendType(obj, BLEND_ALPHA);	
		Boundary(obj, obj);
	
		while(ObjEnemy_GetInfo(obj, INFO_LIFE)>50){
		ObjEnemy_SetIntersectionCircleToPlayer(obj, ObjMove_GetX(obj), ObjMove_GetY(obj), 9);
		ObjEnemy_SetIntersectionCircleToShot(obj, ObjMove_GetX(obj), ObjMove_GetY(obj), 16);
		if(ObjEnemy_GetInfo(obj,INFO_SHOT_HIT_COUNT)>0&&ObjEnemy_GetInfo(obj,INFO_LIFE)>health/3){
		PlaySound(GetCurrentScriptDirectory ~ "se/damage1.wav", 80, 0);}
		if(ObjEnemy_GetInfo(obj,INFO_SHOT_HIT_COUNT)>0&&ObjEnemy_GetInfo(obj,INFO_LIFE)<health/3){
		PlaySound(GetCurrentScriptDirectory ~ "se/damage2.wav", 80, 0);}
		if(ObjEnemy_GetInfo(obj, INFO_LIFE)==0){
		Obj_Delete(obj);
		}
		
		let dir = ObjMove_GetAngle(obj);
		let speed = ObjMove_GetSpeed(obj);
		
		if(moving == false && moving2 == false){ObjRender_SetAngleXYZ(obj,0,0,0);
		if(frame<8){ObjSprite2D_SetSourceRect(obj,0,448 ,X,448+Y );}
		if(frame>=8 && frame<16){ObjSprite2D_SetSourceRect(obj,X,448 ,X*2,448+Y );}
		if(frame>=16 && frame<24){ObjSprite2D_SetSourceRect(obj,X*2,448 ,X*3,448+Y );}
		if(frame>=24 && frame<32){ObjSprite2D_SetSourceRect(obj,X*3,448 ,X*4,448+Y );}
		mframe = 0;
		mframe2 = 0;
		}
		
		if(dir > 45 && dir < 315){moving=false;}
		if(dir < 45 && dir > 315){moving=true;}
		if(dir > 135 && dir < 225){moving2=true;}
		if(dir < 135 && dir > 225){moving2=false;}
		
		else if(moving2) {mframe++;
		ObjRender_SetAngleXYZ(obj,0,180,0);
        if(mframe <= 8) {ObjSprite2D_SetSourceRect(obj,X*4,448 ,X*5,448+Y );}
        if(mframe >= 8) {ObjSprite2D_SetSourceRect(obj,X*5,448 ,X*6,448+Y );}
		if(mframe >= 16) {ObjSprite2D_SetSourceRect(obj,X*6,448 ,X*7,448+Y );}
		if(mframe >= 24) {ObjSprite2D_SetSourceRect(obj,X*7,448 ,X*8,448+Y );}
		if(mframe <= 32) {ObjSprite2D_SetSourceRect(obj,382,320 ,382+X,320+Y );}
        if(mframe >= 40) {ObjSprite2D_SetSourceRect(obj,382+X,320 ,382+X*2,320+Y );}
		if(mframe >= 48) {ObjSprite2D_SetSourceRect(obj,382,382 ,382+X,382+Y );}
		if(mframe >= 52) {ObjSprite2D_SetSourceRect(obj,382+X,382 ,382+X*2,382+Y );}
		if(mframe >= 52) {mframe-=32;}
        }
		
		else if(moving) {mframe2++;
		ObjRender_SetAngleXYZ(obj,0,0,0);
        if(mframe2 <= 8) {ObjSprite2D_SetSourceRect(obj,X*4,448 ,X*5,448+Y );}
        if(mframe2 >= 8) {ObjSprite2D_SetSourceRect(obj,X*5,448 ,X*6,448+Y );}
		if(mframe2 >= 16) {ObjSprite2D_SetSourceRect(obj,X*6,448 ,X*7,448+Y );}
		if(mframe2 >= 24) {ObjSprite2D_SetSourceRect(obj,X*7,448 ,X*8,448+Y );}
		if(mframe2 <= 32) {ObjSprite2D_SetSourceRect(obj,382,320 ,382+X,320+Y );}
        if(mframe2 >= 40) {ObjSprite2D_SetSourceRect(obj,382+X,320 ,382+X*2,320+Y );}
		if(mframe2 >= 48) {ObjSprite2D_SetSourceRect(obj,382,382 ,382+X,382+Y );}
		if(mframe2 >= 52) {ObjSprite2D_SetSourceRect(obj,382+X,382 ,382+X*2,382+Y );}
		if(mframe2 >= 52) {mframe2-=32;}
        }	
		
		
		frame++;
		if(frame==32){frame=0;}	
		count++;
		yield;
		}
		let coloring = [0,0,0];
		if(ObjEnemy_GetInfo(obj, INFO_LIFE)<=50){
		coloring=[255, 255, 255];
		if(ObjEnemy_GetInfo(obj, INFO_LIFE) >= 1){
		DeathCircle(obj, 1);
		PlaySound(GetCurrentScriptDirectory ~ "se/explode.wav", 80, 0);
		loop(4){Particle(obj, rand(4,5), rand(0, 360), 0.5, rand(0,360), "Cherry", coloring, 10);}
		loop(10){
		CreateItemU1(1, ObjMove_GetX(obj)+rand(-50, 50), ObjMove_GetY(obj)+rand(-50, 50), 1000);
		}
		}
		Obj_Delete(obj);
		}
	}
}

task DeathCircle(tar, color){
let obj = ObjPrim_Create(OBJ_SPRITE_2D);
let scale = 0.2;
let alpha = 255;
let X = 64;
let Y = 64;

	Obj_SetRenderPriorityI(obj,22);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/deathcircle.png");
	if(color==1){ObjSprite2D_SetSourceRect(obj,0,0,X,Y);}
	if(color==2){ObjSprite2D_SetSourceRect(obj,X,0,X*2,Y);}
	if(color==3){ObjSprite2D_SetSourceRect(obj,0,Y,X,Y*2);}
	if(color==4){ObjSprite2D_SetSourceRect(obj,Y,X,X*2,Y*2);}
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj, scale, scale, scale);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj, ObjMove_GetX(tar), ObjMove_GetY(tar), 0);
	
	ascent(i in 0..64){
	ObjRender_SetScaleXYZ(obj, scale, scale, scale);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetAngleZ(obj, i*5);
	alpha-=255/18;
	scale+=0.15;
	yield;
	}
	Obj_Delete(obj);
}

task MagicRingSmall(tar, scale){
	let frame = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let Xscale = scale;
	let Yscale = scale;
	let alpha = 122;
	
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/ring.png");
	ObjSprite2D_SetSourceRect(obj,0, 0, 256, 256);
	Obj_SetRenderPriorityI(obj,25);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,ObjMove_GetX(tar),ObjMove_GetY(tar),0);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetScaleXYZ(obj, Xscale, Yscale,1);
	while(!Obj_IsDeleted(tar)){
		frame++;
		ObjRender_SetAngleXYZ(obj,0,0,frame*5);
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetPosition(obj,ObjMove_GetX(tar),ObjMove_GetY(tar),0);
		yield;
	}
	Obj_Delete(obj);
}

task Boundary(obj, obj2){
wait(60);
while(!Obj_IsDeleted(obj)){
if(ObjMove_GetY(obj)<GetStageUp-50){Obj_Delete(obj); Obj_Delete(obj2);}
if(ObjMove_GetY(obj)>GetStageDown+50){Obj_Delete(obj); Obj_Delete(obj2);}
if(ObjMove_GetX(obj)<GetStageLeft-50){Obj_Delete(obj); Obj_Delete(obj2);}
if(ObjMove_GetX(obj)>GetStageRight+50){Obj_Delete(obj); Obj_Delete(obj2);}
yield;
}
}