let CSD = GetCurrentScriptDirectory;
let MD = GetModuleDirectory;

let FAIRY_SMALL_A1 = 1.1;
let FAIRY_SMALL_A2 = 1.2;
let FAIRY_SMALL_A3 = 1.3;

let FAIRY_MEDIUM_A1 = 2.1;
let FAIRY_MEDIUM_A2 = 2.2;
let FAIRY_MEDIUM_A3 = 2.3;
let FAIRY_MEDIUM_A4 = 2.4;
let FAIRY_MEDIUM_A5 = 2.5;

let FAIRY_LARGE_A1 = 3.1;
let FAIRY_LARGE_A2 = 3.2;
let FAIRY_LARGE_B1 = 3.3;

let objEnemy;

#include "../tricky_system/Event_Const.dnh"
#include "../lib/includes/EnemyFunctions.dnh"
#include "../lib/includes/EffectFunctions.dnh"
#include "../lib/includes/Function_Audio.dnh"
#include "../lib/animation/AnimLib.h"
#include "../lib/UNL_Shot/lib_ShotConstants.dnh"
#include "./../lib/includes/ItemFunctions.dnh"

@MainLoop {
	yield;
}

@Event {
	alternative(GetEventType)
	case(EV_SPAWN_ENEMY) {
		let eventParam = GetEventArgument(0);
		let type = eventParam[0];
		let enemyParam = eventParam[1..length(eventParam)];
		
		alternative(type)
		case(FAIRY_SMALL_A1) { CreateFairy_SmallA1(enemyParam); }
		case(FAIRY_SMALL_A2) { CreateFairy_SmallA2(enemyParam); }
		case(FAIRY_SMALL_A3) { CreateFairy_SmallA3(enemyParam); }
		case(FAIRY_MEDIUM_A1) { CreateFairy_MediumA1(enemyParam); }
		case(FAIRY_MEDIUM_A2) { CreateFairy_MediumA2(enemyParam); }
		case(FAIRY_MEDIUM_A3) { CreateFairy_MediumA3(enemyParam); }
		case(FAIRY_MEDIUM_A4) { CreateFairy_MediumA4(enemyParam); }	
		case(FAIRY_MEDIUM_A5) { CreateFairy_MediumA5(enemyParam); }	
	}
}

task CreateFairy_SmallA1(enemyParam) {
	let objEnemy = ObjEnemy_Create(OBJ_ENEMY);
	let x = enemyParam[0];
	let y = enemyParam[1];
	let dir = enemyParam[2];
	
	ObjEnemy_SetLife(objEnemy, 40);
	ObjEnemy_SetDamageRate(objEnemy,100,100);
	Invuln(objEnemy, 15, 100, 100);
	ObjEnemy_Regist(objEnemy);
	ObjMove_SetPosition(objEnemy,x,y);
	
	let GetX = 0;
	let GetY = 0;
	let GetLife = 0;
	let OnScreen = false;
	
	let anglemodifier = 5;
	if(x>GetCenterX){ anglemodifier = -5; }
	
	let angle = 0;
	let moveangle = 90;
	let waitTimeBeforeFiring = randInt(10, 20) + 20;
	
	let itemx = 0;
	let itemy = 0;
	let speedx = 0;
	
	let freq = 35;
	
	let count = 0;
	let shotgraphic = [PELLET[RED], PELLET[BLUE], PELLET[GREEN]][enemyParam[3]];
	
	AnimateEnemyA1(objEnemy, enemyParam[3]);
	EnemyCollision(objEnemy,12,4);
	Const;
	Movement;
	Fire;
	End;
	
	task Const {
		while(!Obj_IsDeleted(objEnemy)) {
			GetX = ObjMove_GetX(objEnemy);
			GetY = ObjMove_GetY(objEnemy);
			GetLife = ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			OnScreen = (GetX>-20 && GetX<GetStgFrameWidth+20 && GetY>-20 && GetY<GetStgFrameHeight+20);
			yield;
		}
	}
	task Movement {
		moveangle = 90;
		ObjMove_SetSpeed(objEnemy, 2);
		ObjMove_SetAngle(objEnemy, moveangle);
		wait(20);
		while(!Obj_IsDeleted(objEnemy)){
			if(x>=GetCenterX){
				if(moveangle<210){ moveangle+=0.75; } if(moveangle>225){ moveangle = 225; }
			}
			else{
				if(moveangle>-30){ moveangle-=0.75; } if(moveangle<-45){ moveangle = -45; }
			}
			ObjMove_SetAngle(objEnemy, moveangle);
			yield;
		}
	}	
	
	task Fire{
		wait(waitTimeBeforeFiring);
		while(OnScreen && !Obj_IsDeleted(objEnemy)){
			if(count%freq==0){
				if(count%freq==0){ PlaySoundEffect("shot2", 80, GetCenterX); }
				loop(2){
					CreateDNHShotA2(GetX, GetY, rand(4-0.1, 4+0.1), GetAngleToPlayer(objEnemy)+rand(-1, 1), -0.025, 1.75+rand(-0.05, 0.05), shotgraphic, 10);
				}
			}
			count++;
			yield;
		}
	}
	
	task End {
		while(!OnScreen) { yield; }
		while(GetLife>0 && OnScreen) { yield; }
		if(OnScreen) {
			PlaySoundEffect("se_enep00", 80, GetX);
			if(enemyParam[3]==0){
				TExpan(GetX, GetY, 2, 15, 255, 0, 0, 100);
			}
			else if(enemyParam[3]==1){
				TExpan(GetX, GetY, 2, 15, 0, 0, 255, 100);
			}
			else if(enemyParam[3]==2){
				TExpan(GetX, GetY, 2, 15, 0, 255, 0, 100);
			}
			
			itemx = GetX;
			itemy = GetY;
			CreateItems02(1, ITEM_POINT_S, GetX, GetY, 0, -50, 25, 25, 10000);
		}
		Obj_Delete(objEnemy);
	}		
}

