let GCSD = GetCurrentScriptDirectory();

function CreateYuugiRing(x,y, an, lf){
	PlaySound("ring",92,0);
	let sht = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(sht);
	ObjMove_SetPosition(sht,x,y);
	ObjEnemy_SetLife(sht,lf);
	SetBox(sht);
	PDelete( sht );
	MakeRing(sht,an,lf);
	MakeRing2(sht,an,lf);
	Delete(sht);
	return sht;
}
task SetBox(obj){
	wait( 300 );
	while(!Obj_IsDeleted(obj)){
		ObjEnemy_SetIntersectionCircleToShot(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),18); 
		//ObjEnemy_SetIntersectionCircleToPlayer(obj,ObjMove_GetX(obj),ObjMove_GetY(obj),26);
		yield;
	}
}
task MakeRing(obj,ang,mxhp){
	let ring = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(ring,PRIMITIVE_TRIANGLESTRIP);
	Obj_SetRenderPriorityI(ring,50);
	ObjPrim_SetTexture(ring,GetCurrentScriptDirectory()~"img/stg3enm3.png");
	ObjSprite2D_SetDestRect(ring,0,0,GetStgFrameWidth(),GetStgFrameHeight());
	let t=0;
	QDelete(obj, ring);
	while(!Obj_IsDeleted(obj)){
		let hp = ObjEnemy_GetInfo(obj,INFO_LIFE);		
		ObjSprite2D_SetDestCenter(ring);
		let vc = 33;
		let tpos;
		let dest;
		let cout = vc*(mxhp/hp*2);
		ObjPrim_SetVertexCount(ring,vc);
		ascent(i in 0..vc){
			if(i%2==1){tpos=70;dest=0;}
			else{tpos=104;dest=33;}
			ObjPrim_SetVertexPosition(ring,i,ObjMove_GetX(obj)+tpos*cos(ang-3+i*384/cout),ObjMove_GetY(obj)+tpos*sin(ang-3+i*384/cout),1);
			ObjPrim_SetVertexUVT(ring,i,dest,(512/(vc)*i)+t*11);
		}
		t++;
		yield;
	}	
}

task MakeRing2(obj,ang,mxhp){
	let ring = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	ObjPrim_SetPrimitiveType(ring,PRIMITIVE_TRIANGLESTRIP);
	Obj_SetRenderPriorityI(ring,50);
	ObjPrim_SetTexture(ring,GetCurrentScriptDirectory()~"img/stg3enm3.png");	
	ObjSprite2D_SetDestRect(ring,0,0,GetStgFrameWidth(),GetStgFrameHeight());
	let t=0;
	QDelete(obj, ring);
	while(!Obj_IsDeleted(obj)){
		let hp = ObjEnemy_GetInfo(obj,INFO_LIFE);		
		ObjSprite2D_SetDestCenter(ring);
		let vc = 33;
		let tpos;
		let dest;
		let cout = vc*(mxhp/hp*2);
		ObjPrim_SetVertexCount(ring,vc);
		ascent(i in 0..vc){
			if(i%2==1){tpos=70;dest=0;}
			else{tpos=104;dest=33;}
			ObjPrim_SetVertexPosition(ring,i,ObjMove_GetX(obj)+tpos*cos(ang+3-i*384/cout),ObjMove_GetY(obj)+tpos*sin(ang+3-i*384/cout),1);
			ObjPrim_SetVertexUVT(ring,i,dest,(512/(vc)*i)+t*11);
		}
		t++;
		yield;
	}	
}

task Delete(obj){
	while(ObjEnemy_GetInfo(obj,INFO_LIFE)>0){yield;}
	Obj_Delete(obj);
}

task QDelete(objt, obj){
	while(!Obj_IsDeleted( objt )){yield;}
	Obj_Delete(obj);
}


function Fairy( type, life, shtdmgrate, spldmgrate ){
	let enemy = ObjEnemy_Create( OBJ_ENEMY );
	ObjEnemy_Regist( enemy );
	ObjEnemy_SetLife( enemy, life );
	ObjEnemy_SetDamageRate( enemy, shtdmgrate, spldmgrate );
	hitbox( enemy, 15, 20 );
	Death( enemy );
	//PDelete( enemy );
	IMAGE( enemy, type );
	DeathSpecial( enemy );
	return enemy;
	}

function YingYang( life, shtdmgrate, spldmgrate ){
	let enemy = ObjEnemy_Create( OBJ_ENEMY );
	ObjEnemy_Regist( enemy );
	ObjEnemy_SetLife( enemy, life );
	ObjEnemy_SetDamageRate( enemy, shtdmgrate, spldmgrate );
	hitbox( enemy, 15, 20 );
	Death( enemy );
	//PDelete( enemy );
	IMAGE4( enemy );
	IMAGE2( enemy );
	IMAGE3( enemy );
	IMAGE1( enemy );
	DeathSpecial( enemy );
	return enemy;
	}

function Fairynhb( type, life, shtdmgrate, spldmgrate, htbxpl ){
	let enemy = ObjEnemy_Create( OBJ_ENEMY );
	ObjEnemy_Regist( enemy );
	ObjEnemy_SetLife( enemy, life );
	ObjEnemy_SetDamageRate( enemy, shtdmgrate, spldmgrate );
	hitbox( enemy, htbxpl, 20 );
	Death( enemy );
	PDelete( enemy );
	IMAGE( enemy, type );
	DeathSpecial( enemy );
	return enemy;
	}

task PDelete( obj ){
   while( ObjMove_GetX(obj)>-64 && ObjMove_GetX(obj)<GetStgFrameWidth+64 && ObjMove_GetY(obj)>-64 && ObjMove_GetY(obj)<GetStgFrameHeight+64){yield;}
   Obj_Delete( obj );
}

task Death( obj ){
	while( ObjEnemy_GetInfo( obj, INFO_LIFE ) > 0 ){ yield; }
	if( ObjMove_GetX(obj)>-64 && ObjMove_GetX(obj)<GetStgFrameWidth+64 && ObjMove_GetY(obj)>-64 && ObjMove_GetY(obj)<GetStgFrameHeight+64 ){
		FamExplode(ObjMove_GetX(obj),ObjMove_GetY(obj),0.1,"WHITE");	
		PlaySound("enemy_death",92,0);
		Obj_Delete( obj );
		}
	if( ObjMove_GetX(obj)<=-64 && ObjMove_GetX(obj)>=GetStgFrameWidth+64 && ObjMove_GetY(obj)<=-64 && ObjMove_GetY(obj)>=GetStgFrameHeight+64 ){
		Obj_Delete( obj );
		}
		}

task DeathSpecial( obj ){
	while( GetCommonData( "IsMidboss", 2 ) == 2 ){ yield; }
		FamExplode(ObjMove_GetX(obj),ObjMove_GetY(obj),0.1,"WHITE");	
		PlaySound("enemy_death",92,0);
		Obj_Delete( obj );
}

task FamExplode(px,py,speed,c){
	let color = GetColor(c);
	let st = rand(0,30);
	TExpan(px,py,4,30,color[0],color[1],color[2]);
}
		

task hitbox( obj, plcollsize, shtcollsize ){
while( !Obj_IsDeleted( obj )){
	ObjEnemy_SetIntersectionCircleToPlayer( obj, ObjMove_GetX( obj ), ObjMove_GetY( obj ), plcollsize );
	ObjEnemy_SetIntersectionCircleToShot( obj, ObjMove_GetX( obj ), ObjMove_GetY( obj ), shtcollsize );
	yield;
	}
}

let blind = GCSD~"img/enemy.png";

task IMAGE( objt, type ){ 
	yield;
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,30);
	ObjPrim_SetTexture(obj,blind);
	SetAnimation1( obj, type );
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	GetP( objt, obj );
	DDD( objt, obj );
}
task IMAGE1( objt ){ 
	yield;
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,30);
	ObjPrim_SetTexture(obj,blind);
	ObjSprite2D_SetSourceRect(obj,32*7,256,32*8,256+32);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	GetP( objt, obj );
	DDD( objt, obj );
}
task IMAGE2( objt ){ 
	yield;
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,30);
	ObjPrim_SetTexture(obj,blind);
	ObjSprite2D_SetSourceRect(obj,32*7,256+32,32*8,256+64);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1.05,1.05,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	spin( objt, obj );
	GetP( objt, obj );
	DDD( objt, obj );
}

task IMAGE3( objt ){ 
	yield;
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,30);
	ObjPrim_SetTexture(obj,blind);
	ObjSprite2D_SetSourceRect(obj,32*7,256+32,32*8,256+64);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1.45,1.45,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	spin2( objt, obj );
	GetP( objt, obj );
	DDD( objt, obj );
}

task IMAGE4( objt ){ 
	yield;
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,30);
	ObjPrim_SetTexture(obj,blind);
	ObjSprite2D_SetSourceRect(obj,32*3,256+32,32*4,256+64);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1.5,1.5,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	spin3( objt, obj );
	GetP( objt, obj );
	DDD( objt, obj );
}

