#include"./../System/Minoriko_Effect.txt"
#include"./../Spells/LoadGraphics.txt"
let enemypath=enemy;
let damage = 0;

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

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

task shot_se{
let shot = GetCurrentScriptDirectory ~ "./../Sounds/se_tan00b.wav";
let obj_se = ObjSound_Create;
	ObjSound_Load(obj_se,shot);
	ObjSound_Play(obj_se);
	ObjSound_SetVolumeRate(obj_se,50);}

task shot_se_kira{
let shot = GetCurrentScriptDirectory ~ "./../Sounds/se_kira00.wav";
let obj_se = ObjSound_Create;
	ObjSound_Load(obj_se,shot);
	ObjSound_Play(obj_se);
	ObjSound_SetVolumeRate(obj_se,50);}

task shot_se_kill{
let shot = GetCurrentScriptDirectory ~ "./../Sounds/se_enep00.wav";
let obj_se = ObjSound_Create;
	ObjSound_Load(obj_se,shot);
	ObjSound_Play(obj_se);
	ObjSound_SetVolumeRate(obj_se,50);}

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

task CreateArrowShot(obj,speed,ang,segment,gr,delay,bool){
	let step = 0;
	let x = 0;
	loop(5){
		let a = CreateShotA1(ObjMove_GetX(obj)+x*cos(ang+step),ObjMove_GetY(obj)+x*sin(ang+step),-speed,ang+step,gr,delay);
		let b = CreateShotA1(ObjMove_GetX(obj)+x*cos(ang-step),ObjMove_GetY(obj)+x*sin(ang-step),-speed,ang-step,gr,delay);
		if(bool == true){
			ObjMove_AddPatternA3(a,30,-1,ObjMove_GetAngle(a)+rand(-8,8),14,rand(-0.1,0.1),-2,NO_CHANGE);
			ObjMove_AddPatternA3(b,30,-1,ObjMove_GetAngle(b)+rand(-8,8),14,rand(-0.1,0.1),-2,NO_CHANGE);}
		x+=15;step+=segment;}}

task TFairyA1{
	let alpha = 0;let scale = 0;let ang = 0;
	let obj = SpawnEnemy_Fairy(192,50,"flower",1500);
	let x = ObjMove_GetX(obj);
	let y = ObjMove_GetY(obj);
	loop(100){
		ObjRender_SetAlpha(obj,alpha);
		ObjRender_SetScaleXYZ(obj,scale,scale,0);
		scale+=0.01;alpha+=2.55;yield;}damage=1;
	w(30);
	let angle1 = 0;
	let angle2 = 0;
	loop(12){
		if(Obj_IsDeleted(obj)){ break; }
		shot_se; ascent(i in 0..12){
		CreateArrowShot(obj,6,ang+i*30,1.5,276,15,false);}
	w(20);ang+=12;}

	w(45);
	let cir2 = 0;
	loop(36){PowerS(x+90*cos(cir2),y+90*sin(cir2));cir2+=10;}

	ObjEnemy_SetLife(obj,0);}

task TFairyA2(x,y,vel){
	let r = rand(-8,8);
	let obj = SpawnEnemy_Fairy(x+r,y+r,"red",15);
	TMove;w(30);shot_se;
	if(!Obj_IsDeleted(obj)){ ascent(a in -2..3){
		let s = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),8,GetAngleToPlayer(obj)+a*25,39,0);
		ObjMove_AddPatternA1(s,20,4,NO_CHANGE);}}

	task TMove{
		ObjMove_SetAngle(obj,90);
		ObjMove_SetSpeed(obj,4);
		w(40);
		ObjMove_SetAngle(obj,90);
		ObjMove_SetSpeed(obj,4);
		ObjMove_SetAngularVelocity(obj,vel);
		w(90);
		ObjMove_SetSpeed(obj,4);
		ObjMove_SetAngularVelocity(obj,0);}}

task TFairyA3(x,st){
	let obj = SpawnEnemy_Fairy(x,100,"flower",500);
	TMove;
	w(80);
	while(!Obj_IsDeleted(obj)){
		ascent(i in 0..15){shot_se;
			ascent(a in 1..3){
			CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1+a,i*24,829,10);}}
		w(40);}
	task TMove{ let ang = 0;
		while(!Obj_IsDeleted(obj)){
			ObjMove_SetDestAtSpeed(obj,x+350*cos(270-ang),100+50*sin(270-ang),3);
		ang+=st;yield;}}}