task CreateFairy_SmallA2(enemyParam) {
	let objEnemy = ObjEnemy_Create(OBJ_ENEMY);
	let x = enemyParam[0];
	let y = enemyParam[1];
	let dir = enemyParam[2];
	
	ObjEnemy_SetLife(objEnemy, 400);
	ObjEnemy_SetDamageRate(objEnemy,100,100);
	Invuln(objEnemy, 0, 100, 100);
	ObjEnemy_Regist(objEnemy);
	ObjMove_SetPosition(objEnemy,x,y);
	
	let GetX = 0;
	let GetY = 0;
	let GetLife = 0;
	let OnScreen = false;
	
	let angle = 0;
	let waitTimeBeforeFiring = 0;
	
	let itemx = 0;
	let itemy = 0;
	let speedx = 0;
	
	let freq = 10;
	if(enemyParam[3]==2){ freq = 3; }
	
	let count = 0;
	let shotgraphic = [PELLET[RED], PELLET[BLUE], PELLET[GREEN]][enemyParam[3]];
	
	AnimateEnemyA1(objEnemy, enemyParam[3]);
	EnemyCollision(objEnemy,12,4);
	Const;
	Movement;
	Fire;
	End;
	
	task Const {
		while(!Obj_IsDeleted(objEnemy)) {
			GetX = ObjMove_GetX(objEnemy);
			GetY = ObjMove_GetY(objEnemy);
			GetLife = ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			OnScreen = (GetX>-20 && GetX<GetStgFrameWidth+20 && GetY>-20 && GetY<GetStgFrameHeight+20);
			yield;
		}
	}
	task Movement {
		if(ObjMove_GetX(objEnemy)>=GetCenterX){
		ObjMove_SetDestAtWeight(objEnemy,GetX-325,GetY+60,5,6);
		}
		else{
		ObjMove_SetDestAtWeight(objEnemy,GetX+325,GetY+60,5,6);
		}
		wait(360);
		ObjMove_SetDestAtWeight(objEnemy, GetX+rand(-20, 20), GetY-200, 10, 2);
	}
	
	task Fire{
		wait(waitTimeBeforeFiring);
		while(OnScreen){
			if(ObjMove_GetSpeed(objEnemy)>1 && count%freq==0){
				if(count%freq*2==0){ PlaySoundEffect("shot3", 100, GetX); }
				ascent(i in -1..2){
					angle = rand(270-5+(i*15), 270+5+(i*15));
					speedx = 3*cos(angle);
					let obj = CreateMDNHShotA2(GetX, GetY, 3, angle, 0, 2, PELLET[BLUE], 10);
					ObjMove_AddPatternB2(obj, 0, NO_CHANGE, NO_CHANGE, -speedx/120, 0.07, 0, 2.35+(0.25*sin(count*5)));
				}
			}
			else if(count%10==0){ }
			count++;
			yield;
		}
	}
	
	task End {
		while(!OnScreen) { yield; }
		while(GetLife>0 && OnScreen) { yield; }
		if(OnScreen) {
			PlaySoundEffect("se_enep00", 80, GetX);
			if(enemyParam[3]==0){
				TExpan(GetX, GetY, 2, 15, 255, 0, 0, 100);
			}
			else if(enemyParam[3]==1){
				TExpan(GetX, GetY, 2, 15, 0, 0, 255, 100);
			}
			else if(enemyParam[3]==2){
				TExpan(GetX, GetY, 2, 15, 0, 255, 0, 100);
			}
			
			itemx = GetX;
			itemy = GetY;
			if(randInt(0, 2)==0){
				CreateItems02(1, ITEM_POINT_S, GetX, GetY, 0, -50, 25, 25, 10000);
			}
		}
		Obj_Delete(objEnemy);
	}
}