task spin( objt, obj ){
let a = 0;
while( !Obj_IsDeleted( objt )){
ObjRender_SetAngleZ( obj, a );
a += 12;
yield;
}
}
task spin2( objt, obj ){
let a = 0;
while( !Obj_IsDeleted( objt )){
ObjRender_SetAngleZ( obj, a );
a -= 5;
yield;
}
}
task spin3( objt, obj ){
let a = 0;
while( !Obj_IsDeleted( objt )){
ObjRender_SetAngleZ( obj, a );
a += 2;
yield;
}
}

	task SetAnimation1( obj, type ){
	if( type == 1 ){
	while( !Obj_IsDeleted( obj )){ 
	ObjSprite2D_SetSourceRect(obj,320 + 48*0,0,320 + 48*1,48);
	wait( 5 );
	ObjSprite2D_SetSourceRect(obj,320 + 48*1,0,320 + 48*2,48);
	wait( 5 );
	ObjSprite2D_SetSourceRect(obj,320 + 48*2,0,320 + 48*3,48);
	wait( 5 );
	ObjSprite2D_SetSourceRect(obj,320 + 48*3,0,320 + 48*4,48);
	wait( 5 );
	}
	}
	if( type == 2 ){
	while( !Obj_IsDeleted( obj )){ 
	ObjSprite2D_SetSourceRect(obj,0,            448,0 + 64,    448 + 64);
	wait( 5 );
	ObjSprite2D_SetSourceRect(obj,0 + 64*1,448,0 + 64*2,448 + 64);
	wait( 5 );
	ObjSprite2D_SetSourceRect(obj,0 + 64*2,448,0 + 64*3,448 + 64);
	wait( 5 );
	ObjSprite2D_SetSourceRect(obj,0 + 64*3,448,0 + 64*4,448 + 64);
	wait( 5 );
	}
	}
	if( type == 3 ){
	while( !Obj_IsDeleted( obj )){ 
	ObjSprite2D_SetSourceRect(obj,0 + 32*8,320+32,32*9,352+32);
	wait( 5 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*9,320+32,32*10,352+32);
	wait( 5 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*10,320+32,32*11,352+32);
	wait( 5 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*11,320+32,32*12,352+32);
	wait( 5 );
	}
	}
	if( type == 4 ){
	ObjRender_SetAngleY(obj,180);
	while( !Obj_IsDeleted( obj )){ 
	ObjSprite2D_SetSourceRect(obj,0 + 32*8,320+32,32*9,352+32);
	wait( 5 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*9,320+32,32*10,352+32);
	wait( 5 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*10,320+32,32*11,352+32);
	wait( 5 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*11,320+32,32*12,352+32);
	wait( 5 );
	}
	}
	if( type == 5 ){
	ObjRender_SetAngleY(obj,180);

	ObjSprite2D_SetSourceRect(obj,0 + 32*8,320,32*9,352);
	wait( 12 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*9,320,32*10,352);
	wait( 12 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*10,320,32*11,352);
	wait( 12 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*11,320,32*12,352);
	wait( 12 );

	ObjSprite2D_SetSourceRect(obj,0 + 32*7,320,32*8,352);
	wait( 3 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*6,320,32*7,352);
	wait( 3 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*5,320,32*6,352);
	wait( 3 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*4,320,32*5,352);
	wait( 3 );

	ObjRender_SetAngleY(obj,0);

	ObjSprite2D_SetSourceRect(obj,0 + 32*4,320,32*5,352);
	wait( 3 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*5,320,32*6,352);
	wait( 3 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*6,320,32*7,352);
	wait( 3 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*7,320,32*8,352);
	wait( 3 );

	ObjSprite2D_SetSourceRect(obj,0 + 32*8,320,32*9,352);
	wait( 12 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*9,320,32*10,352);
	wait( 12 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*10,320,32*11,352);
	wait( 12 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*11,320,32*12,352);
	wait( 12 );
	}

	if( type == 6 ){
	ObjRender_SetAngleY(obj,0);

	ObjSprite2D_SetSourceRect(obj,0 + 32*8,320,32*9,352);
	wait( 12 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*9,320,32*10,352);
	wait( 12 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*10,320,32*11,352);
	wait( 12 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*11,320,32*12,352);
	wait( 12 );

	ObjSprite2D_SetSourceRect(obj,0 + 32*7,320,32*8,352);
	wait( 3 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*6,320,32*7,352);
	wait( 3 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*5,320,32*6,352);
	wait( 3 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*4,320,32*5,352);
	wait( 3 );

	ObjRender_SetAngleY(obj,180);


	ObjSprite2D_SetSourceRect(obj,0 + 32*4,320,32*5,352);
	wait( 3 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*5,320,32*6,352);
	wait( 3 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*6,320,32*7,352);
	wait( 3 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*7,320,32*8,352);
	wait( 3 );

	ObjSprite2D_SetSourceRect(obj,0 + 32*8,320,32*9,352);
	wait( 12 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*9,320,32*10,352);
	wait( 12 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*10,320,32*11,352);
	wait( 12 );
	ObjSprite2D_SetSourceRect(obj,0 + 32*11,320,32*12,352);
	wait( 12 );
	}
	}

	task GetP( objt, obj ){ 
	while( !Obj_IsDeleted( objt )){
	ObjRender_SetPosition( obj, ObjMove_GetX( objt ), ObjMove_GetY( objt ), 0);
	yield;
	}
	}

	task DDD( objt, obj ){
	while( !Obj_IsDeleted(objt)){yield;}
	Obj_Delete(obj);
	}

function Yuugi( life, shtdmgrate, spldmgrate ){
	let enemy = ObjEnemy_Create( OBJ_ENEMY );
	ObjEnemy_Regist( enemy );
	ObjEnemy_SetLife( enemy, life );
	ObjEnemy_SetDamageRate( enemy, shtdmgrate, spldmgrate );
	hitbox( enemy, 15, 20 );
	Death( enemy );
	PDelete( enemy );
	IMAGEX( enemy );
	return enemy;
	}

let yuugi = GCSD~"img/yuugidot.png";

function IMAGEX( objt ){ 
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,30);
	ObjPrim_SetTexture(obj,yuugi);
	ObjSprite2D_SetSourceRect(obj,256/4*2,256/3*2,256/4*3,256/3*3);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	GetP( objt, obj );
	DDD( objt, obj );
	return obj;
}

function Yuugi2( life, shtdmgrate, spldmgrate ){
	let enemy = ObjEnemy_Create( OBJ_ENEMY );
	ObjEnemy_Regist( enemy );
	ObjEnemy_SetLife( enemy, life );
	ObjEnemy_SetDamageRate( enemy, shtdmgrate, spldmgrate );
	hitbox( enemy, 15, 20 );
	Death( enemy );
	PDelete( enemy );
	IMAGEX2( enemy );
	return enemy;
	}

