#include"./../System/Miyako_Effect.txt"
#include"./../Stage/Script/LoadGraphics.txt"
#include"./../Stage/Script/LoadSounds.txt"
let damage = 0;

function w(w){loop(w){yield;}}

task LoadShot{
	let current = GetCurrentScriptDirectory();
	let path = current ~ "AllStarShot.txt";
	LoadEnemyShotData(path);}

task FairyCheck{
	let obj = SpawnEnemy_Fairy(-200,-100,"red",100);
	w(10);Obj_Delete(obj);}

task TFairyA1{
	let alpha = 0;let scale = 0;let angle = 0;
	let obj = SpawnEnemy_Fairy(192,50,"flower",600);
	loop(100){
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		scale+=1/100;alpha+=255/100;yield;}
		damage=1;
	w(30);
	if(!Obj_IsDeleted(obj)){
	let shot1 = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),3,GetAngleToPlayer(obj),823,30);
	let shot2 = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),3,GetAngleToPlayer(obj)+50,824,30);
	let shot3 = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),3,GetAngleToPlayer(obj)-50,825,30);
	TSpawn(shot1,519,332);TSpawn(shot2,523,334);TSpawn(shot3,527,336);
	reflectX(shot1);reflectX(shot2);reflectX(shot3);}
	w(30);
	SE(se_tan);

	task TSpawn(object,color,color2){let angle = 0; 
		while(!Obj_IsDeleted(object)){
			let s = CreateShotA1(ObjMove_GetX(object)+rand(-8,8),ObjMove_GetY(object)+rand(-8,8),0,0,color,15);
			manage(s,angle); w(3);angle+=15;}
			task manage(o,ang){w(90); if(!Obj_IsDeleted(o)){
				CreateShotA2(ObjMove_GetX(o),ObjMove_GetY(o),5,ang,-0.4,rand(0.6,1),color2,15);
				Obj_Delete(o);}w(15);SE(se_kira);}}
	w(90);
	ObjMove_SetDestAtWeight(obj,192,-80,5,1);}

task TFairyA2(x,y,x1,y1,x2,y2){
	let obj = SpawnEnemy_Fairy(x,y,"flower",800);
	ObjMove_SetDestAtWeight(obj,x1,y1,5,2);
	w(90);
	let angle = 0;
	let player = GetAngleToPlayer(obj);
		loop(15){
			if(Obj_IsDeleted(obj)){break;}
			CreateShotL1(ObjMove_GetX(obj),ObjMove_GetY(obj),player+10+angle);
			CreateShotL1(ObjMove_GetX(obj),ObjMove_GetY(obj),player-10-angle);
			w(4);angle+=5;}
	w(90);
	ObjMove_SetDestAtWeight(obj,x2,y2,5,2);
	
	function CreateShotL1(x,y,ang){
		if(!Obj_IsDeleted(obj)){
		let shot = CreateShotA2(x,y,5,ang,-0.2,0,780,30);
		ObjShot_SetSpellResist(shot,true);
		task manage{
			while(ObjMove_GetSpeed(shot) > 0){yield;}
				let l = CreateStraightLaserA1(ObjMove_GetX(shot),ObjMove_GetY(shot),ObjMove_GetAngle(shot),400,20,60,1021,60);
				ObjShot_SetSpellResist(l,true);
			w(60);SE(se_lazer);
			w(60);ObjShot_FadeDelete(shot);}
		manage;}}}

task TSpiritA2(x,y,ang){
	let obj = SpawnEnemy_Spirit(x,y,"blue",200);
	let count = 0;
		
	ObjMove_SetAngle(obj,ang);
	ObjMove_SetSpeed(obj,0.8);
	w(90);
	while(!Obj_IsDeleted(obj)){
	let r = rand(0,24);
	if(Obj_IsDeleted(obj)){break;}
	ascent(i in 0..15){ ascent(s in 0..2){
		let a = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),6+s,i*24+r,22,0);
		ObjMove_AddPatternA1(a,10,2,NO_CHANGE);}}
	if(count>=8){break;}
	SE(se_tan);w(30);count++;}}

task TFairyA3(x,ang){
	let obj = SpawnEnemy_Fairy(x,rand(0,50),"flower",500);
	ObjMove_SetSpeed(obj,5);
	ObjMove_SetAngle(obj,ang);
	w(30);
	if(!Obj_IsDeleted(obj)){
		ascent(i in 0..30){
			ascent(a in 1..3){
			CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),2+a,GetAngleToPlayer(obj)+i*12,333,10);}
		let sh2=CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),4,GetAngleToPlayer(obj)+i*12,523,10);
		ObjMove_AddPatternA1(sh2,10,2,GetAngleToPlayer(sh2));}
		}
	w(10);SE(se_tan);}

task TFairyA4(x,wert){damage=1;
	let obj = SpawnEnemy_Fairy(x,-50,"flower",800);
	ObjMove_SetDestAtWeight(obj,x,50,5,3);
	w(60);SE(se_tan);
	let fam = CreateFamilar(ObjMove_GetX(obj),ObjMove_GetY(obj),255,255,200);
	ObjMove_SetAngle(fam,90);
	ObjMove_SetSpeed(fam,3);
	while(!Obj_IsDeleted(fam)){
		if(CheckOutsideScreenA2(ObjMove_GetX(fam),ObjMove_GetY(fam),15)){
			Obj_Delete(fam);break;}
		let s1 = CreateShotA1(ObjMove_GetX(fam)+rand(-8,8),ObjMove_GetY(fam)+rand(-8,8),0,0,523,15);
		let s2 = CreateShotA1(ObjMove_GetX(fam)+rand(-8,8),ObjMove_GetY(fam)+rand(-8,8),0,180,523,15);
		tManage(s1);tManage(s2); w(3); SE(se_kira3);}w(60);
	ObjMove_SetDestAtWeight(obj,x+wert,50,5,3);w(30);
	
	if(!Obj_IsDeleted(obj)){SE(se_tan);
	let fam2 = CreateFamilar(ObjMove_GetX(obj),ObjMove_GetY(obj),255,255,200);
	ObjMove_SetAngle(fam2,90);
	ObjMove_SetSpeed(fam2,3);
	while(!Obj_IsDeleted(fam2)){
		if(CheckOutsideScreenA2(ObjMove_GetX(fam2),ObjMove_GetY(fam2),15)){
			Obj_Delete(fam2);break;}
		let s1 = CreateShotA1(ObjMove_GetX(fam2)+rand(-8,8),ObjMove_GetY(fam2)+rand(-8,8),0,0,523,15);
		let s2 = CreateShotA1(ObjMove_GetX(fam2)+rand(-8,8),ObjMove_GetY(fam2)+rand(-8,8),0,180,523,15);
		tManage(s1);tManage(s2); w(3); SE(se_kira);}}
	
	task tManage(object){ w(90); if(!Obj_IsDeleted(object)){
		CreateShotA2(ObjMove_GetX(object),ObjMove_GetY(object),0,ObjMove_GetAngle(object),0.2,rand(0.5,2),834,15);
		Obj_Delete(object);}w(15);SE(se_kira);}}