task CreateFairy_SmallA3(enemyParam) {
	let objEnemy = ObjEnemy_Create(OBJ_ENEMY);
	let x = enemyParam[0];
	let y = enemyParam[1];
	let dir = enemyParam[2];
	
	ObjEnemy_SetLife(objEnemy, 100);
	ObjEnemy_SetDamageRate(objEnemy,100,100);
	Invuln(objEnemy, 0, 100, 100);
	ObjEnemy_Regist(objEnemy);
	ObjMove_SetPosition(objEnemy,x,y);
	
	let GetX = 0;
	let GetY = 0;
	let GetLife = 0;
	let OnScreen = false;
	
	let angle = 0;
	let waitTimeBeforeFiring = 0;
	
	let itemx = 0;
	let itemy = 0;
	let speedx = 0;
	
	let freq = 10;
	if(enemyParam[3]==2){ freq = 3; }
	
	let count = 0;
	let shotgraphic = [OVAL[RED], OVAL[BLUE], OVAL[GREEN]][enemyParam[3]];
	
	AnimateEnemyA1(objEnemy, enemyParam[3]);
	EnemyCollision(objEnemy,12,4);
	Const;
	Movement;
	Fire;
	End;
	
	task Const {
		while(!Obj_IsDeleted(objEnemy)) {
			GetX = ObjMove_GetX(objEnemy);
			GetY = ObjMove_GetY(objEnemy);
			GetLife = ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			OnScreen = (GetX>-20 && GetX<GetStgFrameWidth+20 && GetY>-20 && GetY<GetStgFrameHeight+20);
			yield;
		}
	}
	task Movement {
	
		ObjMove_SetSpeed(objEnemy, 1.5);
		
		if(ObjMove_GetX(objEnemy)>=GetCenterX){ ObjMove_SetAngle(objEnemy, 180+25); }
		else{ ObjMove_SetAngle(objEnemy, 0-25); }
	}
	
	task Fire{
		wait(waitTimeBeforeFiring);
		while(OnScreen && !Obj_IsDeleted(objEnemy)){
			if(count%6!=0){ CreateMDNHShotA2(GetX, GetY, 1, GetAngleToPlayer(objEnemy), 0.1, 5, shotgraphic, 30); yield; }
			if(count%6==0){ PlaySoundEffect("shot3", 95, 384/2); wait(12); }
			count++;
			yield;
		}
	}
	
	task End {
		while(!OnScreen) { yield; }
		while(GetLife>0 && OnScreen) { yield; }
		if(OnScreen) {
			PlaySoundEffect("se_enep00", 80, GetX);
			if(enemyParam[3]==0){
				TExpan(GetX, GetY, 2, 15, 255, 0, 0, 100);
			}
			else if(enemyParam[3]==1){
				TExpan(GetX, GetY, 2, 15, 0, 0, 255, 100);
			}
			else if(enemyParam[3]==2){
				TExpan(GetX, GetY, 2, 15, 0, 255, 0, 100);
			}
			
			itemx = GetX;
			itemy = GetY;
			if(randInt(0, 2)==0){
				CreateItems02(1, ITEM_POINT_S, GetX, GetY, 0, -50, 25, 25, 10000);
			}
		}
		Obj_Delete(objEnemy);
	}
}