function IMAGEX2( objt ){ 
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,30);
	ObjPrim_SetTexture(obj,yuugi);
	ObjRender_SetAngleY(obj,180); 
	ObjSprite2D_SetSourceRect(obj,256/4*2,256/3*2,256/4*3,256/3*3);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	GetP( objt, obj );
	DDD( objt, obj );
	return obj;
}

	task YuugiRight{
              let enm = Yuugi( 10000, 0, 0 );
              ObjMove_SetPosition( enm, -60, GetStgFrameHeight/2 + 30 );
              ObjMove_SetDestAtWeight( enm, GetStgFrameWidth + 60, GetStgFrameHeight/2 - 30, 1, 6 );
              FUYUGI( enm );
	}

	task YuugiLeft{
              let enm = Yuugi2( 10000, 0, 0 );
              ObjMove_SetPosition( enm, GetStgFrameWidth + 60, GetStgFrameHeight/2 + 30 );
              ObjMove_SetDestAtWeight( enm, -60, GetStgFrameHeight/2 - 30, 1, 6 );
              FUYUGI( enm );
	}


              task FUYUGI( obj ){ 
              wait( 25 );
              loop( 1 ){
	                                	let way = 1;
			loop( way ){

              			let sx = ObjMove_GetX( obj );
              			let sy = ObjMove_GetY( obj );
			if( Obj_IsDeleted( obj )){ break; }
				
				let sht1 = CreateYuugiRing( sx, sy, 90, 1000 );
				ObjMove_AddPatternA2( sht1, 0, 2, 270, -0.02, 0, -2.5 );
				Translate( sht1 );
			
			}
			wait( 35 );
	}

   }

	task Translate( obj ){
	let x;
	let y;
	while( !Obj_IsDeleted( obj )){ 
	x = ObjMove_GetX( obj );
	y = ObjMove_GetY( obj ) + 80;
	yield; }
              	let speed = 0;
	let angle = rand( 0, 360 );
       	loop( 1 ){

			if( y > GetStgFrameHeight ){ break; }
	                                	let way = 1;
                                                	let shote = 824;
			let delay = 20;
			loop( way ){

              			let sx = x;
              			let sy = y;
				
				let sht1 = TShotA2( sx, sy, 0, angle, 0, 0, shote, delay );
				ChangeAngle( sht1 );
				angle += 360 / way;
			
			}
			PlaySound("Enep1",92,0);
	}

   }

	task ChangeAngle( obj ){
	wait( 300 );
	ObjMove_AddPatternA2( obj, 0, 0, GetAngleToPlayer( obj ), 0.01, 0, 1 );
	}
	

	task Fairy0{
	wait( 60 );
              wait( 120 );
              let y = 40;
              let x1 = GetStgFrameWidth - 40;
              let x2 = 40;
              loop( 6 ){
              let enm1 = Fairynhb( 4, 100, 100, 100, 0 );
              let enm2 = Fairynhb( 3, 100, 100, 100, 0 );
              ObjMove_SetPosition( enm1, GetStgFrameWidth - 30, GetStgFrameHeight + 20 );
              ObjMove_SetPosition( enm2, 30, GetStgFrameHeight + 20 );
              ObjMove_SetDestAtWeight( enm1, x1, y, 10, 7 );
              ObjMove_SetDestAtWeight( enm2, x2, y, 10, 7 );
              ObjMove_AddPatternA2( enm1, 200, 0, 160, 0.01, 0, 2 );
              ObjMove_AddPatternA2( enm2, 200, 0, 20, 0.01, 0, 2 );
              x1 -= 6;
              x2 += 6;
              y += 5;
	F0( enm1 );
	F0( enm2 );
              
              wait( 18 );
	}
	}

              task F0( obj ){ 
              wait( 130 );
              loop( 10 ){
              if( Obj_IsDeleted( obj )){ break; }
              let angle = GetAngleToPlayer( obj );
              let sx = ObjMove_GetX( obj );
              let sy = ObjMove_GetY( obj );
 	loop( 5 ){
              			let speed = 8;
	                                	let way = 1;
                                                	let shote = 276;
			let delay = 10;
			if( Obj_IsDeleted( obj )){ break; }

			loop( way ){
				
				let sht1 = TShotA2( sx, sy, 18, angle, -1, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, 18, angle + 20, -1, speed, shote, delay );
				let sht3 = TShotA2( sx, sy, 18, angle - 20, -1, speed, shote, delay );

				angle += 360 / way;
			
			}
			if( Obj_IsDeleted( obj )){ break; }
			PlaySound("LenenShot1",92,0);
			wait( 6 );
			}
			if( Obj_IsDeleted( obj )){ break; }
			wait( 60 );
	}

   }
	task Fairy1{
              let enm0 = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm0, GetStgFrameWidth/2, -60 );
              ObjMove_AddPatternA2( enm0, 0, 1, 90, 0, 0, 1 );
              F1( enm0 );

              wait( 220 );

              let enm1 = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm1, GetStgFrameWidth/4, -60 );
              ObjMove_AddPatternA2( enm1, 0, 1, 90, 0, 0, 1 );
              F1( enm1 );
              let enm2 = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm2, GetStgFrameWidth/4*3, -60 );
              ObjMove_AddPatternA2( enm2, 0, 1, 90, 0, 0, 1 );
              F1( enm2 );

              wait( 220 );

              let enm3 = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm3, GetStgFrameWidth/4 + 50, -60 );
              ObjMove_AddPatternA2( enm3, 0, 1, 90, 0, 0, 1 );
              F1( enm3 );
              let enm4 = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm4, GetStgFrameWidth/4*3 - 50, -60 );
              ObjMove_AddPatternA2( enm4, 0, 1, 90, 0, 0, 1 );
              F1( enm4 );

              wait( 220 );

              let enm5 = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm5, GetStgFrameWidth/4 - 50, -60 );
              ObjMove_AddPatternA2( enm5, 0, 1, 90, 0, 0, 1 );
              F1( enm5 );
              let enm6 = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm6, GetStgFrameWidth/4*3 + 50, -60 );
              ObjMove_AddPatternA2( enm6, 0, 1, 90, 0, 0, 1 );
              F1( enm6 );

              wait( 220 );

              let enm7 = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm7, GetStgFrameWidth/4 - 40, -60 );
              ObjMove_AddPatternA2( enm7, 0, 1, 90, 0, 0, 1 );
              F1( enm7 );
              let enm8 = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm8, GetStgFrameWidth/4*3 + 40, -60 );
              ObjMove_AddPatternA2( enm8, 0, 1, 90, 0, 0, 1 );
              F1( enm8 );

              wait( 220 );

              let enm9 = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm9, GetStgFrameWidth/4 - 30, -60 );
              ObjMove_AddPatternA2( enm9, 0, 1, 90, 0, 0, 1 );
              F1( enm9 );
              let enm10 = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm10, GetStgFrameWidth/4*3 + 30, -60 );
              ObjMove_AddPatternA2( enm10, 0, 1, 90, 0, 0, 1 );
              F1( enm10 );
	}


              task F1( obj ){ 
              wait( 60 );
              let angle = rand( 0, 360 );
              loop( 3 ){
              if( Obj_IsDeleted( obj )){ break; }
              let r = 0;
 	loop( 4 ){
              			let speed = 1.6;
	                                	let way = 40;
                                                	let shote = 55;
			let delay = 10;
			loop( way ){
              			let sx = ObjMove_GetX( obj ) + r*cos( angle );
              			let sy = ObjMove_GetY( obj ) + r*sin( angle );
			if( Obj_IsDeleted( obj )){ break; }
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );

				angle += 360 / way;
			
			}
			r+= 10;
			}
			PlaySound("LenenShot1",92,0);
			if( Obj_IsDeleted( obj )){ break; }
			wait( 120 );
	}

   }

	task Fairy2{
              let enm = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm, GetStgFrameWidth/2, -60 );
              ObjMove_SetDestAtWeight( enm, GetStgFrameWidth/2, GetStgFrameHeight/2 - 120, 10, 3 );
              ObjMove_AddPatternA2( enm, 360, 0, 270, 0.05, 0, 5 );
              DelayDelete( enm, 400 );
              F2( enm );
	}


              task F2( obj ){ 
              wait( 100 );
              let a = 0;
	while( !Obj_IsDeleted( obj )){
              loop( 20 ){
              let speed = 10;
 	loop( 6 ){
              			let angle1 = GetAngleToPlayer( obj ) + a;
              			let angle2 = GetAngleToPlayer( obj ) - a;
	                                	let way = 1;
                                                	let shote = 71;
			let delay = 10;
			if( Obj_IsDeleted( obj )){ break; }

			loop( way ){

              			let sx = ObjMove_GetX( obj );
              			let sy = ObjMove_GetY( obj );
			if( Obj_IsDeleted( obj )){ break; }
				
				let sht1 = TShotA2( sx, sy, speed, angle1, -0.2, 0, shote, delay );
				let sht2 = TShotA2( sx, sy, speed, angle2, -0.2, 0, shote, delay );
				Change( sht1 );
				Change( sht2 );

				angle1 += 360 / way;
				angle2 += 360 / way;
			
			}
			speed -= 0.75;
			}
			a += 6;
			PlaySound("LenenShot1",92,0);
			if( Obj_IsDeleted( obj )){ break; }
			wait( 8 );
	}
              loop( 20 ){
	let speed = 10;
 	loop( 6 ){
              			let angle1 = GetAngleToPlayer( obj )  + a;
              			let angle2 = GetAngleToPlayer( obj )  - a;
	                                	let way = 1;
                                                	let shote = 71;
			let delay = 10;
			if( Obj_IsDeleted( obj )){ break; }

			loop( way ){

              			let sx = ObjMove_GetX( obj );
              			let sy = ObjMove_GetY( obj );
			if( Obj_IsDeleted( obj )){ break; }
				
				let sht1 = TShotA2( sx, sy, speed, angle1, -0.2, 0, shote, delay );
				let sht2 = TShotA2( sx, sy, speed, angle2, -0.2, 0, shote, delay );
				Change( sht1 );
				Change( sht2 );

				angle1 += 360 / way;
				angle2 += 360 / way;
			
			}
			speed -= 0.75;
			}
			a -= 6;
			PlaySound("LenenShot1",92,0);
			if( Obj_IsDeleted( obj )){ break; }
			wait( 8 );
	}
	}
   }

	task Change( obj ){
	while( ObjMove_GetSpeed( obj ) != 0 ){ yield; }
	wait( 10 );
	ObjMove_AddPatternA2( obj, 0, 3, GetAngleToPlayer( obj ), 0, 0, 3 );
	}

	task Fairy3{
	loop( 40 ){
              let enm = Fairy( 6, 10, 70, 70 );
              ObjMove_SetPosition( enm, -60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 0, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, -6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F3( enm, 8 );
	wait( 5 );
	}

	wait( 65 );

	loop( 40 ){
              let enm = Fairy( 5, 10, 70, 70 );
              ObjMove_SetPosition( enm, GetStgFrameWidth+60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 180, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, 6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F3( enm, -8 );
	wait( 5 );
	}

	wait( 65 );

	loop( 40 ){
              let enm = Fairy( 6, 10, 70, 70 );
              ObjMove_SetPosition( enm, -60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 0, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, -6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F3( enm, 8 );
	wait( 5 );
	}

	wait( 65 );

	loop( 40 ){
              let enm = Fairy( 5, 10, 70, 70 );
              ObjMove_SetPosition( enm, GetStgFrameWidth+60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 180, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, 6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F3( enm, -8 );
	wait( 5 );
	}

	wait( 65 );
	finale1;
	finale2;
	
	}

	task finale1{
	loop( 40 ){
              let enm = Fairy( 6, 10, 70, 70 );
              ObjMove_SetPosition( enm, -60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 0, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, -6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F3( enm, 8 );
	wait( 5 );
	}
	}

	task finale2{
	loop( 40 ){
              let enm = Fairy( 5, 10, 70, 70 );
              ObjMove_SetPosition( enm, GetStgFrameWidth+60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 180, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, 6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F3( enm, -8 );
	wait( 5 );
	}
	}


              task F3( obj, plus ){ 
              wait( 10 );
              let a = rand( 0, 360 );
              loop( 6 ){

			if( Obj_IsDeleted( obj )){ break; }
			let speed = 8;
              			let angle = GetAngleToPlayer( obj );
	                                	let way = 1;
                                                	let shote = 55;
			let delay = 10;

			loop( way ){

              			let sx = ObjMove_GetX( obj );
              			let sy = ObjMove_GetY( obj );
			if( Obj_IsDeleted( obj )){ break; }
				
				let sht1 = TShotA2( sx, sy, speed, angle, -0.16, 0, shote, delay );
				Change2( sht1, a );

				angle += 360 / way;
			
			}
			if( Obj_IsDeleted( obj )){ break; }
			a += plus;
			PlaySound("LenenShot1",92,0);
			wait( 6 );
	}
  
   }

	task Change2( obj, angle ){
	while( ObjMove_GetSpeed( obj ) != 0 ){ yield; }
	wait( 10 );
	ObjMove_AddPatternA2( obj, 0, 1, angle, 0, 0, 1 );
	}


	task Fairy4{
              let y = 178;
              let enm = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm, GetStgFrameWidth/2, -60 );
              ObjMove_SetDestAtWeight( enm, GetStgFrameWidth/2, GetStgFrameHeight/2 - 120, 10, 5 );
              ObjMove_AddPatternA2( enm, 350, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm, 420 );
              F4( enm );

	wait( y );

              let enm2 = Fairy( 2, 250, 70, 70 );
              let x = GetStgFrameWidth/2 + rand( 120, 140 );
              ObjMove_SetPosition( enm2, x, -60 );
              ObjMove_SetDestAtWeight( enm2, x, GetStgFrameHeight/2 - 120, 10, 5 );
              ObjMove_AddPatternA2( enm2, 350, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm2, 420 );
              F4( enm2 );

	wait( y );

              let enm3 = Fairy( 2, 250, 70, 70 );
              let x1 = GetStgFrameWidth/2 + rand( 50, 70 );
              ObjMove_SetPosition( enm3, x1, -60 );
              ObjMove_SetDestAtWeight( enm3, x1, GetStgFrameHeight/2 - 120, 10, 5 );
              ObjMove_AddPatternA2( enm3, 350, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm3, 420 );
              F4( enm3 );

	wait( y );

              let enm4 = Fairy( 2, 250, 70, 70 );
              let x2 = GetStgFrameWidth/2 - rand( 50, 70 );
              ObjMove_SetPosition( enm4, x2, -60 );
              ObjMove_SetDestAtWeight( enm4, x2, GetStgFrameHeight/2 - 120, 10, 5 );
              ObjMove_AddPatternA2( enm4, 350, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm4, 420 );
              F4( enm4 );

	wait( y );

              let enm5 = Fairy( 2, 250, 70, 70 );
              let x3 = GetStgFrameWidth/2 - rand( 120, 140 );
              ObjMove_SetPosition( enm5, x3, -60 );
              ObjMove_SetDestAtWeight( enm5, x3, GetStgFrameHeight/2 - 120, 10, 5 );
              ObjMove_AddPatternA2( enm5, 350, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm5, 420 );
              F4( enm5 );

	wait( y );

              let enm6 = Fairy( 2, 250, 70, 70 );
              let x4 = GetStgFrameWidth/2 - rand( 20, 40 );
              ObjMove_SetPosition( enm6, x4, -60 );
              ObjMove_SetDestAtWeight( enm6, x4, GetStgFrameHeight/2 - 120, 10, 5 );
              ObjMove_AddPatternA2( enm6, 350, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm6, 420 );
              F4( enm6 );

	wait( y );

              let enm7 = Fairy( 2, 250, 70, 70 );
              let x5 = GetStgFrameWidth/2 + rand( 80, 100 );
              ObjMove_SetPosition( enm7, x5, -60 );
              ObjMove_SetDestAtWeight( enm7, x5, GetStgFrameHeight/2 - 120, 10, 5 );
              ObjMove_AddPatternA2( enm7, 350, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm7, 420 );
              F4( enm7 );

	wait( y );

              let enm8 = Fairy( 2, 250, 70, 70 );
              let x6 = GetStgFrameWidth/2 + 50;
              ObjMove_SetPosition( enm8, x6, -60 );
              ObjMove_SetDestAtWeight( enm8, x6, GetStgFrameHeight/2 - 120, 10, 5 );
              ObjMove_AddPatternA2( enm8, 350, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm8, 420 );
              F4( enm8 );
              let enm9 = Fairy( 2, 250, 70, 70 );
              let x7 = GetStgFrameWidth/2 - 50;
              ObjMove_SetPosition( enm9, x7, -60 );
              ObjMove_SetDestAtWeight( enm9, x7, GetStgFrameHeight/2 - 120, 10, 5 );
              ObjMove_AddPatternA2( enm9, 350, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm9, 420 );
              F4( enm9 );
	}


              task F4( obj ){ 
              wait( 10 );
              let a = 190;
              while( !Obj_IsDeleted( obj )){

			if( Obj_IsDeleted( obj )){ break; }
			let speed = 8;
              			let angle1 = 90;
              			let angle2 = 90;
	                                	let way = 10;
                                                	let shote = 71;
			let delay = 10;
			if( a < 40 ){ a += 2; }

			loop( way ){

              			let sx = ObjMove_GetX( obj );
              			let sy = ObjMove_GetY( obj );
			if( Obj_IsDeleted( obj )){ break; }
				
				let sht1 = TShotA2( sx, sy, speed, angle1, 0, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, speed, angle2, 0, speed, shote, delay );

				angle1 += a / way;
				angle2 -= a / way;
			
			}
			if( Obj_IsDeleted( obj )){ break; }
			a -= 2;
			PlaySound("LenenShot1",92,0);
			wait( 4 );
	}
   }

	task Fairy5{
	loop( 40 ){
              let enm = Fairy( 6, 10, 70, 70 );
              ObjMove_SetPosition( enm, -60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 0, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, -6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F5( enm, 8 );
	wait( 5 );
	}

	wait( 20 );

	loop( 40 ){
              let enm = Fairy( 5, 10, 70, 70 );
              ObjMove_SetPosition( enm, GetStgFrameWidth+60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 180, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, 6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F5( enm, -8 );
	wait( 5 );
	}

	wait( 20 );

	loop( 40 ){
              let enm = Fairy( 6, 10, 70, 70 );
              ObjMove_SetPosition( enm, -60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 0, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, -6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F5( enm, 8 );
	wait( 5 );
	}

	wait( 20 );

	loop( 40 ){
              let enm = Fairy( 5, 10, 70, 70 );
              ObjMove_SetPosition( enm, GetStgFrameWidth+60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 180, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, 6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F5( enm, -8 );
	wait( 5 );
	}

	wait( 20 );

	loop( 40 ){
              let enm = Fairy( 6, 10, 70, 70 );
              ObjMove_SetPosition( enm, -60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 0, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, -6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F5( enm, 8 );
	wait( 5 );
	}

	wait( 20 );

	loop( 40 ){
              let enm = Fairy( 5, 10, 70, 70 );
              ObjMove_SetPosition( enm, GetStgFrameWidth+60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 180, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, 6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F5( enm, -8 );
	wait( 5 );
	}
	
	}

              task F5( obj, plus ){ 
              wait( 10 );
              loop( 6 ){

			if( Obj_IsDeleted( obj )){ break; }
			let speed = 8;
              			let angle = GetAngleToPlayer( obj );
	                                	let way = 1;
                                                	let shote = 55;
			let delay = 10;

			loop( way ){

              			let sx = ObjMove_GetX( obj );
              			let sy = ObjMove_GetY( obj );
			if( Obj_IsDeleted( obj )){ break; }
				
				let sht1 = TShotA2( sx, sy, speed, angle, -0.16, 0, shote, delay );
				Change3( sht1 );

				angle += 360 / way;
			
			}
			if( Obj_IsDeleted( obj )){ break; }
			PlaySound("LenenShot1",92,0);
			wait( 6 );
	}
  
   }

	task Change3( obj ){
	while( ObjMove_GetSpeed( obj ) != 0 ){ yield; }
	wait( 10 );
	ObjMove_AddPatternA2( obj, 0, 3, GetAngleToPlayer( obj ), 0, 0, 3 );
	}

	task Fairy6{
              wait( 70 );
              let y = 140;
              let enm = YingYang( 250, 70, 70 );
              ObjMove_SetPosition( enm, GetStgFrameWidth/2, -60 );
              ObjMove_SetDestAtWeight( enm, GetStgFrameWidth/2, GetStgFrameHeight/2 - 115, 10, 5 );
              ObjMove_AddPatternA2( enm, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm, 300 );
              F6( enm );

	wait( y );

              let enm2 = YingYang( 250, 70, 70 );
              let x = GetStgFrameWidth/2 + rand( 120, 140 );
              ObjMove_SetPosition( enm2, x, -60 );
              ObjMove_SetDestAtWeight( enm2, x, GetStgFrameHeight/2 - 115, 10, 5 );
              ObjMove_AddPatternA2( enm2, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm2, 300 );
              F6( enm2 );

	wait( y );

              let enm3 = YingYang( 250, 70, 70 );
              let x1 = GetStgFrameWidth/2 + rand( 50, 70 );
              ObjMove_SetPosition( enm3, x1, -60 );
              ObjMove_SetDestAtWeight( enm3, x1, GetStgFrameHeight/2 - 115, 10, 5 );
              ObjMove_AddPatternA2( enm3, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm3, 300 );
              F6( enm3 );

	wait( y );

              let enm4 = YingYang( 250, 70, 70 );
              let x2 = GetStgFrameWidth/2 - rand( 50, 70 );
              ObjMove_SetPosition( enm4, x2, -60 );
              ObjMove_SetDestAtWeight( enm4, x2, GetStgFrameHeight/2 - 115, 10, 5 );
              ObjMove_AddPatternA2( enm4, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm4, 300 );
              F6( enm4 );

	wait( y );

              let enm5 = YingYang( 250, 70, 70 );
              let x3 = GetStgFrameWidth/2 - rand( 120, 140 );
              ObjMove_SetPosition( enm5, x3, -60 );
              ObjMove_SetDestAtWeight( enm5, x3, GetStgFrameHeight/2 - 115, 10, 5 );
              ObjMove_AddPatternA2( enm5, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm5, 300 );
              F6( enm5 );

	wait( y );

              let enm6 = YingYang( 250, 70, 70 );
              let x4 = GetStgFrameWidth/2 - rand( 20, 40 );
              ObjMove_SetPosition( enm6, x4, -60 );
              ObjMove_SetDestAtWeight( enm6, x4, GetStgFrameHeight/2 - 115, 10, 5 );
              ObjMove_AddPatternA2( enm6, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm6, 300 );
              F6( enm6 );

	wait( y );

              let enm7 = YingYang( 250, 70, 70 );
              let x5 = GetStgFrameWidth/2 + rand( 20, 40 );
              ObjMove_SetPosition( enm7, x5, -60 );
              ObjMove_SetDestAtWeight( enm7, x5, GetStgFrameHeight/2 - 115, 10, 5 );
              ObjMove_AddPatternA2( enm7, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm7, 300 );
              F6( enm7 );

	wait( y );

              let enm8 = YingYang( 250, 70, 70 );
              let x6 = GetStgFrameWidth/2 ;
              ObjMove_SetPosition( enm8, x6, -60 );
              ObjMove_SetDestAtWeight( enm8, x6, GetStgFrameHeight/2 - 115, 10, 5 );
              ObjMove_AddPatternA2( enm8, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm8, 300 );
              F6( enm8 );

	}

             task F6( obj ){ 
              wait( 40 );
              let angle = 0;
              let a = [ 9, -9 ];
              let b = a[ round( rand( 0, 1 ))];
              loop( 40 ){

			let speed = 10;
	                                	let way = 2;
                                                	let shote = 553;
			let delay = 10;

			loop( way ){

              			let sx = ObjMove_GetX( obj );
              			let sy = ObjMove_GetY( obj );
			if( Obj_IsDeleted( obj )){ break; }
				
				let sht0 = TShotA2( sx, sy, 0, 0, 0, 0, 704, 0 );
				let sht1 = CreateLooseLaserA1( sx, sy, speed, angle, 140, 15, shote, delay );
				DelayDelete( sht0, 120 );
				CheckDelete( obj, sht0 );
				ObjMove_AddPatternA2( sht1, 0, speed, angle, -0.2, 0, 0.8 );
				ObjMove_AddPatternA2( sht1, 90, 0.8, angle, 0.2, 0, 5 );

				let sht2 = TShotA2( sx, sy, 0.5, angle, 0.05, speed, 745, delay );
				ObjMove_AddPatternA2( sht2, 0, speed, angle, -0.2, 0, 0.8 );
				ObjMove_AddPatternA2( sht2, 90, 0.8, angle, 0.2, 0, 5 );

				angle += 360 / way;
			
			}
			angle += b;
			if( Obj_IsDeleted( obj )){ break; }
			PlaySound("LenenLaserShort",92,0);
			wait( 3 );
	}
  
   }

	task DelayDelete( obj, t ){
	wait( t );
	Obj_Delete( obj );
	}

	task CheckDelete( objt, obj ){
	while( !Obj_IsDeleted( objt )){ yield; }
	Obj_Delete( obj );
	}


	task Fairy7{
              let y = 140;
              let enm = Fairy( 2, 250, 70, 70 );
              ObjMove_SetPosition( enm, GetStgFrameWidth/2, -60 );
              ObjMove_SetDestAtWeight( enm, GetStgFrameWidth/2, GetStgFrameHeight/2 - 130, 10, 5 );
              ObjMove_AddPatternA2( enm, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm, 300 );
              F7( enm );

	wait( y );

              let enm2 = Fairy( 2, 250, 70, 70 );
              let x = GetStgFrameWidth/2 + rand( 120, 140 )+ rand( -30, 30 );
              ObjMove_SetPosition( enm2, x, -60 );
              ObjMove_SetDestAtWeight( enm2, x, GetStgFrameHeight/2 - 130, 10, 5 );
              ObjMove_AddPatternA2( enm2, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm2, 300 );
              F7( enm2 );

	wait( y );

              let enm3 = Fairy( 2, 250, 70, 70 );
              let x1 = GetStgFrameWidth/2 + rand( 50, 70 )+ rand( -30, 30 );
              ObjMove_SetPosition( enm3, x1, -60 );
              ObjMove_SetDestAtWeight( enm3, x1, GetStgFrameHeight/2 - 130, 10, 5 );
              ObjMove_AddPatternA2( enm3, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm3, 300 );
              F7( enm3 );

	wait( y );

              let enm4 = Fairy( 2, 250, 70, 70 );
              let x2 = GetStgFrameWidth/2 - rand( 50, 70 )+ rand( -30, 30 );
              ObjMove_SetPosition( enm4, x2, -60 );
              ObjMove_SetDestAtWeight( enm4, x2, GetStgFrameHeight/2 - 130, 10, 5 );
              ObjMove_AddPatternA2( enm4, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm4, 300 );
              F7( enm4 );

	wait( y );

              let enm5 = Fairy( 2, 250, 70, 70 );
              let x3 = GetStgFrameWidth/2 - rand( 120, 140 )+ rand( -30, 30 );
              ObjMove_SetPosition( enm5, x3, -60 );
              ObjMove_SetDestAtWeight( enm5, x3, GetStgFrameHeight/2 - 130, 10, 5 );
              ObjMove_AddPatternA2( enm5, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm5, 300 );
              F7( enm5 );

	wait( y );

              let enm6 = Fairy( 2, 250, 70, 70 );
              let x4 = GetStgFrameWidth/2 - rand( 20, 40 )+ rand( -30, 30 );
              ObjMove_SetPosition( enm6, x4, -60 );
              ObjMove_SetDestAtWeight( enm6, x4, GetStgFrameHeight/2 - 130, 10, 5 );
              ObjMove_AddPatternA2( enm6, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm6, 300 );
              F7( enm6 );

	wait( y );

              let enm7 = Fairy( 2, 250, 70, 70 );
              let x5 = GetStgFrameWidth/2 + rand( 80, 100 )+ rand( -30, 30 );
              ObjMove_SetPosition( enm7, x5, -60 );
              ObjMove_SetDestAtWeight( enm7, x5, GetStgFrameHeight/2 - 130, 10, 5 );
              ObjMove_AddPatternA2( enm7, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm7, 300 );
              F7( enm7 );

	wait( y );

              let enm8 = Fairy( 2, 250, 70, 70 );
              let x6 = GetStgFrameWidth/2 + rand( -30, 30 );
              ObjMove_SetPosition( enm8, x5, -60 );
              ObjMove_SetDestAtWeight( enm8, x6, GetStgFrameHeight/2 - 130, 10, 5 );
              ObjMove_AddPatternA2( enm8, 250, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm8, 300 );
              F7( enm8 );

	}

             task F7( obj ){ 
              wait( 40 );
              while( !Obj_IsDeleted( obj )){

			if( Obj_IsDeleted( obj )){ break; }
			let speed = 5;
              			let angle = GetAngleToPlayer( obj );
	                                	let way = 1;
                                                	let shote = 825;
			let delay = 10;

			loop( way ){

              			let sx = ObjMove_GetX( obj );
              			let sy = ObjMove_GetY( obj );
			if( Obj_IsDeleted( obj )){ break; }
				
				let sht1 = TShotA2( sx, sy, 0.5, angle, 0.05, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, 0.5, angle + 40, 0.05, speed, shote, delay );
				let sht3 = TShotA2( sx, sy, 0.5, angle - 40, 0.05, speed, shote, delay );

				angle += 360 / way;
			
			}
			if( Obj_IsDeleted( obj )){ break; }
			PlaySound("LenenShot1",92,0);
			wait( 42 );
	}
  
   }

	task Fairy8{
	loop( 40 ){
              let enm = Fairy( 6, 10, 70, 70 );
              ObjMove_SetPosition( enm, -60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 0, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, -6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F3( enm, 8 );
	wait( 5 );
	}

	wait( 65 );

	loop( 40 ){
              let enm = Fairy( 5, 10, 70, 70 );
              ObjMove_SetPosition( enm, GetStgFrameWidth+60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 180, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, 6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F3( enm, -8 );
	wait( 5 );
	}

	wait( 65 );

	loop( 40 ){
              let enm = Fairy( 6, 10, 70, 70 );
              ObjMove_SetPosition( enm, -60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 0, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, -6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F3( enm, 8 );
	wait( 5 );
	}

	wait( 65 );

	loop( 40 ){
              let enm = Fairy( 5, 10, 70, 70 );
              ObjMove_SetPosition( enm, GetStgFrameWidth+60, 160 );
              ObjMove_AddPatternA2( enm, 0, 6, 180, 0, 0, 1 );
              ObjMove_AddPatternA2( enm, 45, 6, NO_CHANGE, 0, 6, 1 );
              ObjMove_AddPatternA2( enm, 75, 6, NO_CHANGE, 0, 0, 1 );
              F3( enm, -8 );
	wait( 5 );
	}
	wait( 65 );
	}

	task Fairy9{
              loop( 2 ){
              let enm0 = Fairy( 2, 350, 70, 70 );
              ObjMove_SetPosition( enm0, GetStgFrameWidth/2, -60 );
              ObjMove_AddPatternA2( enm0, 0, 1, 90, 0, 0, 1 );
              F1( enm0 );

              wait( 220 );

              let enm1 = Fairy( 2, 350, 70, 70 );
              ObjMove_SetPosition( enm1, GetStgFrameWidth/2 + 40, -60 );
              ObjMove_AddPatternA2( enm1, 0, 1, 90, 0, 0, 1 );
              F1( enm1 );
              let enm2 = Fairy( 2, 350, 70, 70 );
              ObjMove_SetPosition( enm2, GetStgFrameWidth/2 - 40, -60 );
              ObjMove_AddPatternA2( enm2, 0, 1, 90, 0, 0, 1 );
              F1( enm2 );

              wait( 220 );

              let enm3 = Fairy( 2, 350, 70, 70 );
              ObjMove_SetPosition( enm3, GetStgFrameWidth/2 + 80, -60 );
              ObjMove_AddPatternA2( enm3, 0, 1, 90, 0, 0, 1 );
              F1( enm3 );
              let enm4 = Fairy( 2, 350, 70, 70 );
              ObjMove_SetPosition( enm4, GetStgFrameWidth/2 - 80, -60 );
              ObjMove_AddPatternA2( enm4, 0, 1, 90, 0, 0, 1 );
              F1( enm4 );

              wait( 220 );

              let enm5 = Fairy( 2, 350, 70, 70 );
              ObjMove_SetPosition( enm5, GetStgFrameWidth/2 + 120, -60 );
              ObjMove_AddPatternA2( enm5, 0, 1, 90, 0, 0, 1 );
              F1( enm5 );
              let enm6 = Fairy( 2, 350, 70, 70 );
              ObjMove_SetPosition( enm6, GetStgFrameWidth/2 -120, -60 );
              ObjMove_AddPatternA2( enm6, 0, 1, 90, 0, 0, 1 );
              F1( enm6 );

              wait( 220 );
	}

	}

	task Fairy10{
              let y = 300;
              let enm = Fairy( 2, 400, 70, 70 );
              ObjMove_SetPosition( enm, GetStgFrameWidth/2, -60 );
              ObjMove_SetDestAtWeight( enm, GetStgFrameWidth/2, GetStgFrameHeight/2 - 60, 10, 5 );
              ObjMove_AddPatternA2( enm, 240, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm, 300 );
              F10( enm );
              F11( enm, 276 );

	wait( y );

              let enm2 = Fairy( 2, 400, 70, 70 );
              let x = GetStgFrameWidth/2 - rand( 60, 80 )+ rand( -30, 30 );
              ObjMove_SetPosition( enm2, x, -60 );
              ObjMove_SetDestAtWeight( enm2, x, GetStgFrameHeight/2 - 60, 10, 5 );
              ObjMove_AddPatternA2( enm2, 240, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm2, 300 );
              F10( enm2 );
              F11( enm2, 277 );

	wait( y );

              let enm3 = Fairy( 2, 400, 70, 70 );
              let x1 = GetStgFrameWidth/2 - rand( 50, 70 )+ rand( -30, 30 );
              ObjMove_SetPosition( enm3, x1, -60 );
              ObjMove_SetDestAtWeight( enm3, x1, GetStgFrameHeight/2 - 60, 10, 5 );
              ObjMove_AddPatternA2( enm3, 240, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm3, 300 );
              F10( enm3 );
              F11( enm3, 279 );

	wait( y );

              let enm4 = Fairy( 2, 400, 70, 70 );
              let x2 = GetStgFrameWidth/2 + rand( 50, 70 )+ rand( -30, 30 );
              ObjMove_SetPosition( enm4, x2, -60 );
              ObjMove_SetDestAtWeight( enm4, x2, GetStgFrameHeight/2 - 60, 10, 5 );
              ObjMove_AddPatternA2( enm4, 240, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm4, 300 );
              F10( enm4 );
              F11( enm4, 280 );

	wait( y );

              let enm5 = Fairy( 2, 400, 70, 70 );
              let x3 = GetStgFrameWidth/2 + rand( 60, 80 )+ rand( -30, 30 );
              ObjMove_SetPosition( enm5, x3, -60 );
              ObjMove_SetDestAtWeight( enm5, x3, GetStgFrameHeight/2 - 60, 10, 5 );
              ObjMove_AddPatternA2( enm5, 240, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm5, 300 );
              F10( enm5 );
              F11( enm5, 281 );

	wait( y );

              let enm6 = Fairy( 2, 600, 70, 70 );
              let x4 = GetStgFrameWidth/2;
              ObjMove_SetPosition( enm6, x4, -60 );
              ObjMove_SetDestAtWeight( enm6, x4, GetStgFrameHeight/2 - 60, 10, 5 );
              ObjMove_AddPatternA2( enm6, 240, 0, 270, 0.08, 0, 5 );
              DelayDelete( enm6, 300 );
              F10( enm6 );
              F11( enm6, 275 );

	}

             task F10( obj ){ 
              wait( 50 );
              let a = 0;
              while( !Obj_IsDeleted( obj )){

			if( Obj_IsDeleted( obj )){ break; }
			let speed = 2.2;
	                                	let way = 9;
              			let angle = 90 + ( 360 / way / 2 ) + 13*sin( a );
                                                	let shote = 310;
			let delay = 10;
			let b = 3;

			loop( way ){

              			let sx = ObjMove_GetX( obj );
              			let sy = ObjMove_GetY( obj );
			if( Obj_IsDeleted( obj )){ break; }
				
				let sht1 = TShotA2( sx, sy, speed, angle - b*3, 0, speed, shote, delay );
				let sht2 = TShotA2( sx, sy, speed, angle - b*2 , 0, speed, shote, delay );
				let sht3 = TShotA2( sx, sy, speed, angle - b*1, 0, speed, shote, delay );
				let sht4 = TShotA2( sx, sy, speed, angle - b*0, 0, speed, shote, delay );
				let sht5 = TShotA2( sx, sy, speed, angle + b*1, 0, speed, shote, delay );
				let sht6 = TShotA2( sx, sy, speed, angle + b*2, 0, speed, shote, delay );
				let sht7 = TShotA2( sx, sy, speed, angle + b*3, 0, speed, shote, delay );

				angle += 360 / way;
			
			}
			a += 38;
			if( Obj_IsDeleted( obj )){ break; }
			PlaySound("LenenShot1",92,0);
			wait( 14 );
	}
  
   }

            task F11( obj, shote ){ 
              wait( 50 );
              let a = 0;
              while( !Obj_IsDeleted( obj )){

			if( Obj_IsDeleted( obj )){ break; }
			let speed = 3;
	                                	let way = 9;
              			let angle = 90 + 13*sin( a );
			let delay = 10;
			let b = 3;

			loop( way ){

              			let sx = ObjMove_GetX( obj );
              			let sy = ObjMove_GetY( obj );
			if( Obj_IsDeleted( obj )){ break; }
				
				let sht1 = TShotA2( sx, sy, speed, angle - b*3, 0, speed, shote, delay );

				angle += 360 / way;
			
			}
			a += 38;
			if( Obj_IsDeleted( obj )){ break; }
			PlaySound("LenenShot1",92,0);
			wait( 14 );
	}
  
   }


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

task BossCharge(boss,num,color){
	let value = [0,0,0];
	value = GetColor(color);
	ascent(i in 0..num){
	FakeLaser;
	if(i%7==0){Bright(boss,11,30,color);}
	wait(1+i%2);
	}
	task FakeLaser{
	let ang = rand(0,360);
	let length = round(rand(250,300));
	let l = length;
	let obj = CreateStraightLaserA1(ObjMove_GetX(boss),ObjMove_GetY(boss),ang,length,5,120,48,0);
	ObjRender_SetColor(obj,value[0],value[1],value[2]);
	ObjShot_SetIntersectionEnable(obj,false);
	ObjShot_SetSpellResist(obj,true);
	ObjStLaser_SetSource(obj,false);
		while(length>0){
		ObjLaser_SetLength(obj,length);
		length -=l/20;
		yield;
		}
		Obj_Delete(obj);
	}
}

	task DrawDifficulty{
	let path = GetCurrentScriptDirectory() ~ "img/front00.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let value = 0;
	ObjPrim_SetTexture(obj, path);
	ObjRender_SetScaleXYZ(obj,0,0,0);
	while(value==0){
	if(GetCommonData("Difficulty","Easy")=="Hard"){value = 2;}
	if(GetCommonData("Difficulty","Easy")=="Lunatic"){value = 3;}
	yield;
	}
	MinorEffect;
	while(!Obj_IsDeleted(obj)){
	ObjSprite2D_SetSourceRect(obj, 520, 608+32*value, 520+144, 640+32*value);
	Obj_SetRenderPriority(obj, 1);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,530,30,0);
	yield;
	}
		task MinorEffect{
			ascent(i in 0..60){
			ObjRender_SetScaleXYZ(obj,0.55,i*0.01,0);
			yield;
			}
			ascent(i in 0..90){
			ObjRender_SetColor(obj,192+63*sin(i*20+90),192+63*sin(i*20+90),192+63*sin(i*20+90));
			yield;
			}
		}
	}


function GetColor(type){
	if(type=="RED"){return [255,32,32];}
	if(type=="ORANGE"){return [255,128,32];}
	if(type=="YELLOW"){return [255,255,32];}
	if(type=="GREEN"){return [32,255,32];}
	if(type=="BLUE"){return [32,32,255];}
	if(type=="PURPLE"){return [255,32,255];}
	if(type=="PINK"){return [255,32,128];}
	if(type=="WHITE"){return [255,255,255];}
	if(type=="AQUA"){return [0,255,255];}
	if(type=="WHITE"){return [255,255,255];}
	}
	
task Bright(boss,size,t,color){ // task for draw light circle , I can't describe it, so try it yourself
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GCSD~"img/bright.png";
	let c = 0;
	let set = 360/(t*3);
	let value = [0,0,0];
	let speed = 90/t;
	let size_speed = size/t;
	value = GetColor(color);
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,64,64);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,ObjRender_GetX(boss),ObjRender_GetY(boss),0);
	ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	ObjRender_SetScaleXYZ(obj,0,0,0);
	Obj_SetRenderPriorityI(obj,25);
		ascent(i in 0..t){
		if(Obj_IsDeleted(boss)){break;}
		ObjRender_SetColor(obj,value[0]*sin(i*speed)/2,value[1]*sin(i*speed)/2,value[2]*sin(i*speed)/2);
		ObjRender_SetScaleXYZ(obj,11-i*size_speed,11-i*size_speed,0);
		yield;
		}
		Obj_Delete(obj);
	}
	
task MapleExplode(px,py,speed,c){
	let color = GetColor(c);
	let st = rand(0,30);
	TExpan(px,py,12,30,color[0],color[1],color[2]);
	ascent(i in 0..12){
		Maple(px,py,speed+speed/(5/3)*sin(i*177),i*30+st,color[0],color[1],color[2]);
	}
}

task Maple(px,py,sizespeed,dir,red,green,blue){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GCSD~"img/effect1.png";
	let spd = sizespeed*7;
	let acc = spd/60;
	let acc2 = acc/100;
	let r = 0;
	let a = [0,0,0];
	let angle_s = [0,0,0];
	let alpha = 255;
	let result = 0;
	let color_ratio = [red/90,green/90,blue/90];
	ascent(i in 0..3){
	result = rand(-1,1);
	if(result>0){result = 1;}
	else{result = -1;}
	angle_s[i] = rand(2,4)*result;
	}
	LoadTexture(img);
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj, 0, 0, 64, 64);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	ObjRender_SetScaleXYZ(obj,sizespeed,sizespeed,sizespeed);
		while(alpha>0){
		ObjRender_SetAngleXYZ(obj,a[0],a[1],a[2]);
		ObjRender_SetPosition(obj,px+r*cos(dir),py+r*sin(dir),0);
		ObjRender_SetColor(obj,red,green,blue);
		r+=spd;
		if(spd>1.5){
		red -= color_ratio[0];
		green -= color_ratio[1];
		blue -= color_ratio[2];
		spd -=acc;
		acc += acc2;
		}
		else{
		red -= color_ratio[0]*4;
		green -= color_ratio[1]*4;
		blue -= color_ratio[2]*4;
		}
		ascent(i in 0..3){
		a[i] = a[i]+angle_s[i];
		}
		yield;
		}
		Obj_Delete(obj);
}

function TExpan(px,py,maxv,t,r,g,b){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let img=GCSD~"img/charge.png";
	let scale = 0;
	let v = 0;
	let malpha = 255/t;
	ObjPrim_SetTexture(obj,img);
	ObjSprite2D_SetSourceRect(obj,0,0,128,128);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,px,py,0);
	ObjRender_SetColor(obj,r,g,b);
	Obj_SetRenderPriorityI(obj,25);
	Expan;
		task Expan{
			descent(i in 0..t){
			ObjRender_SetAlpha(obj,malpha*i);
			v = (i*maxv/2)/(t*t);
			scale += v;
			ObjRender_SetScaleXYZ(obj,scale,scale,0);
			yield;
			}
			Obj_Delete(obj);
		}
	}
	

function Sound(path){
	ObjSound_Load(song,path);
	ObjSound_SetSoundDivision(song, SOUND_BGM);
	ObjSound_SetRestartEnable(song, true);
	ObjSound_SetLoopEnable(song, true);
	ObjSound_SetLoopSampleCount(song,6956568,16334097);
	ObjSound_Play(song);
	}
	
task StopS(obj){
	descent(i in 0..100){
	ObjSound_SetVolumeRate(song,i);
	loop(1){yield;}
	}
	}


// Custom delay function for AllStarShot.png

function ShotA1(x,y,spd,dir,graphic,cloud,delay){
	let shot = CreateShotA1(x,y,spd,dir,graphic,delay);
	DelayCloud(shot,x,y,spd,dir,graphic,cloud,delay);
	return shot;
	}
	
function TShotA1(x,y,spd,dir,graphic,delay){ // FOR ZUN DELAY CLOUD
	let cloud = CheckDelayColor(graphic);
	let shot = ShotA1(x,y,spd,dir,graphic,cloud,delay);
	return shot;
	}
	
function CheckDelayColor(graphic){ // ZUN DELAY CLOUD
	let color = GetShotDataInfoA1(graphic,TARGET_ENEMY,INFO_DELAY_COLOR);
	let cloud = 0;
	if(color[0]==128 && color[1]==128 && color[2]==128){cloud = 201;} // GRAY
	if(color[0]==255 && color[1]==64 && color[2]==64){cloud = 202;} // RED
	if(color[0]==255 && color[1]==64 && color[2]==255){cloud = 203;} // PURPLE
	if(color[0]==64 && color[1]==64 && color[2]==255){cloud = 204;} // BLUE
	if(color[0]==64 && color[1]==255 && color[2]==255){cloud = 205;} // AQUA
	if(color[0]==64 && color[1]==255 && color[2]==64){cloud = 206;} // GREEN
	if(color[0]==255 && color[1]==255 && color[2]==64){cloud = 207;} // YELLOW
	if(color[0]==192 && color[1]==255 && color[2]==64){cloud = 207;} // YELLOW 2
	if(color[0]==255 && color[1]==128 && color[2]==64){cloud = 208;} // ORANGE
	if(graphic>500){cloud+=500;}
	return cloud;
}
	
function ShotA2(x,y,spd,dir,acc,maxacc,graphic,cloud,delay){
	let shot = CreateShotA2(x,y,spd,dir,acc,maxacc,graphic,delay);
	DelayCloud(shot,x,y,spd,dir,graphic,cloud,delay);
	return shot;
	}
	
function TShotA2(x,y,spd,dir,acc,maxacc,graphic,delay){ // FOR ZUN DELAY CLOUD
	let cloud = CheckDelayColor(graphic);
	let shot = ShotA2(x,y,spd,dir,acc,maxacc,graphic,cloud,delay);
	return shot;
	}

function ShotOA1(obj,spd,dir,graphic,cloud,delay){
	let shot = CreateShotOA1(obj,spd,dir,graphic,delay);
	DelayCloud(shot,ObjMove_GetX(obj),ObjMove_GetY(obj),spd,dir,graphic,cloud,delay);
	return shot;
	}
	
function TShotOA1(obj,spd,dir,graphic,delay){ // FOR ZUN DELAY CLOUD
	let cloud = CheckDelayColor(graphic);
	let shot = ShotOA1(obj,spd,dir,graphic,cloud,delay);
	return shot;
}
	
function ShotB2(x,y,xspd,yspd,xacc,yacc,xmax,ymax,graphic,cloud,delay){
	let angle = atan2(yspd,xspd);
	let shot = CreateShotB2(x,y,xspd,yspd,xacc,yacc,xmax,ymax,graphic,delay);
	DelayCloud(shot,x,y,0,angle,graphic,cloud,delay);
	return shot;
}

task DelayCloud(shot,x,y,spd,dir,graphic,cloud,delay){
	 let img=GCSD~"Shot/AllStarShot.png";
	 let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	 let c = 0;
	 let v = false;
	 let px = 0;
	 let adc = false;
	 let s;
	 if(!Obj_IsDeleted(shot)){
	 ObjPrim_SetTexture(obj,img);
	 ObjRender_SetBlendType(obj,BLEND_ALPHA);
	 ObjRender_SetAngleXYZ(obj,0,0,dir+90);
	 if(cloud==0){cloud=graphic;}
	 if( (cloud>=201 && cloud<=208) || (cloud>=701 && cloud<=708)){
	 s = GetShotDataInfoA1(cloud,TARGET_ENEMY,INFO_COLLISION)/2.5;
	 }
	 else if ( (cloud>=323 && cloud<=330) || (cloud>=823 && cloud<=830)){
	 s = GetShotDataInfoA1(cloud,TARGET_ENEMY,INFO_COLLISION)/5.5;
	 }
	 else{
	  s = GetShotDataInfoA1(cloud,TARGET_ENEMY,INFO_COLLISION)/2.5;
	 }
	 if(GetShotDataInfoA1(cloud,TARGET_ENEMY,INFO_BLEND)==BLEND_ADD_RGB || GetShotDataInfoA1(cloud,TARGET_ENEMY,INFO_BLEND)==BLEND_ADD_ARGB){
	 adc = true;
	 ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	 }
	 let s_value = s-1;
	 let rect = GetShotDataInfoA1(cloud,TARGET_ENEMY,INFO_RECT);
	 ObjSprite2D_SetSourceRect(obj,rect[0],rect[1],rect[2],rect[3]);
	 ObjSprite2D_SetDestCenter(obj);
	 ObjRender_SetPosition(obj,x,y,0);
	 while(c<delay && !Obj_IsDeleted(shot)){
	 ObjRender_SetScaleXYZ(obj,s,s,0);
	 if(v==true){ ObjRender_SetAngleXYZ(obj,0,0,dir+90-c*3)};
	 if(s>=1){s -= s_value/delay;}
	 c++;
	 if(adc==false){ObjRender_SetAlpha(obj,c*255/(delay*1.25));}
	else {ObjRender_SetColor(obj,c*255/(delay*1.25),c*255/(delay*1.25),c*255/(delay*1.25));}
	 yield;
	 }
	 Obj_Delete(obj);
	 }
	 }
	 
	function CurvyLaser(x,y,speed,dir,l,w,graphic,fade){
	let shot = CreateShotA1(x,y,speed,dir,graphic,0);
	Obj_SetVisible(shot,false);
	ObjShot_SetIntersectionEnable(shot,false);
	ObjShot_SetSpellResist(shot,true);
	Trail;
	return shot;
		task Trail{
			while(!Obj_IsDeleted(shot)){
				LaserEffect(fade,l,w);
				wait(1);
			}
				task LaserEffect(fade,l,w){
				let fade_value = 1.25;
				fade *= fade_value;
				l = ObjMove_GetSpeed(shot)*l+l;
				let obj = CreateStraightLaserA1(ObjMove_GetX(shot),ObjMove_GetY(shot),ObjMove_GetAngle(shot),l,w,fade/1.5,graphic,0);
				let original_l = l;
				let original_w = w;
				let alpha = 0;
					loop(fade){
					ObjLaser_SetRenderWidth(obj,w*fade_value);
					ObjLaser_SetIntersectionWidth(obj,(w/2)*fade_value);
					ObjLaser_SetLength(obj,l*fade_value);
					if(alpha<200){alpha+=20;}
					ObjRender_SetColor(obj,alpha,alpha,alpha);
					l -= original_l/fade;
					w -= original_w/fade;
					wait(2);
					}
					Obj_Delete(obj);
				}
		}
}

	function CurvyLaser2(x,y,speed,dir,l,w,graphic,fade){
	let shot = CreateShotA1(x,y,speed,dir,graphic,0);
	Obj_SetVisible(shot,false);
	ObjShot_SetIntersectionEnable(shot,false);
	ObjShot_SetSpellResist(shot,true);
	Trail;
	return shot;
		task Trail{
			let c = 0;
			while(!Obj_IsDeleted(shot)){
				LaserEffect(fade,l,w,c);
				wait(1);
				c+=10;
			}
				task LaserEffect(fade,l,w,c){
				let fade_value = 1.25;
				fade *= fade_value;
				l = ObjMove_GetSpeed(shot)*l+l;
				let obj = CreateStraightLaserA1(ObjMove_GetX(shot),ObjMove_GetY(shot),ObjMove_GetAngle(shot),l,w,fade/1.5,graphic,0);
				let original_l = l;
				let original_w = w;
				let alpha = 0;
					loop(fade){
					ObjLaser_SetRenderWidth(obj,w*fade_value);
					ObjLaser_SetIntersectionWidth(obj,(w/2)*fade_value);
					ObjLaser_SetLength(obj,l*fade_value);
					if(alpha<200){alpha+=20;}
					ObjRender_SetColor(obj,192+32*sin(c),48,128+64*sin(c+180));
					l -= original_l/fade;
					w -= original_w/fade;
					wait(2);
					}
					Obj_Delete(obj);
				}
		}
}
	
function ScalingBullet(x,y,v,dir,graphic,hitbox,scale,cloud,delay){
	let shot = ShotA1(x,y,v,dir,hitbox,0,0);
	Obj_SetVisible(shot,false);
		ManageGraphic;
		return shot;
			task ManageGraphic{
			let dummy = ShotOA1(shot,0,0,graphic,cloud,delay);
			ObjRender_SetScaleXYZ(dummy,scale,scale,scale);
			ObjShot_SetIntersectionEnable(dummy,false);
			Obj_SetValue(dummy,"ShotEffectOrNot",0);
				while(!Obj_IsDeleted(shot) && !Obj_IsDeleted(dummy)){
					ObjMove_SetPosition(dummy,ObjMove_GetX(shot),ObjMove_GetY(shot));
					ObjRender_SetAngleXYZ(dummy,0,0,ObjMove_GetAngle(shot));
					yield;
				}
				Obj_Delete(dummy);
			}
	}

function wait(t){loop(t){yield;}}