task TFairyA5(x){
	let count = 0; let move = 0; let angle_a = 0;let angle_c = 0;
	let obj = SpawnEnemy_Fairy(x,-50,"flower",1000);
	ObjMove_SetDestAtWeight(obj,x,100,5,3);

	ascent(i in 0..4){
	let fam = CreateFamilar(0,0,255,255,255);
		manage(fam,i*90);shot(fam);}w(120);
		
	while(!Obj_IsDeleted(obj)){count++;
	ascent(i in 0..30){
		let shot = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),0,GetAngleToPlayer(obj)+i*12,278,10);
		TSpeed(shot);}
	w(10); SE(se_tan); if(count>=20){break;}}
	
	task TSpeed(object){
		loop(28){ObjMove_SetSpeed(object,ObjMove_GetSpeed(object)+0.2);
			w(2);}}
	ObjMove_SetDestAtWeight(obj,x,-100,5,3);

	task manage(object,ang){
	while(!Obj_IsDeleted(obj)){
		ObjMove_SetPosition(object,ObjMove_GetX(obj)+120*cos(move+ang),ObjMove_GetY(obj)+120*sin(move+ang));
		ObjMove_SetAngle(object,move+ang);move+=0.5;yield;}
	Obj_Delete(object);}
		
	task shot(object){ w(90); while(!Obj_IsDeleted(obj)){
		let a = CreateShotA1(ObjMove_GetX(object),ObjMove_GetY(object),1,angle_a+140,375,10);
		let c = CreateShotA1(ObjMove_GetX(object),ObjMove_GetY(object),1,angle_c,377,10);
		angle_a = atan2(ObjMove_GetY(a)-ObjMove_GetY(obj),ObjMove_GetX(a)-ObjMove_GetX(obj));
		angle_c = atan2(ObjMove_GetY(c)-ObjMove_GetY(obj),ObjMove_GetX(c)-ObjMove_GetX(obj));
		w(4);SE(se_kira3);}}}

task TFairyA6{
	let count = 0;
	let obj = SpawnEnemy_Fairy(192,-50,"flower",1000);
	ObjMove_SetDestAtWeight(obj,192,100,5,3);
	
	w(90);
	let angle = 0;
	while(!Obj_IsDeleted(obj)){
		ascent(i in 0..12){
		let s = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),5,i*30,214,0);
		ObjMove_AddPatternA1(s,3,2,angle);}
		CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),2,-angle,37,15);
		angle+=49;count++;
		if(count>=150){break;}
	w(3);SE(se_tan);}w(45);
	ObjMove_SetAngle(obj,270);
	ObjMove_SetSpeed(obj,1);}

task TSpiritA6(x,y,x1,y1){
	let obj = SpawnEnemy_Spirit(x,y,"red",200);
	ObjMove_SetDestAtWeight(obj,x1,y1,5,3);
	w(90);
	let ang = GetAngleToPlayer(obj);
	loop(6){
		if(Obj_IsDeleted(obj)){break;}
		ascent(i in -5..6){
			let a = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),6,ang+i*12,333,15);
			ObjMove_AddPatternA1(a,10,3,NO_CHANGE);}
	w(4);}
	ObjEnemy_SetLife(obj,0);}

task TFairyA8(x1,y1,x2,y2,move,gr){let count = 0;let angle = 0;
	let obj = SpawnEnemy_Fairy(x1,y2,"yellow",500);
	ObjMove_SetDestAtWeight(obj,x2,y2,5,5);w(60);
	while(!Obj_IsDeleted(obj)){ ascent(i in 0..4){
		let shot = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),8,angle+i*90,gr,5);
		TSpeed(shot);}
		if(count>=90){break;}
	yield;angle+=move*9.15;count++;SE(se_tan3);}
	w(60);
	ObjMove_SetDestAtWeight(obj,x2,y2-150,5,5);

	task TSpeed(object){w(20);
		while(ObjMove_GetSpeed(object) > 1){yield;
		ObjMove_SetSpeed(object,ObjMove_GetSpeed(object)-0.2);}}}

function GetPointToPointAngle(x1,y1,x2,y2){
	let dir = atan2(y1-y2,x1-x2);
	return dir;}

task TFairyA10(type,gr){damage=1;
	let obj = SpawnEnemy_Fairy(192,-50,"flower",600);
	ObjMove_SetDestAtWeight(obj,192,192,5,4);
	if(type == "red"){
		ascent(i in 0..10){tSpirit(i*36,1,332,8,45,90);}}
	if(type == "green"){
		ascent(i in 0..10){tSpirit(i*36,1,336,6,40,80);}
		w(40);
		ascent(i in 0..10){tSpirit(i*36,-1,336,6,40,95);}}
	if(type == "blue"){
		ascent(i in 0..10){tSpirit(i*36,1,334,4,30,70);}w(30);
		ascent(i in 0..10){tSpirit(i*36,-1,334,4,30,95);}w(30);
		ascent(i in 0..10){tSpirit(i*36,1,334,4,30,110);}}
	w(60);
	while(!Obj_IsDeleted(obj)){
		tShot;
		loop(60){
		if(type=="red" && Obj_IsDeleted(obj)){PowerL(192,180);break;}
		if(type=="green" && Obj_IsDeleted(obj)){SPELLUP(192,180);break;}
		if(type=="blue" && Obj_IsDeleted(obj)){LIFEUP(192,180);break;}
		yield;}}
		
	task tShot{
	let a = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),5,350-rand(0,20),gr,30);
	let b = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),5,190+rand(0,20),gr,30);
	SE(se_kira);
	loop(90){
		ObjMove_SetSpeed(a,ObjMove_GetSpeed(a) - 5/90);
		ObjMove_SetSpeed(b,ObjMove_GetSpeed(b) - 5/90);
		yield;}
	loop(5){yield;}
	ObjMove_SetAngle(a,GetAngleToPlayer(a));
	ObjMove_SetAngle(b,GetAngleToPlayer(b));
	loop(90){
		ObjMove_SetSpeed(a,ObjMove_GetSpeed(a) + 4/90);
		ObjMove_SetSpeed(b,ObjMove_GetSpeed(b) + 4/90);
		yield;}}
	
	task tSpirit(ang,turn,gra,length,per,rad){ let way = 0; let r = 0;
		let spi = SpawnEnemy_Spirit(192,-50,type,300);
		move;w(90);
		while(!Obj_IsDeleted(spi)){ loop(length){ w(3);SE(se_tan);
			let x = ObjMove_GetX(spi);
			let y = ObjMove_GetY(spi);
			if(Obj_IsDeleted(spi)){break;}
			if(Obj_IsDeleted(obj)){break;}
			CreateShotA1(x,y,1.5,atan2(y-ObjMove_GetY(obj),x-ObjMove_GetX(obj)),gra,0);}
		w(per);}
		task move{
			while(!Obj_IsDeleted(obj)){
				ObjMove_SetPosition(spi,ObjMove_GetX(obj)+r*cos(way+ang),ObjMove_GetY(obj)+r*sin(way+ang));
				if(r>=rad){r=rad;}way+=1*turn; r+=2; yield;}
		ObjEnemy_SetLife(spi,0);}}}