task CreateFairy_MediumA1(enemyParam) {

	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	let familiar = GetCurrentScriptDirectory~"sprites/familiar.png";
	ObjPrim_SetTexture(obj2, familiar);
	ObjSprite2D_SetSourceRect(obj2, 0, 0, 64, 64);
	ObjSprite2D_SetDestCenter(obj2);
	ObjRender_SetScaleXYZ(obj2, 0.75, 0.75, 1);
	
	let objEnemy = ObjEnemy_Create(OBJ_ENEMY);
	let x = enemyParam[0];
	let y = enemyParam[1];
	
	let circleangle = 0;
	
	ObjEnemy_SetLife(objEnemy, 850);
	//if(enemyParam[2]>1000){ 
	PlayEnemyHitSound(objEnemy, 1); 
	//}
	ObjEnemy_SetDamageRate(objEnemy,100,100);
	Invuln(objEnemy, 0, 100, 100);
	ObjEnemy_Regist(objEnemy);
	ObjMove_SetPosition(objEnemy,x,y);
	
	let GetX = 0;
	let GetY = 0;
	let GetLife = 0;
	let OnScreen = false;
	
	let angle = 0;
	let speed = 0;
	
	let switch = 1;
	if(ObjMove_GetX(objEnemy)>384/2){ switch=-1; }
	
	let itemx = 0;
	let itemy = 0;
	let dir = 0;
	
	let shotgraphic = [CIRCLE_S[RED], CIRCLE_S[BLUE], CIRCLE_S[GREEN]][enemyParam[3]];
	
	AnimateEnemyA1(objEnemy, enemyParam[3]);
	EnemyCollision(objEnemy,17,6);
	Const;
	Movement;
	Fire;
	End;
	
	task Const {
		while(!Obj_IsDeleted(objEnemy)) {
			ObjRender_SetAngleZ(obj2, circleangle);
			GetX = ObjMove_GetX(objEnemy);
			GetY = ObjMove_GetY(objEnemy);
			ObjRender_SetPosition(obj2, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0);
			GetLife = ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			OnScreen = (GetX>-20 && GetX<GetStgFrameWidth+20 && GetY>-40 && GetY<GetStgFrameHeight+20);
			circleangle+=2;
			yield;
		}
	}
	
	task Movement {
		ObjMove_SetDestAtWeight(objEnemy,GetX,GetY+150,5,4);
		wait(330);
		
	}
	
	task Fire {
		wait(45);
		dir = GetAngleToPlayer(objEnemy)-(45*switch)+360/6/2;
		loop(16){
		if(!Obj_IsDeleted(objEnemy)) {
			PlaySoundEffect("shot3", 90, GetX);
			loop(6){
				ascent(i in -3..4){
					CreateDNHShotA1(GetX, GetY, 2-(absolute(i)*0.2), dir+(i*4), shotgraphic, 10);
				}
				dir+=360/6;
			}
		}
		dir+=21.76*switch;
		wait(22);
		}
		switch*=-1;
		wait(60);
		if(ObjMove_GetX(objEnemy)>GetCenterX){ ObjMove_SetAngle(objEnemy, 180); }
		else if(ObjMove_GetX(objEnemy)<GetCenterX){ ObjMove_SetAngle(objEnemy, 0); }
		else{ ObjMove_SetAngle(objEnemy, 270); }
		
		ObjMove_SetAcceleration(objEnemy, 2/120);
		ObjMove_SetMaxSpeed(objEnemy, 2);
	}
	
	task End {
		while(!OnScreen) { yield; }
		while(GetLife>0 && OnScreen) { yield; }
		if(OnScreen) {
			PlaySoundEffect("se_enep00", 80, GetX);
			if(enemyParam[3]==0){
				TExpan(GetX, GetY, 2, 15, 255, 0, 0, 100);
			}
			else if(enemyParam[3]==1){
				TExpan(GetX, GetY, 2, 15, 0, 0, 255, 100);
			}
			else if(enemyParam[3]==2){
				TExpan(GetX, GetY, 2, 15, 0, 255, 0, 100);
			}
			
			CreateItems02(12, ITEM_POINT_S, GetX, GetY, 0, -50, 25, 25, 10000);
		}
		Obj_Delete(obj2);
		Obj_Delete(objEnemy);
	}
}