task TFairyA4(x1,y1,x2,y2,x3,y3){damage=1;
	let obj = SpawnEnemy_Fairy(x1,y1,"yellow",500);
	ObjMove_SetDestAtWeight(obj,x2,y2,5,3);
	w(120);
	let angle = GetAngleToPlayer(obj);
	if(!Obj_IsDeleted(obj)){ leaf(angle); }
	w(120);
	ObjMove_SetDestAtWeight(obj,x3,y3,5,3);

	function leaf(ang){
	let count = 1; 
	loop(10){
	if(Obj_IsDeleted(obj)){ break; } 
	ascent(an in 0..count){shot_se;
		let s = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),10,ang+an*2-count,378,10);
		ObjMove_AddPatternA1(s,15,3,NO_CHANGE);}
	w(4);count+=1;}}}

task TFairyA5(x1,y1,x2,y2,x3,y3,gr){
	let obj = SpawnEnemy_Fairy(x1,y1,"yellow",500);
	ObjMove_SetDestAtWeight(obj,x2,y2,2,3);
	w(90);shot_se;
	if(!Obj_IsDeleted(obj)){
		let angle = GetAngleToPlayer(obj);
		shot_se; ascent(s in 0..3){ ascent(i in -1..2){
		CreateArrowShot(obj,2+s*2,angle+180+i*30,1.5,gr,15,false);}}}
	w(90);
	ObjMove_SetDestAtWeight(obj,x3,y3,2,3);}

task TFairyB5(x1,y1,x2,y2,x3,y3,gr){
	let obj = SpawnEnemy_Fairy(x1,y1,"yellow",500);
	ObjMove_SetDestAtWeight(obj,x2,y2,2,3);
	w(90);shot_se;
	if(!Obj_IsDeleted(obj)){
		shot_se; ascent(i in 0..12){
		CreateArrowShot(obj,5,i*30,1.5,gr,15,true);}}
	w(90);
	ObjMove_SetDestAtWeight(obj,x3,y3,2,3);}

task TFairyA6(x1,y1,x2,y2,x3,y3,ang,turn){damage=1;
	let obj = SpawnEnemy_Fairy(x1,y1,"flower",700);
	ObjMove_SetDestAtWeight(obj,x2,y2,3,2);
	w(90);
	let x = ObjRender_GetX(obj);
	let y = ObjRender_GetY(obj);
	loop(120){
		if(Obj_IsDeleted(obj)){ break; }
		shot_se;
		let a = CreateShotA1(x,y,rand(3,4),ang+rand(-5,5),179,0);
		CreateShotA1(x,y,rand(3,4),ang+rand(-5,5),47,0);
			ObjMove_AddPatternA1(a,50,2,NO_CHANGE);
		ang+=5*turn;yield;}
	w(90);
	ObjMove_SetDestAtWeight(obj,x3,y3,3,2);}

task TFairyA7{
	let obj = SpawnEnemy_Fairy(192,-50,"flower",700);
	ObjMove_SetDestAtWeight(obj,192,50,3,2);
	w(90);
	let x = ObjRender_GetX(obj);
	let y = ObjRender_GetY(obj);
	if(!Obj_IsDeleted(obj)){
		shot_se; ascent(i in 0..15){ ascent(a in 0..5){
		CreateShotA1(x,y,1.5+a,i*24+6,823,30);}}}
	w(90);
	ObjMove_SetDestAtWeight(obj,192,-100,3,2);}
	
task TFairyA8{ let turn = 1;
	let obj = SpawnEnemy_Fairy(192,-50,"flower",3500);
	ObjMove_SetDestAtWeight(obj,192,192,3,2);
	w(120);
	let x = ObjRender_GetX(obj);
	let y = ObjRender_GetY(obj);
	loop(5){
	if(Obj_IsDeleted(obj)){break;}
		shot_se; ascent(i in 0..15){
		let shot = CreateShotA1(x,y,1,i*24,823,30);
		if(turn >= 3){turn = 1;}
		if(turn == 1){
			ObjMove_AddPatternA3(shot,0,NO_CHANGE,NO_CHANGE,0,0.6,0,NO_CHANGE);
			ObjMove_AddPatternA3(shot,120,NO_CHANGE,NO_CHANGE,0,0.3,0,NO_CHANGE);}
		if(turn == 2){
			ObjMove_AddPatternA3(shot,0,NO_CHANGE,NO_CHANGE,0,-0.6,0,NO_CHANGE);
			ObjMove_AddPatternA3(shot,120,NO_CHANGE,NO_CHANGE,0,-0.3,0,NO_CHANGE);}}
		turn+=1;
		w(120);}
	w(90);
	ObjMove_SetDestAtWeight(obj,192,-100,3,2);}