function CreateFamilar(x,y,r,g,b){
	let fam = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(fam);
	ObjEnemy_SetLife(fam,100);
	ObjPrim_SetTexture(fam,fami);
	Obj_SetRenderPriorityI(fam,25);
	ObjSprite2D_SetSourceRect(fam,0,0,64,64);
	ObjSprite2D_SetDestCenter(fam);
	ObjRender_SetBlendType(fam,BLEND_ALPHA);
	ObjRender_SetColor(fam,r,g,b);
	ObjRender_SetPosition(fam,x,y,0);
	return fam;}
	
function CheckOutsideScreen(objectID, distance){
	return ObjRender_GetX(objectID)>GetStgFrameWidth+distance||ObjRender_GetX(objectID)<GetStgFrameLeft-distance||
		ObjRender_GetY(objectID)>GetStgFrameHeight+distance||ObjRender_GetY(objectID)<GetStgFrameTop-distance;}

function CheckOutsideScreenA2(x, y, distance){
	return x>GetStgFrameWidth+distance||x<-distance||y>GetStgFrameHeight+distance||y<-distance;}

function SpawnEnemy_Fairy(x_appearance,y_appearance,color,life){
	let spirit = CreateEnemy_Fairy(life);
	LoadShot;
	ObjMove_SetPosition(spirit,x_appearance,y_appearance);
	ObjEnemy_SetDamageRate(spirit,100,100);
	AnimateEnemy_Fairy(spirit,color);
	return spirit;}

function CreateEnemy_Fairy(objlife){
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(obj);
	ObjEnemy_SetLife(obj,objlife);
	return obj;}