task CreateFairy_MediumA2(enemyParam) {

	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	let familiar = GetCurrentScriptDirectory~"sprites/familiar.png";
	ObjPrim_SetTexture(obj2, familiar);
	ObjSprite2D_SetSourceRect(obj2, 0, 0, 64, 64);
	ObjSprite2D_SetDestCenter(obj2);
	ObjRender_SetScaleXYZ(obj2, 0.75, 0.75, 1);
	
	let objEnemy = ObjEnemy_Create(OBJ_ENEMY);
	let x = enemyParam[0];
	let y = enemyParam[1];
	let dir = enemyParam[2];
	
	
	let circleangle = 0;
	
	ObjEnemy_SetLife(objEnemy, 100);
	ObjEnemy_SetDamageRate(objEnemy,100,100);
	Invuln(objEnemy, 60, 100, 100);
	ObjEnemy_Regist(objEnemy);
	ObjMove_SetPosition(objEnemy,x,y);
	
	let GetX = 0;
	let GetY = 0;
	let GetLife = 0;
	let OnScreen = false;
	
	let angle = 0;
	let speed = 0;
	
	let switch = 1;
	if(ObjMove_GetX(objEnemy)>GetStgFrameWidth/2){ switch = -1; }
	let itemx = 0;
	let itemy = 0;
	
	let shotgraphic = [CIRCLE_S[RED], CIRCLE_S[BLUE], CIRCLE_S[GREEN]][enemyParam[3]];
	
	AnimateEnemyA1(objEnemy, enemyParam[3]);
	EnemyCollision(objEnemy,17,6);
	Const;
	Movement;
	Fire;
	End;
	
	task Const {
		while(!Obj_IsDeleted(objEnemy)) {
			ObjRender_SetAngleZ(obj2, circleangle);
			GetX = ObjMove_GetX(objEnemy);
			GetY = ObjMove_GetY(objEnemy);
			ObjRender_SetPosition(obj2, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0);
			GetLife = ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			OnScreen = (GetX>-20 && GetX<GetStgFrameWidth+20 && GetY>-40 && GetY<GetStgFrameHeight+20);
			circleangle+=2;
			yield;
		}
	}
	
	task Movement {
		ObjMove_SetAngle(objEnemy, 90);
		ObjMove_SetSpeed(objEnemy, 0.75);
	}
	
	task Fire {
		while(!Obj_IsDeleted(objEnemy)){
			if(ObjMove_GetY(objEnemy)<(GetStgFrameHeight/2)-40){
				PlaySoundEffect("shot", 90, GetX);
				loop(10){
					let obj = CreateMDNHShotA2(GetX, GetY, 4, angle+rand(-2, 2), -(3/30), 2.25, CIRCLE_L[GRAY], 10);
					ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
					angle+=360/10;
				}
			}
			else{ ObjMove_SetMaxSpeed(objEnemy, 2); ObjMove_SetAcceleration(objEnemy, 0.025); }
				angle+=360/10/4*switch;
				wait(22);
			
		}
	}
	
	task End {
		while(!OnScreen) { yield; }
		while(GetLife>0 && OnScreen) { yield; }
		if(OnScreen) {
			PlaySoundEffect("se_enep00", 80, GetX);
			if(enemyParam[3]==0){
				TExpan(GetX, GetY, 2, 15, 255, 0, 0, 100);
			}
			else if(enemyParam[3]==1){
				TExpan(GetX, GetY, 2, 15, 0, 0, 255, 100);
			}
			else if(enemyParam[3]==2){
				TExpan(GetX, GetY, 2, 15, 0, 255, 0, 100);
			}
			
			CreateItems02(7, ITEM_POINT_S, GetX, GetY, 0, -50, 25, 25, 10000);
		}
		Obj_Delete(obj2);
		Obj_Delete(objEnemy);
	}
}