task TFairyA9(x1,y1,x2,y2){ let count = 0;
	let obj = SpawnEnemy_Fairy(x1,y1,"blue",50);
	ObjMove_SetDestAtWeight(obj,x2,y2,3,4);
	while(!Obj_IsDeleted(obj)){
	let x = ObjRender_GetX(obj);
	let y = ObjRender_GetY(obj);
		count=1;
		loop(5){
			if(Obj_IsDeleted(obj)){break;}
			ascent(an in 0..count){shot_se;
				let s = CreateShotA1(x,y,10,90+an*2-count,378,10);
				ObjMove_AddPatternA1(s,15,3,NO_CHANGE);}
			w(4);count+=1;}
		w(rand(45,90));}}

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 count = 0;
	let animFrame = 0;
	let animFrame2 = 0;
	let fairyX;
	let fairyY;
	let fairyDir;
	let fairySpeed;

	while(!Obj_IsDeleted(id)){
		ObjPrim_SetTexture(id,enemypath);
		ObjSprite2D_SetDestCenter(id);
		fairyX = ObjMove_GetX(id);
		fairyY = ObjMove_GetY(id);
		fairyDir = ObjMove_GetAngle(id);
		fairySpeed = ObjMove_GetSpeed(id);

	if(damage==1){
		ObjEnemy_SetIntersectionCircleToPlayer(id,fairyX,fairyY,16);
		ObjEnemy_SetIntersectionCircleToShot(id,fairyX,fairyY,16);}
	if(damage==0){yield;}

	if(ObjEnemy_GetInfo(id,INFO_LIFE) <= 0){shot_se_kill;
		if(color=="red"){TExplosionB(fairyX,fairyY,"RED");
			PowerS(fairyX,fairyY);}
		else if(color=="blue"){TExplosionB(fairyX,fairyY,"BLUE");}
		else if(color=="green"){TExplosionB(fairyX,fairyY,"GREEN");}
		else if(color=="yellow"){TExplosionB(fairyX,fairyY,"YELLOW");
			ascent(c in 0..10){Fruit(fairyX+40*cos(c*36),fairyY+40*sin(c*36));}}
		else if(color=="flower"){TExplosionB(fairyX,fairyY,"GREEN");
			ascent(c in 0..10){Fruit(fairyX+40*cos(c*36),fairyY+40*sin(c*36));}
			ascent(c in 0..30){Point(fairyX+60*cos(c*12),fairyY+60*sin(c*12));}}
		Obj_Delete(id);break;}

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

		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;}}

task EndMidbossItems{
	LIFEUP(192,120);
	ascent(i in 0..10){Fruit(192+40*cos(i*36),120+40*sin(i*36));}
	ascent(i in 0..18){Fruit(192+60*cos(i*20),120+60*sin(i*20));}
	ascent(i in 0..25){Fruit(192+80*cos(i*14.4),120+80*sin(i*14.4));}}

function PowerS(x,y){
	let obj = CreateItemA2(ITEM_POWER_S,x,y,x,y-32,100);
	itemHandler(obj,1,0);
	return obj;}
function PowerB(x,y){
	let obj = CreateItemA2(ITEM_POWER,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,100);
	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 Fruit(x,y){ 
	let obj = CreateItemU2(8,x,y,x,y-32,200);
	itemHandler(obj,1,0);
	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 < 720) { itemDir+=40; } 
		CollectItemsInCircle(GetPlayerX,GetPlayerY,64); 
		
		if(ObjMove_GetX(obj) < -4 || ObjMove_GetX(obj) > 388 || ObjMove_GetY(obj) > GetStgFrameHeight+4){ 
			break;}
		yield;}
	Obj_Delete(obj);}