task AnimateEnemy_Fairy(id,color){
	let anim = 0;
	let animFrame = 0;
	let animFrame2 = 0;
	let fairyX;
	let fairyDir;
	let fairySpeed;
	let count;

	ObjPrim_SetTexture(id,enemy);
	while(!Obj_IsDeleted(id)){
		ObjSprite2D_SetDestCenter(id);
		fairyX = ObjMove_GetX(id);
		fairyDir = ObjMove_GetAngle(id);
		fairySpeed = ObjMove_GetSpeed(id);
		count = ObjEnemy_GetInfo(id,INFO_SHOT_HIT_COUNT);
	if(damage==1){
		ObjEnemy_SetIntersectionCircleToPlayer(id,ObjMove_GetX(id),ObjMove_GetY(id),16);
		ObjEnemy_SetIntersectionCircleToShot(id,ObjMove_GetX(id),ObjMove_GetY(id),16);}
	if(damage==0){yield;}

	if(ObjEnemy_GetInfo(id,INFO_LIFE) <= 0){ SE(se_enep1);
	if(color == "red"){
		loop(4){PowerS(ObjRender_GetX(id)+rand(-30,30),ObjRender_GetY(id)+rand(-30,30));}
		TExplosionB(ObjMove_GetX(id),ObjMove_GetY(id),"RED");yield;Obj_Delete(id);break;}
	if(color == "blue"){
		loop(4){Point(ObjRender_GetX(id)+rand(-30,30),ObjRender_GetY(id)+rand(-30,30));}
		TExplosionB(ObjMove_GetX(id),ObjMove_GetY(id),"BLUE");yield;Obj_Delete(id);break;}
	if(color == "yellow"){
		PowerS(ObjRender_GetX(id)+rand(-30,30),ObjRender_GetY(id)+rand(-30,30));
		TExplosionB(ObjMove_GetX(id),ObjMove_GetY(id),"YELLOW");yield;Obj_Delete(id);break;}
	if(color == "green"){
		loop(4){Point(ObjRender_GetX(id)+rand(-30,30),ObjRender_GetY(id)+rand(-30,30));}
		TExplosionB(ObjMove_GetX(id),ObjMove_GetY(id),"GREEN");yield;Obj_Delete(id);break;}
	if(color == "flower"){TExplosionB(ObjMove_GetX(id),ObjMove_GetY(id),"GREEN");
						Coin(ObjMove_GetX(id)-30,ObjMove_GetY(id));yield;Obj_Delete(id);break;}}

	if(CheckOutsideScreenA2(ObjMove_GetX(id),ObjMove_GetY(id),64)){Obj_Delete(id);break;}
	ascent(i in 0..30){
		if(count>10+20*i && count<=20+20*i){ObjRender_SetColor(id,64,64,255);}
		else{ObjRender_SetColor(id,255,255,255);}}

		if(color=="red"){
		    if(fairySpeed == 0){
			if(animFrame < 5){ObjSprite2D_SetSourceRect(id,0,288,32,320);}
			if(animFrame >= 5 && animFrame < 10){ObjSprite2D_SetSourceRect(id,32,288,64,320);}
			if(animFrame >= 10 && animFrame < 15){ObjSprite2D_SetSourceRect(id,64,288,96,320);}
			if(animFrame > 15){ObjSprite2D_SetSourceRect(id,96,288,128,320);}
			animFrame2 = 0;}
		    else if(cos(fairyDir) > 0){ 
			ObjRender_SetAngleXYZ(id,0,0,0);
			if(animFrame2 < 5){ObjSprite2D_SetSourceRect(id,128,288,160,320);}
			if(animFrame2 >= 5 && animFrame2 < 10){ObjSprite2D_SetSourceRect(id,160,288,192,320);}
			if(animFrame2 >= 10 && animFrame2 < 15){ObjSprite2D_SetSourceRect(id,192,288,224,320);}
			if(animFrame2 >= 15 && animFrame2 < 20){ObjSprite2D_SetSourceRect(id,224,288,256,320);}
			if(animFrame2 >= 20 && animFrame2 < 25){ObjSprite2D_SetSourceRect(id,256,288,288,320);}
			if(animFrame2 >= 25 && animFrame2 < 30){ObjSprite2D_SetSourceRect(id,288,288,320,320);}
			if(animFrame2 >= 30 && animFrame2 < 35){ObjSprite2D_SetSourceRect(id,320,288,352,320);}
			if(animFrame2 > 35){ObjSprite2D_SetSourceRect(id,352,288,384,320);}}
		    else if(cos(fairyDir) < 0){ 
			ObjRender_SetAngleXYZ(id,0,180,0);
			if(animFrame2 < 5){ObjSprite2D_SetSourceRect(id,128,288,160,320);}
			if(animFrame2 >= 5 && animFrame2 < 10){ObjSprite2D_SetSourceRect(id,160,288,192,320);}
			if(animFrame2 >= 10 && animFrame2 < 15){ObjSprite2D_SetSourceRect(id,192,288,224,320);}
			if(animFrame2 >= 15 && animFrame2 < 20){ObjSprite2D_SetSourceRect(id,224,288,256,320);}
			if(animFrame2 >= 20 && animFrame2 < 25){ObjSprite2D_SetSourceRect(id,256,288,288,320);}
			if(animFrame2 >= 25 && animFrame2 < 30){ObjSprite2D_SetSourceRect(id,288,288,320,320);}
			if(animFrame2 >= 30 && animFrame2 < 35){ObjSprite2D_SetSourceRect(id,320,288,352,320);}
			if(animFrame2 > 35){ObjSprite2D_SetSourceRect(id,352,288,384,320);}}}

		if(color=="green"){
		    if(fairySpeed == 0){
			if(animFrame < 5){ObjSprite2D_SetSourceRect(id,0,320,32,352);}
			if(animFrame >= 5 && animFrame < 10){ObjSprite2D_SetSourceRect(id,32,320,64,352);}
			if(animFrame >= 10 && animFrame < 15){ObjSprite2D_SetSourceRect(id,64,320,96,352);}
			if(animFrame > 15){ObjSprite2D_SetSourceRect(id,96,320,128,352);}
			animFrame2 = 0;}
		    else if(cos(fairyDir) > 0){ 
			ObjRender_SetAngleXYZ(id,0,0,0);
			if(animFrame2 < 5){ObjSprite2D_SetSourceRect(id,128,320,160,352);}
			if(animFrame2 >= 5 && animFrame2 < 10){ObjSprite2D_SetSourceRect(id,160,320,192,352);}
			if(animFrame2 >= 10 && animFrame2 < 15){ObjSprite2D_SetSourceRect(id,192,320,224,352);}
			if(animFrame2 >= 15 && animFrame2 < 20){ObjSprite2D_SetSourceRect(id,224,320,256,352);}
			if(animFrame2 >= 20 && animFrame2 < 25){ObjSprite2D_SetSourceRect(id,256,320,288,352);}
			if(animFrame2 >= 25 && animFrame2 < 30){ObjSprite2D_SetSourceRect(id,288,320,320,352);}
			if(animFrame2 >= 30 && animFrame2 < 35){ObjSprite2D_SetSourceRect(id,320,320,352,352);}
			if(animFrame2 > 35){ObjSprite2D_SetSourceRect(id,352,320,384,352);}}
		    else if(cos(fairyDir) < 0){ 
			ObjRender_SetAngleXYZ(id,0,180,0);
			if(animFrame2 < 5){ObjSprite2D_SetSourceRect(id,128,320,160,352);}
			if(animFrame2 >= 5 && animFrame2 < 10){ObjSprite2D_SetSourceRect(id,160,320,192,352);}
			if(animFrame2 >= 10 && animFrame2 < 15){ObjSprite2D_SetSourceRect(id,192,320,224,352);}
			if(animFrame2 >= 15 && animFrame2 < 20){ObjSprite2D_SetSourceRect(id,224,320,256,352);}
			if(animFrame2 >= 20 && animFrame2 < 25){ObjSprite2D_SetSourceRect(id,256,320,288,352);}
			if(animFrame2 >= 25 && animFrame2 < 30){ObjSprite2D_SetSourceRect(id,288,320,320,352);}
			if(animFrame2 >= 30 && animFrame2 < 35){ObjSprite2D_SetSourceRect(id,320,320,352,352);}
			if(animFrame2 > 35){ObjSprite2D_SetSourceRect(id,352,320,384,352);}}}

		if(color=="blue"){
		    if(fairySpeed == 0){
			if(animFrame < 5){ObjSprite2D_SetSourceRect(id,0,256,32,288);}
			if(animFrame >= 5 && animFrame < 10){ObjSprite2D_SetSourceRect(id,32,256,64,288);}
			if(animFrame >= 10 && animFrame < 15){ObjSprite2D_SetSourceRect(id,64,256,96,288);}
			if(animFrame > 15){ObjSprite2D_SetSourceRect(id,96,256,128,288);}
			animFrame2 = 0;}
		    else if(cos(fairyDir) > 0){ 
			ObjRender_SetAngleXYZ(id,0,0,0);
			if(animFrame2 < 5){ObjSprite2D_SetSourceRect(id,128,256,160,288);}
			if(animFrame2 >= 5 && animFrame2 < 10){ObjSprite2D_SetSourceRect(id,160,256,192,288);}
			if(animFrame2 >= 10 && animFrame2 < 15){ObjSprite2D_SetSourceRect(id,192,256,224,288);}
			if(animFrame2 >= 15 && animFrame2 < 20){ObjSprite2D_SetSourceRect(id,224,256,256,288);}
			if(animFrame2 >= 20 && animFrame2 < 25){ObjSprite2D_SetSourceRect(id,256,256,288,288);}
			if(animFrame2 >= 25 && animFrame2 < 30){ObjSprite2D_SetSourceRect(id,288,256,320,288);}
			if(animFrame2 >= 30 && animFrame2 < 35){ObjSprite2D_SetSourceRect(id,320,256,352,288);}
			if(animFrame2 > 35){ObjSprite2D_SetSourceRect(id,352,256,384,288);}}
		    else if(cos(fairyDir) < 0){ 
			ObjRender_SetAngleXYZ(id,0,180,0);
			if(animFrame2 < 5){ObjSprite2D_SetSourceRect(id,128,256,160,288);}
			if(animFrame2 >= 5 && animFrame2 < 10){ObjSprite2D_SetSourceRect(id,160,256,192,288);}
			if(animFrame2 >= 10 && animFrame2 < 15){ObjSprite2D_SetSourceRect(id,192,256,224,288);}
			if(animFrame2 >= 15 && animFrame2 < 20){ObjSprite2D_SetSourceRect(id,224,256,256,288);}
			if(animFrame2 >= 20 && animFrame2 < 25){ObjSprite2D_SetSourceRect(id,256,256,288,288);}
			if(animFrame2 >= 25 && animFrame2 < 30){ObjSprite2D_SetSourceRect(id,288,256,320,288);}
			if(animFrame2 >= 30 && animFrame2 < 35){ObjSprite2D_SetSourceRect(id,320,256,352,288);}
			if(animFrame2 > 35){ObjSprite2D_SetSourceRect(id,352,256,384,288);}}}

		if(color=="yellow"){
		    if(fairySpeed == 0){
			if(animFrame < 5){ObjSprite2D_SetSourceRect(id,0,352,32,384);}
			if(animFrame >= 5 && animFrame < 10){ObjSprite2D_SetSourceRect(id,32,352,64,384);}
			if(animFrame >= 10 && animFrame < 15){ObjSprite2D_SetSourceRect(id,64,352,96,384);}
			if(animFrame > 15){ObjSprite2D_SetSourceRect(id,96,352,128,384);}
			animFrame2 = 0;}
		    else if(cos(fairyDir) > 0){ 
			ObjRender_SetAngleXYZ(id,0,0,0);
			if(animFrame2 < 5){ObjSprite2D_SetSourceRect(id,128,352,160,384);}
			if(animFrame2 >= 5 && animFrame2 < 10){ObjSprite2D_SetSourceRect(id,160,352,192,384);}
			if(animFrame2 >= 10 && animFrame2 < 15){ObjSprite2D_SetSourceRect(id,192,352,224,384);}
			if(animFrame2 >= 15 && animFrame2 < 20){ObjSprite2D_SetSourceRect(id,224,352,256,384);}
			if(animFrame2 >= 20 && animFrame2 < 25){ObjSprite2D_SetSourceRect(id,256,352,288,384);}
			if(animFrame2 >= 25 && animFrame2 < 30){ObjSprite2D_SetSourceRect(id,288,352,320,384);}
			if(animFrame2 >= 30 && animFrame2 < 35){ObjSprite2D_SetSourceRect(id,320,352,352,384);}
			if(animFrame2 > 35){ObjSprite2D_SetSourceRect(id,352,352,384,384);}}
		    else if(cos(fairyDir) < 0){ 
			ObjRender_SetAngleXYZ(id,0,180,0);
			if(animFrame2 < 5){ObjSprite2D_SetSourceRect(id,128,352,160,384);}
			if(animFrame2 >= 5 && animFrame2 < 10){ObjSprite2D_SetSourceRect(id,160,352,192,384);}
			if(animFrame2 >= 10 && animFrame2 < 15){ObjSprite2D_SetSourceRect(id,192,352,224,384);}
			if(animFrame2 >= 15 && animFrame2 < 20){ObjSprite2D_SetSourceRect(id,224,352,256,384);}
			if(animFrame2 >= 20 && animFrame2 < 25){ObjSprite2D_SetSourceRect(id,256,352,288,384);}
			if(animFrame2 >= 25 && animFrame2 < 30){ObjSprite2D_SetSourceRect(id,288,352,320,384);}
			if(animFrame2 >= 30 && animFrame2 < 35){ObjSprite2D_SetSourceRect(id,320,352,352,384);}
			if(animFrame2 > 35){ObjSprite2D_SetSourceRect(id,352,352,384,384);}}}

		if(color=="flower"){
		    if(fairySpeed == 0){
			if(animFrame < 5){ObjSprite2D_SetSourceRect(id,0,384,64,448);}
			if(animFrame >= 5 && animFrame < 10){ObjSprite2D_SetSourceRect(id,64,384,128,448);}
			if(animFrame >= 10 && animFrame < 15){ObjSprite2D_SetSourceRect(id,128,384,192,448);}
			if(animFrame > 15){ObjSprite2D_SetSourceRect(id,192,384,256,448);}
			animFrame2 = 0;}
		    else if(cos(fairyDir) > 0){ 
			ObjRender_SetAngleXYZ(id,0,0,0);
			if(animFrame2 < 5){ObjSprite2D_SetSourceRect(id,256,384,320,448);}
			if(animFrame2 >= 5 && animFrame2 < 10){ObjSprite2D_SetSourceRect(id,320,384,384,448);}
			if(animFrame2 >= 10 && animFrame2 < 15){ObjSprite2D_SetSourceRect(id,384,384,448,448);}
			if(animFrame2 >= 15 && animFrame2 < 20){ObjSprite2D_SetSourceRect(id,448,384,512,448);}
			if(animFrame2 >= 20 && animFrame2 < 25){ObjSprite2D_SetSourceRect(id,384,256,448,320);}
			if(animFrame2 >= 25 && animFrame2 < 30){ObjSprite2D_SetSourceRect(id,448,256,512,320);}
			if(animFrame2 >= 30 && animFrame2 < 35){ObjSprite2D_SetSourceRect(id,384,320,448,384);}
			if(animFrame2 > 35){ObjSprite2D_SetSourceRect(id,448,320,512,384);}}
		    else if(cos(fairyDir) < 0){ 
			ObjRender_SetAngleXYZ(id,0,180,0);
			if(animFrame2 < 5){ObjSprite2D_SetSourceRect(id,256,384,320,448);}
			if(animFrame2 >= 5 && animFrame2 < 10){ObjSprite2D_SetSourceRect(id,320,384,384,448);}
			if(animFrame2 >= 10 && animFrame2 < 15){ObjSprite2D_SetSourceRect(id,384,384,448,448);}
			if(animFrame2 >= 15 && animFrame2 < 20){ObjSprite2D_SetSourceRect(id,448,384,512,448);}
			if(animFrame2 >= 20 && animFrame2 < 25){ObjSprite2D_SetSourceRect(id,384,256,448,320);}
			if(animFrame2 >= 25 && animFrame2 < 30){ObjSprite2D_SetSourceRect(id,448,256,512,320);}
			if(animFrame2 >= 30 && animFrame2 < 35){ObjSprite2D_SetSourceRect(id,384,320,448,384);}
			if(animFrame2 > 35){ObjSprite2D_SetSourceRect(id,448,320,512,384);}}}
		   if(color=="zombie"){
		    if(cos(fairyDir) > 0){ ObjRender_SetAngleXYZ(id,0,0,0);
			if(anim < 6){ObjSprite2D_SetSourceRect(id,256,32,288,64);}
			if(anim >= 6 && anim < 18){ObjSprite2D_SetSourceRect(id,288,32,320,64);}
			if(anim >= 18 && anim < 24){ObjSprite2D_SetSourceRect(id,320,32,352,64);}
			if(anim >= 24){ObjSprite2D_SetSourceRect(id,352,32,384,64);}}
		    if(cos(fairyDir) < 0){ ObjRender_SetAngleXYZ(id,0,180,0);
			if(anim < 5){ObjSprite2D_SetSourceRect(id,256,32,288,64);}
			if(anim >= 5 && anim < 10){ObjSprite2D_SetSourceRect(id,288,32,320,64);}
			if(anim >= 10 && anim < 15){ObjSprite2D_SetSourceRect(id,320,32,352,64);}
			if(anim >= 15){ObjSprite2D_SetSourceRect(id,352,32,384,64);}}}
		count++;
		anim++;
		animFrame++;
		animFrame2++;
		if(anim >= 20){anim = 0;}
		if(animFrame >= 20){animFrame = 0;}
		if(animFrame2 >= 40){animFrame2 = 20;}
		yield;}}