task CreateFairy_MediumA3(enemyParam) {

	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	let familiar = GetCurrentScriptDirectory~"sprites/familiar.png";
	ObjPrim_SetTexture(obj2, familiar);
	ObjSprite2D_SetSourceRect(obj2, 0, 0, 64, 64);
	ObjSprite2D_SetDestCenter(obj2);
	ObjRender_SetScaleXYZ(obj2, 0.75, 0.75, 1);
	
	let objEnemy = ObjEnemy_Create(OBJ_ENEMY);
	let x = enemyParam[0];
	let y = enemyParam[1];
	let dir = enemyParam[2];

	let circleangle = 0;
	
	ObjEnemy_SetLife(objEnemy, 200);
	ObjEnemy_SetDamageRate(objEnemy,100,100);
	Invuln(objEnemy, 30, 100, 100);
	ObjEnemy_Regist(objEnemy);
	
	
	let GetX = 0;
	let GetY = 0;
	let GetLife = 0;
	let OnScreen = false;
	
	let angle = 270;
	if(x>GetCenterX){ angle = 0; }
	else{ angle = 180; }
	let speed = 0;
	
	let itemx = 0;
	let itemy = 0;
	let xrad = 220;
	let angleacc = 1.2;
	let count = 0;
	let switch = -1;
	let side = 0;
	let const = 7.67;
	
	
	if(x>GetCenterX){ switch=1; side=1; }
	
	ObjMove_SetPosition(objEnemy, GetCenterX+xrad*cos(angle), 100+70*sin(angle));
	
	let shotgraphic = [CIRCLE_S[RED], CIRCLE_S[BLUE], CIRCLE_S[GREEN]][enemyParam[3]];
	
	AnimateEnemyA1(objEnemy, enemyParam[3]);
	//PlayEnemyHitSound(objEnemy, 1); 
	EnemyCollision(objEnemy,17,6);
	Const;
	Movement;
	Fire;
	End;
	
	
	
	task Const {
		while(!Obj_IsDeleted(objEnemy)) {
			ObjRender_SetAngleZ(obj2, circleangle);
			GetX = ObjMove_GetX(objEnemy);
			GetY = ObjMove_GetY(objEnemy);
			ObjRender_SetPosition(obj2, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0);
			GetLife = ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			OnScreen = (GetX>-20 && GetX<GetStgFrameWidth+20 && GetY>-40 && GetY<GetStgFrameHeight+20);
			circleangle+=2;
			yield;
		}
	}
	
	task Movement {
			if(x>GetCenterX){ ObjMove_SetDestAtWeight(objEnemy, GetX-130, GetY, 10, 5); }
			else{ ObjMove_SetDestAtWeight(objEnemy, GetX+130, GetY, 10, 5); }
	}
	
	task Fire {
		wait(45);
		//let dir = 90;
		if(!Obj_IsDeleted(objEnemy)){
			PlaySoundEffect("shot3", 100, GetX); 
			ascent(i in 0..9){
				loop(16){
					let obj2 = CreateDNHShotA2(GetX, GetY, 4+(i/1.25), dir, -0.4, 0, [PELLET[GREEN], PELLET[BLUE]][side%2], 10);
					if(side==0){
						ObjMove_AddPatternA2(obj2, 45, 3.1-(i/5), dir+(130+(i*4.58)), 0, 0, 0);
						ObjMove_AddPatternA2(obj2, 1800, NO_CHANGE, NO_CHANGE, -0.001, 0, 1);
					}
					else{
						ObjMove_AddPatternA2(obj2, 45, 3.1-(i/5), dir+(230-(i*4.58)), 0, 0, 0);
						ObjMove_AddPatternA2(obj2, 1800, NO_CHANGE, NO_CHANGE, -0.001, 0, 1);
					}	
					dir+=360/16;
				}
				dir+=const*switch;
			}
		}
		wait(60);
		if(!Obj_IsDeleted(objEnemy)){
			if(x>GetCenterX){ ObjMove_SetDestAtWeight(objEnemy, GetX+500, GetY, 20, 2); }
			else{ ObjMove_SetDestAtWeight(objEnemy, GetX-500, GetY, 20, 2); }
		}
	}
	
	task End {
		while(!OnScreen) { yield; }
		while(GetLife>0 && OnScreen) { yield; }
		if(OnScreen) {
			PlaySoundEffect("se_enep00", 80, GetX);
			if(enemyParam[3]==0){
				TExpan(GetX, GetY, 2, 15, 255, 0, 0, 100);
			}
			else if(enemyParam[3]==1){
				TExpan(GetX, GetY, 2, 15, 0, 0, 255, 100);
			}
			else if(enemyParam[3]==2){
				TExpan(GetX, GetY, 2, 15, 0, 255, 0, 100);
			}
			
			CreateItems02(5, ITEM_POINT_S, GetX, GetY, 0, -50, 25, 25, 10000);
		}
		Obj_Delete(obj2);
		Obj_Delete(objEnemy);
	}
}