function SpawnEnemy_Spirit(x_appearance,y_appearance,color,life){
	let spirit = CreateEnemy_Spirit(life);
	ObjMove_SetPosition(spirit,x_appearance,y_appearance);
	ObjEnemy_SetDamageRate(spirit,100,100);
	AnimateEnemy_Spirit(spirit,color);
	return spirit;}

function CreateEnemy_Spirit(objlife){
	let obj = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(obj);
	ObjEnemy_SetLife(obj,objlife);
	return obj;}

task AnimateEnemy_Spirit(id,color){
	let animFrame = 0;
	if(color == "red"){TEnemyAura(id,255,50,50);}
	if(color == "green"){TEnemyAura(id,50,255,50);}
	if(color == "blue"){TEnemyAura(id,50,50,255);}
	if(color == "yellow"){TEnemyAura(id,255,255,50);}
	
	while(!Obj_IsDeleted(id)){
	ObjPrim_SetTexture(id,enemy2);
	ObjSprite2D_SetDestCenter(id);

	if(damage==1){
		ObjEnemy_SetIntersectionCircleToPlayer(id,ObjMove_GetX(id),ObjMove_GetY(id),15);
		ObjEnemy_SetIntersectionCircleToShot(id,ObjMove_GetX(id),ObjMove_GetY(id),15);}
	if(damage==0){yield;}

	if(ObjEnemy_GetInfo(id,INFO_LIFE) <= 0) { SE(se_enep1);
	if(color == "red"){
		loop(4){PowerS(ObjRender_GetX(id)+rand(-30,30),ObjRender_GetY(id)+rand(-30,30));}
		TExplosionB(ObjMove_GetX(id),ObjMove_GetY(id),"RED");yield;Obj_Delete(id);break;}
	if(color == "blue"){
		loop(4){Point(ObjRender_GetX(id)+rand(-30,30),ObjRender_GetY(id)+rand(-30,30));}
		TExplosionB(ObjMove_GetX(id),ObjMove_GetY(id),"BLUE");yield;Obj_Delete(id);break;}
	if(color == "yellow"){
		loop(4){PowerS(ObjRender_GetX(id)+rand(-30,30),ObjRender_GetY(id)+rand(-30,30));}
		TExplosionB(ObjMove_GetX(id),ObjMove_GetY(id),"YELLOW");yield;Obj_Delete(id);break;}
	if(color == "green"){
		loop(5){Point(ObjRender_GetX(id)+rand(-30,30),ObjRender_GetY(id)+rand(-30,30));}
		TExplosionB(ObjMove_GetX(id),ObjMove_GetY(id),"GREEN");yield;Obj_Delete(id);break;}}

	if(CheckOutsideScreenA2(ObjMove_GetX(id),ObjMove_GetY(id),64)){
		Obj_Delete(id); break;}

		if(color=="red"){ ascent(i in 0..8){
			if(animFrame >= i*5 && animFrame < 5+i*5){ObjSprite2D_SetSourceRect(id,i*32,0,32+i*32,32);}}}
		if(color=="green"){ ascent(i in 0..8){
			if(animFrame >= i*5 && animFrame < 5+i*5){ObjSprite2D_SetSourceRect(id,i*32,32,32+i*32,64);}}}
		if(color=="blue"){ ascent(i in 0..8){
			if(animFrame >= i*5 && animFrame < 5+i*5){ObjSprite2D_SetSourceRect(id,i*32,64,32+i*32,96);}}}
		if(color=="yellow"){ ascent(i in 0..8){
			if(animFrame >= i*5 && animFrame < 5+i*5){ObjSprite2D_SetSourceRect(id,i*32,96,32+i*32,128);}}}

		if(animFrame >= 40){animFrame = 0;}
		animFrame++;
		yield;}}

task TEnemyAura(obj,r,g,b){
	let anim = 0;
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	let graphic = GetCurrentScriptDirectory() ~ "./enemy_aura.png";
	ObjPrim_SetTexture(obj2,graphic);
	Obj_SetRenderPriorityI(obj2,30);
	ObjRender_SetBlendType(obj2,BLEND_ADD_ARGB);
	ObjRender_SetScaleXYZ(obj2,0.9,0.9,0);
	ObjRender_SetColor(obj2,r,g,b);

	while(!Obj_IsDeleted(obj)){
		ObjRender_SetPosition(obj2,ObjRender_GetX(obj)+1,ObjRender_GetY(obj)-6,0);
		ascent(i in 0..8){
			if(anim >= i*5 && anim < 5+i*5){
			ObjSprite2D_SetSourceRect(obj2,i*48,0,48+i*48,48);
			ObjSprite2D_SetDestCenter(obj2);}}
		if(anim>=40){anim=0;}
	anim++; yield;}
	Obj_Delete(obj2);}

task reflectX(object){
	while(ObjMove_GetX(object) > 0 && ObjMove_GetX(object) < 384 && ObjMove_GetY(object) > 0){yield;}
	if(ObjMove_GetX(object) <= 0){
		ObjMove_SetAngle(object,180-ObjMove_GetAngle(object));}
	if(ObjMove_GetX(object) >= 384){
		ObjMove_SetAngle(object,180-ObjMove_GetAngle(object));}
	if(ObjMove_GetY(object) <= 0){
		ObjMove_SetAngle(object,-ObjMove_GetAngle(object));}}

task MiyakoAppearance{
	TConcentration(0,255,64,64);
	TConcentration(120,64,64,255);
	TConcentration(240,64,255,64);

	task TConcentration(angle,r,b,g){
		let obj = ObjPrim_Create(OBJ_SPRITE_2D);
		let item = GetCurrentScriptDirectory() ~ "./../Image/Halo.png";
		ObjPrim_SetTexture(obj,item);
		Obj_SetRenderPriorityI(obj,60);
		ObjSprite2D_SetSourceRect(obj,0,0,256,256);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
		ObjRender_SetColor(obj,r,g,b);
		ObjRender_SetScaleXYZ(obj,1,1,0);
		let move = 0;
		let rad = 420;
		loop(340){
			ObjRender_SetPosition(obj,GetStgFrameWidth/2+rad*cos(move+angle),GetStgFrameHeight/2-80+rad*sin(move+angle),0);
			move+=5;rad-=3;yield;}
		Obj_Delete(obj);}}

function PowerS(x,y){
	let obj = CreateItemU2(1,x,y,x,y-32,100);
	itemHandler(obj,1,0);
	return obj;}
function PowerB(x,y){
	let obj = CreateItemU2(2,x,y,x,y-32,500);
	itemHandler(obj,1,0);
	return obj;}
function PowerL(x,y){
	let obj = CreateItemU2(3,x,y,x,y-32,1000);
	itemHandler(obj,1,0);
	return obj;}
function Point(x,y){ 
	let obj = CreateItemU2(4,x,y,x,y-32,1500);
	itemHandler(obj,1,0);
	return obj;}
function LIFEUP(x,y){ 
	let obj = CreateItemU2(5,x,y,x,y-32,10000);
	itemHandler(obj,1,0);
	return obj;}
function SPELLUP(x,y){ 
	let obj = CreateItemU2(6,x,y,x,y-32,5000);
	itemHandler(obj,1,0);
	return obj;}
function PowerFull(x,y){ 
	let obj = CreateItemU2(7,x,y,x,y-32,10000);
	itemHandler(obj,1,0);
	return obj;}
function Item(x,y){ 
	let obj = CreateItemU2(8,x,y,x,y-32,200);
	return obj;}
function LifeP(x,y){ 
	let obj = CreateItemU2(9,x,y,x,y-32,200);
	itemHandler(obj,1,0);
	return obj;}
function SpellP(x,y){
	let obj = CreateItemU2(10,x,y,x,y-32,200);
	itemHandler(obj,1,0);
	return obj;}
function Coin(x,y){
	let obj = CreateItemU2(11,x,y,x,y-32,200);
	TCoinEffect(obj);
	return obj;}

task itemHandler(obj,v,s){ 
	let itemX = 0;
	let itemY = 0;
	let itemDir = 0;
	
	while(!Obj_IsDeleted(obj)){
		itemX = ObjMove_GetX(obj);
		itemY = ObjMove_GetY(obj);
		ObjRender_SetAngleZ(obj,itemDir);
		if(itemDir < 360) { itemDir+=12; } 
		CollectItemsInCircle(GetPlayerX,GetPlayerY,64); 
		
		if(ObjMove_GetX(obj) < -4 || ObjMove_GetX(obj) > 388 || ObjMove_GetY(obj) > GetStgFrameHeight+4)
		{break;}
		yield;}
	Obj_Delete(obj);}

task TCoinEffect(object){
	let path = GetCurrentScriptDirectory ~ "./../Functions/Coin.mqo";
	let obj = ObjMesh_Create();
	ObjMesh_Load(obj, path);
	ObjMesh_SetCoordinate2D(obj,true);

	ObjRender_SetScaleXYZ(obj,0.4,0.4,0.4);
	Obj_SetRenderPriority(obj,0.6);
	ObjRender_SetAngleZ(obj,90);
	ObjRender_SetAngleX(obj,54);
	let color = 0;
	let time = 40;
	let angy = 0;
	let r = 100;
	let g = 255;
	let b = 100;
	let index = (g-b)/time;
	while(!Obj_IsDeleted(object)){
		ObjRender_SetPosition(obj,ObjRender_GetX(object),ObjRender_GetY(object),0);
		ObjRender_SetAngleY(obj,angy);
		if(angy>=360){angy=0;}
		
		if(color>=0 && color<time){
			ObjMesh_SetColor(obj,r,g,b);
			g-=index; r+=index;}
		if(color>=time && color<time*2){
			ObjMesh_SetColor(obj,r,g,b);
			r-=index; b+=index;}
		if(color>=time*2 && color<time*3){
			ObjMesh_SetColor(obj,r,g,b);
			b-=index; g+=index;}
		if(color>=time*3){color=0;}
		color++; 
		angy+=3; yield;}
	Obj_Delete(obj);}