task CreateFairy_MediumA4(enemyParam) {

	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	let familiar = GetCurrentScriptDirectory~"sprites/familiar.png";
	ObjPrim_SetTexture(obj2, familiar);
	ObjSprite2D_SetSourceRect(obj2, 0, 0, 64, 64);
	ObjSprite2D_SetDestCenter(obj2);
	ObjRender_SetScaleXYZ(obj2, 0.75, 0.75, 1);
	
	let objEnemy = ObjEnemy_Create(OBJ_ENEMY);
	let x = enemyParam[0];
	let y = enemyParam[1];
	
	let circleangle = 0;
	
	ObjEnemy_SetLife(objEnemy, 800);
	//if(enemyParam[2]>1000){ 
	PlayEnemyHitSound(objEnemy, 1); 
	//}
	ObjEnemy_SetDamageRate(objEnemy,100,100);
	Invuln(objEnemy, 0, 100, 100);
	ObjEnemy_Regist(objEnemy);
	ObjMove_SetPosition(objEnemy,x,y);
	
	let GetX = 0;
	let GetY = 0;
	let GetLife = 0;
	let OnScreen = false;
	
	let angle = 0;
	let speed = 0;
	
	let switch = 1;
	if(ObjMove_GetX(objEnemy)>384/2){ switch=-1; }
	
	let itemx = 0;
	let itemy = 0;
	let dir = 0;
	
	let shotgraphic = [CIRCLE_S[RED], CIRCLE_S[BLUE], CIRCLE_S[GREEN]][enemyParam[3]];
	
	AnimateEnemyA1(objEnemy, enemyParam[3]);
	EnemyCollision(objEnemy,17,6);
	Const;
	Movement;
	Fire;
	End;
	
	task Const {
		while(!Obj_IsDeleted(objEnemy)) {
			ObjRender_SetAngleZ(obj2, circleangle);
			GetX = ObjMove_GetX(objEnemy);
			GetY = ObjMove_GetY(objEnemy);
			ObjRender_SetPosition(obj2, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0);
			GetLife = ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			OnScreen = (GetX>-20 && GetX<GetStgFrameWidth+20 && GetY>-40 && GetY<GetStgFrameHeight+20);
			circleangle+=2;
			yield;
		}
	}
	
	task Movement {
		ObjMove_SetDestAtWeight(objEnemy,GetX,GetY+150,5,4);
		wait(330);
		
	}
	
	task Fire {
		wait(45);
		dir = GetAngleToPlayer(objEnemy)-(45*switch)+360/6/2;
		loop(32){
		if(!Obj_IsDeleted(objEnemy)) {
			PlaySoundEffect("shot3", 90, GetX);
			loop(6){
				ascent(i in -3..4){
					CreateDNHShotA1(GetX, GetY, 2.25-(absolute(i)*0.25), dir+(i*5.5), shotgraphic, 10);
				}
				dir+=360/6;
			}
		}
		dir+=21.76*switch;
		wait(30);
		}
		switch*=-1;
		wait(60);
		if(ObjMove_GetX(objEnemy)>GetCenterX){ ObjMove_SetAngle(objEnemy, 180); }
		else if(ObjMove_GetX(objEnemy)<GetCenterX){ ObjMove_SetAngle(objEnemy, 0); }
		else{ ObjMove_SetAngle(objEnemy, 270); }
		
		ObjMove_SetAcceleration(objEnemy, 2/120);
		ObjMove_SetMaxSpeed(objEnemy, 2);
	}
	
	task End {
		while(!OnScreen) { yield; }
		while(GetLife>0 && OnScreen) { yield; }
		if(OnScreen) {
			PlaySoundEffect("se_enep00", 80, GetX);
			if(enemyParam[3]==0){
				TExpan(GetX, GetY, 2, 15, 255, 0, 0, 100);
			}
			else if(enemyParam[3]==1){
				TExpan(GetX, GetY, 2, 15, 0, 0, 255, 100);
			}
			else if(enemyParam[3]==2){
				TExpan(GetX, GetY, 2, 15, 0, 255, 0, 100);
			}
			
			CreateItems02(12, ITEM_POINT_S, GetX, GetY, 0, -50, 25, 25, 10000);
		}
		Obj_Delete(obj2);
		Obj_Delete(objEnemy);
	}
}

task CreateFairy_MediumA5(enemyParam) {

	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	let familiar = GetCurrentScriptDirectory~"sprites/familiar.png";
	ObjPrim_SetTexture(obj2, familiar);
	ObjSprite2D_SetSourceRect(obj2, 0, 0, 64, 64);
	ObjSprite2D_SetDestCenter(obj2);
	ObjRender_SetScaleXYZ(obj2, 0.75, 0.75, 1);
	
	let objEnemy = ObjEnemy_Create(OBJ_ENEMY);
	let x = enemyParam[0];
	let y = enemyParam[1];
	
	let circleangle = 0;
	
	ObjEnemy_SetLife(objEnemy, 1500);
	//if(enemyParam[2]>1000){ 
	PlayEnemyHitSound(objEnemy, 1); 
	//}
	ObjEnemy_SetDamageRate(objEnemy,100,100);
	Invuln(objEnemy, 10000, 100, 100);
	ObjEnemy_Regist(objEnemy);
	ObjMove_SetPosition(objEnemy,x,y);
	
	let GetX = 0;
	let GetY = 0;
	let GetLife = 0;
	let OnScreen = false;
	
	let angle = 0;
	let speed = 0;
	
	let switch = 1;
	if(ObjMove_GetX(objEnemy)>384/2){ switch=-1; }
	
	let itemx = 0;
	let itemy = 0;
	let dir = 0;
	let red = 0;
	let green = 0;
	let blue = 0;
	if(enemyParam[3]==0){ red = 255; } else if(enemyParam[3]==1){ green = 255; } else if(enemyParam[3]==2){ blue = 255; }
	let shotgraphic = [CIRCLE_S[RED], CIRCLE_S[BLUE], CIRCLE_S[GREEN]][enemyParam[3]];
	
	AnimateEnemyA1(objEnemy, enemyParam[3]);
	EnemyCollision(objEnemy,17,6);
	Const;
	Movement;
	Fire;
	End;
	
	task Const {
		while(!Obj_IsDeleted(objEnemy)) {
			ObjRender_SetAngleZ(obj2, circleangle);
			GetX = ObjMove_GetX(objEnemy);
			GetY = ObjMove_GetY(objEnemy);
			ObjRender_SetPosition(obj2, ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0);
			GetLife = ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			OnScreen = (GetX>-20 && GetX<GetStgFrameWidth+20 && GetY>-40 && GetY<GetStgFrameHeight+20);
			circleangle+=2;
			yield;
		}
	}
	
	task Movement {
		ObjMove_SetDestAtWeight(objEnemy,GetX,GetY+210,5,4);
		wait(330);
		
	}
	
	task Fire {
		wait(60);
		dir = GetAngleToPlayer(objEnemy)-(45*switch)+360/6/2;
		loop(6){
			PlaySoundEffect("charge", 100, GetX);
			TCharge01(GetX, GetY, 3, 90, red, green, blue, BLEND_ADD_ARGB, 25);
			wait(20);
		}
	}
	
	task End {
		while(!OnScreen) { yield; }
		while(GetLife>0 && OnScreen) { yield; }
		if(OnScreen) {
			PlaySoundEffect("se_enep00", 80, GetX);
			if(enemyParam[3]==0){
				TExpan(GetX, GetY, 2, 15, 255, 0, 0, 100);
			}
			else if(enemyParam[3]==1){
				TExpan(GetX, GetY, 2, 15, 0, 0, 255, 100);
			}
			else if(enemyParam[3]==2){
				TExpan(GetX, GetY, 2, 15, 0, 255, 0, 100);
			}
		}
		Obj_Delete(obj2);
		Obj_Delete(objEnemy);
	}
}

task AnimateEnemyA1(objEnemy, color){
	let graphic = GetCurrentScriptDirectory~"sprites/zako_yousei.png";
	let yoffset = [0, 64, 128][color%3];
	ObjPrim_SetTexture(objEnemy, graphic); 
	ObjSprite2D_SetSourceRect(objEnemy, 0, 0, 32, 32);
	ascent(x in 0..3){ObjAnim_AddFrameA1(objEnemy, ANIM_IDLE, 32*x, yoffset, 32*x+32, yoffset+32);}
	ascent(x in 4..8){ObjAnim_AddFrameA1(objEnemy, ANIM_MOVE, 32*x, yoffset+32, 32*x+32, yoffset+64);}
	ObjAnim_AddFrameA1(objEnemy, ANIM_MOVEEND, 32, 32+yoffset, 64, 64+yoffset);
	ObjAnim_SetSpeedA1(objEnemy, ANIM_IDLE, 12);
	ObjAnim_SetSpeedA1(objEnemy, ANIM_MOVE, 6);
	ObjAnim_SetLoopPointA1(objEnemy, ANIM_MOVE, 1);
	ObjAnim_StartAnimationA1(objEnemy, 0, 0);
	ObjSprite2D_SetDestCenter(objEnemy); 
}

task EnemyCollision(objEnemy,hitboxA,hitboxB) {
	while(!Obj_IsDeleted(objEnemy)) {
		ObjEnemy_SetIntersectionCircleToShot(objEnemy,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),hitboxA);
		ObjEnemy_SetIntersectionCircleToPlayer(objEnemy,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),hitboxB);
		yield;
	}
}