task TFairyU1{
	let alpha = 0;let scale = 0;let angle = 0;
	let obj = SpawnEnemy_Fairy(192,50,"flower",600);
	loop(100){
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		scale+=1/100;alpha+=255/100;yield;}
		damage=1;
	w(30);
	if(!Obj_IsDeleted(obj)){
	let shot1 = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),3,GetAngleToPlayer(obj),823,30);
	let shot2 = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),3,GetAngleToPlayer(obj)+50,824,30);
	let shot3 = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),3,GetAngleToPlayer(obj)-50,825,30);
	TSpawn(shot1,519,332);TSpawn(shot2,523,334);TSpawn(shot3,527,336);
	reflectX(shot1);reflectX(shot2);reflectX(shot3);}
	w(30); ascent(i in 0..20){
		CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(1,3),i*18+rand(-6,6),rand(823,825),0);}
	SE(se_tan);

	task TSpawn(object,color,color2){let angle = 0; 
		while(!Obj_IsDeleted(object)){
			let s = CreateShotA1(ObjMove_GetX(object)+rand(-10,10),ObjMove_GetY(object)+rand(-10,10),0,0,color,15);
			manage(s,angle); w(2);angle+=15;}
			task manage(o,ang){w(90); if(!Obj_IsDeleted(o)){
				CreateShotA2(ObjMove_GetX(o),ObjMove_GetY(o),5,ang,-0.4,rand(0.6,1),color2,15);
				Obj_Delete(o);}w(15);SE(se_kira);}}
	w(90);
	ObjMove_SetDestAtWeight(obj,192,-80,5,1);}

task TFairyU2(x,y,x1,y1,x2,y2){
	let obj = SpawnEnemy_Fairy(x,y,"flower",800);
	ObjMove_SetDestAtWeight(obj,x1,y1,5,2);
	w(90);
	let angle = 0;
	let player = GetAngleToPlayer(obj);
		loop(15){
			if(Obj_IsDeleted(obj)){break;}
			CreateShotL1(ObjMove_GetX(obj),ObjMove_GetY(obj),player+2.5+angle);
			CreateShotL1(ObjMove_GetX(obj),ObjMove_GetY(obj),player-2.5-angle);
			w(4);angle+=5;}
	w(90);
	ObjMove_SetDestAtWeight(obj,x2,y2,5,2);
	
	function CreateShotL1(x,y,ang){
		if(!Obj_IsDeleted(obj)){
		let shot = CreateShotA2(x,y,5,ang,-0.2,0,780,30);
		ObjShot_SetSpellResist(shot,true);
		task manage{
			while(ObjMove_GetSpeed(shot) > 0){yield;}
				let l = CreateStraightLaserA1(ObjMove_GetX(shot),ObjMove_GetY(shot),ObjMove_GetAngle(shot),400,20,60,1021,60);
				ObjShot_SetSpellResist(l,true);
			w(60);SE(se_lazer);
			w(60);ObjShot_FadeDelete(shot);}
		manage;}}}

task TSpiritU2(x,y,ang){
	let obj = SpawnEnemy_Spirit(x,y,"blue",200);
	let count = 0;
		
	ObjMove_SetAngle(obj,ang);
	ObjMove_SetSpeed(obj,0.8);
	w(90);
	while(!Obj_IsDeleted(obj)){
	let r = rand(0,24);
	if(Obj_IsDeleted(obj)){break;}
	ascent(i in 0..20){ ascent(s in 0..3){
		let a = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),6+s,i*18+r,22,0);
		ObjMove_AddPatternA1(a,10,2,NO_CHANGE);}}
	if(count>=8){break;}
	SE(se_tan);w(30);count++;}}

task TFairyU3(x,ang){
	let obj = SpawnEnemy_Fairy(x,rand(0,50),"flower",500);
	ObjMove_SetSpeed(obj,5);
	ObjMove_SetAngle(obj,ang);
	w(30);
	if(!Obj_IsDeleted(obj)){
		ascent(i in 0..30){
			ascent(a in 1..5){
			CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1+a,GetAngleToPlayer(obj)+i*12,333,10);}
		let sh2=CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),4,GetAngleToPlayer(obj)+i*12,523,10);
		ObjMove_AddPatternA1(sh2,10,2,GetAngleToPlayer(sh2));}
		}
	w(10);SE(se_tan);}

task TFairyU4(x,wert){damage=1;
	let obj = SpawnEnemy_Fairy(x,-50,"flower",800);
	ObjMove_SetDestAtWeight(obj,x,50,5,3);
	w(60);SE(se_tan);
	let fam = CreateFamilar(ObjMove_GetX(obj),ObjMove_GetY(obj),255,255,200);
	ObjMove_SetAngle(fam,GetAngleToPlayer(fam));
	ObjMove_SetSpeed(fam,3);
	while(!Obj_IsDeleted(fam)){
		if(CheckOutsideScreenA2(ObjMove_GetX(fam),ObjMove_GetY(fam),15)){
			Obj_Delete(fam);break;}
		let s1 = CreateShotA1(ObjMove_GetX(fam)+rand(-8,8),ObjMove_GetY(fam)+rand(-8,8),0,ObjMove_GetAngle(fam)+90,523,15);
		let s2 = CreateShotA1(ObjMove_GetX(fam)+rand(-8,8),ObjMove_GetY(fam)+rand(-8,8),0,ObjMove_GetAngle(fam)-90,523,15);
		tManage(s1);tManage(s2); w(2); SE(se_kira3);}w(60);
	ObjMove_SetDestAtWeight(obj,x+wert,50,5,3);w(30);
	
	if(!Obj_IsDeleted(obj)){SE(se_tan);
	let fam2 = CreateFamilar(ObjMove_GetX(obj),ObjMove_GetY(obj),255,255,200);
	ObjMove_SetAngle(fam2,GetAngleToPlayer(fam2));
	ObjMove_SetSpeed(fam2,3);
	while(!Obj_IsDeleted(fam2)){
		if(CheckOutsideScreenA2(ObjMove_GetX(fam2),ObjMove_GetY(fam2),15)){
			Obj_Delete(fam2);break;}
		let s1 = CreateShotA1(ObjMove_GetX(fam2)+rand(-8,8),ObjMove_GetY(fam2)+rand(-8,8),0,ObjMove_GetAngle(fam2)+90,523,15);
		let s2 = CreateShotA1(ObjMove_GetX(fam2)+rand(-8,8),ObjMove_GetY(fam2)+rand(-8,8),0,ObjMove_GetAngle(fam2)-90,523,15);
		tManage(s1);tManage(s2); w(2); SE(se_kira);}}
	
	task tManage(object){ w(90); if(!Obj_IsDeleted(object)){
		CreateShotA2(ObjMove_GetX(object),ObjMove_GetY(object),0,ObjMove_GetAngle(object),0.2,rand(0.5,2),834,15);
		Obj_Delete(object);}w(15);SE(se_kira);}}

task TFairyU5(x){
	let count = 0; let move = 0; let angle_a = 0;let angle_c = 0;
	let obj = SpawnEnemy_Fairy(x,-50,"flower",1000);
	ObjMove_SetDestAtWeight(obj,x,100,5,3);

	ascent(i in 0..4){
	let fam = CreateFamilar(0,0,255,255,255);
		manage(fam,i*90);shot(fam);}w(120);
		
	while(!Obj_IsDeleted(obj)){count++;
	ascent(i in 0..30){
		let shot = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),0,GetAngleToPlayer(obj)+i*12,278,10);
		TSpeed(shot);}
	w(5); SE(se_tan); if(count>=65){break;}}
	
	task TSpeed(object){
		loop(28){ObjMove_SetSpeed(object,ObjMove_GetSpeed(object)+0.2);
			w(2);}}
	ObjMove_SetDestAtWeight(obj,x,-100,5,3);

	task manage(object,ang){
	while(!Obj_IsDeleted(obj)){
		ObjMove_SetPosition(object,ObjMove_GetX(obj)+120*cos(move+ang),ObjMove_GetY(obj)+120*sin(move+ang));
		ObjMove_SetAngle(object,move+ang);move+=0.5;yield;}
	Obj_Delete(object);}
		
	task shot(object){ w(90); while(!Obj_IsDeleted(obj)){
		let a = CreateShotA1(ObjMove_GetX(object),ObjMove_GetY(object),1,angle_a+140,375,10);
		let c = CreateShotA1(ObjMove_GetX(object),ObjMove_GetY(object),1,angle_c,377,10);
		angle_a = atan2(ObjMove_GetY(a)-ObjMove_GetY(obj),ObjMove_GetX(a)-ObjMove_GetX(obj));
		angle_c = atan2(ObjMove_GetY(c)-ObjMove_GetY(obj),ObjMove_GetX(c)-ObjMove_GetX(obj));
		w(3);SE(se_kira3);}}}

task TFairyU6{
	let count = 0;
	let obj = SpawnEnemy_Fairy(192,-50,"flower",1000);
	ObjMove_SetDestAtWeight(obj,192,100,5,3);
	
	w(90);
	let angle = 0;
	while(!Obj_IsDeleted(obj)){
		ascent(i in 0..12){
		let s = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),5,i*30,214,0);
		ObjMove_AddPatternA1(s,3,2,angle);}
		CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),2,-angle,37,15);
		angle+=49;count++;
		if(count>=150){break;}
	w(2);SE(se_tan);}w(45);
	ObjMove_SetAngle(obj,270);
	ObjMove_SetSpeed(obj,1);}

task TSpiritU6(x,y,x1,y1){
	let obj = SpawnEnemy_Spirit(x,y,"red",200);
	ObjMove_SetDestAtWeight(obj,x1,y1,5,3);
	w(90);
	let ang = GetAngleToPlayer(obj);
	loop(6){
		if(Obj_IsDeleted(obj)){break;}
		ascent(i in -6..7){
			let a = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),6,ang+i*8,333,15);
			ObjMove_AddPatternA1(a,10,3,NO_CHANGE);}
	w(4);}
	ObjEnemy_SetLife(obj,0);}

task TFairyU8(x1,y1,x2,y2,move,gr){let count = 0;let angle = 0;
	let obj = SpawnEnemy_Fairy(x1,y2,"yellow",500);
	ObjMove_SetDestAtWeight(obj,x2,y2,5,5);w(60);
	while(!Obj_IsDeleted(obj)){ ascent(i in 0..6){
		let shot = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),8,angle+i*60,gr,5);
		TSpeed(shot);}
		if(count>=90){break;}
	yield;angle+=move*8;count++;SE(se_tan3);}
	w(60);
	ObjMove_SetDestAtWeight(obj,x2,y2-150,5,5);

	task TSpeed(object){w(20);
		while(ObjMove_GetSpeed(object) > 1){yield;
		ObjMove_SetSpeed(object,ObjMove_GetSpeed(object)-0.2);}}}

task TFairyU10(type,gr){damage=1;
	let obj = SpawnEnemy_Fairy(192,-50,"flower",800);
	ObjMove_SetDestAtWeight(obj,192,192,5,4);
	if(type == "red"){
		ascent(i in 0..10){tSpirit(i*36,1,332,8,45,90);}}
	if(type == "green"){
		ascent(i in 0..10){tSpirit(i*36,1,336,6,40,80);}
		w(40);
		ascent(i in 0..10){tSpirit(i*36,-1,336,6,40,95);}}
	if(type == "blue"){
		ascent(i in 0..10){tSpirit(i*36,1,334,4,30,70);}w(30);
		ascent(i in 0..10){tSpirit(i*36,-1,334,4,30,95);}w(30);
		ascent(i in 0..10){tSpirit(i*36,1,334,4,30,110);}}
	w(60);
	while(!Obj_IsDeleted(obj)){
		tShot;
		loop(30){
		if(type=="red" && Obj_IsDeleted(obj)){PowerL(192,180);break;}
		if(type=="green" && Obj_IsDeleted(obj)){SpellP(192,180);break;}
		if(type=="blue" && Obj_IsDeleted(obj)){LifeP(192,180);break;}
		yield;}}
		
	task tShot{
	let a = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),5,350-rand(0,20),gr,30);
	let b = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),5,190+rand(0,20),gr,30);
	SE(se_kira);
	loop(90){
		ObjMove_SetSpeed(a,ObjMove_GetSpeed(a) - 5/90);
		ObjMove_SetSpeed(b,ObjMove_GetSpeed(b) - 5/90);
		yield;}
	loop(5){yield;}
	ObjMove_SetAngle(a,GetAngleToPlayer(a));
	ObjMove_SetAngle(b,GetAngleToPlayer(b));
	loop(90){
		ObjMove_SetSpeed(a,ObjMove_GetSpeed(a) + 4/90);
		ObjMove_SetSpeed(b,ObjMove_GetSpeed(b) + 4/90);
		yield;}}
	
	task tSpirit(ang,turn,gra,length,per,rad){ let way = 0; let r = 0;
		let spi = SpawnEnemy_Spirit(192,-50,type,400);
		move;w(90);
		while(!Obj_IsDeleted(spi)){ loop(length){ w(3);SE(se_tan);
			let x = ObjMove_GetX(spi);
			let y = ObjMove_GetY(spi);
			if(Obj_IsDeleted(spi)){break;}
			if(Obj_IsDeleted(obj)){break;}
			CreateShotA1(x,y,1.5,atan2(y-ObjMove_GetY(obj),x-ObjMove_GetX(obj)),gra,0);}
		w(per);}
		task move{
			while(!Obj_IsDeleted(obj)){
				ObjMove_SetPosition(spi,ObjMove_GetX(obj)+r*cos(way+ang),ObjMove_GetY(obj)+r*sin(way+ang));
				if(r>=rad){r=rad;}way+=1*turn; r+=2; yield;}
		ObjEnemy_SetLife(spi,0);}}}