task CreateStageEnemy6(x, y, speedE, angleE) {
let shootSFX = GetCurrentScriptDirectory ~ "SFX/ATTACK5.wav";
let deadSFX = GetCurrentScriptDirectory ~ "SFX/BEAT.mp3";
let animFrame = 0; 
let animFrame2 = 0;
 let Xmin = -32;
    let Xmax = GetStgFrameWidth + 32;
    let Ymin = -300; 
    let Ymax = GetStgFrameHeight + 32;
	let count = 0; 
    
	let objEnemy6 = ObjEnemy_Create(OBJ_ENEMY);
    TInitialize;
    task TInitialize 
    {
        LoadSound(shootSFX);
        
        LoadSound(deadSFX);
        
        
        ObjEnemy_Regist(objEnemy6);
        ObjEnemy_SetLife(objEnemy6, 120);
        
        ObjEnemy_SetDamageRate(objEnemy6, 200, 200);
        ObjMove_SetPosition(objEnemy6, x, y);
        ObjMove_SetAngle(objEnemy6, angleE);
        ObjMove_SetSpeed(objEnemy6, speedE); 
        ObjMove_SetDestAtSpeed(objEnemy6, x , y+250, 5); //movement function
        TDrawLoop;
        TMainLoop;
        TFinalize;
        wait(400);
        
        let e_dir = GetAngleToPlayer(objEnemy6) > 192;
        ObjMove_AddPatternA2(objEnemy6, 0, 0, 180, 6/120, 0, 6);
        
        //TFinalize;
    }
	function GetEnemyX{
return ObjMove_GetX(objEnemy6);
}
	function GetEnemyY{
return ObjMove_GetY(objEnemy6);
}
     task TMainLoop {
        while(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) > 0) {
            ObjEnemy_SetIntersectionCircleToShot(objEnemy6, ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 32); 
            ObjEnemy_SetIntersectionCircleToPlayer(objEnemy6, ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 8);
            if (count % 60 == 30) {bulletA;}
			
            count++;
			if (count == 300){DeleteShotAll(TYPE_CHILD, TYPE_ITEM);	}
			
			/// animation
			let speed;
            let dir;
			dir = ObjMove_GetAngle(objEnemy6);
		speed = ObjMove_GetSpeed(objEnemy6);
		
			if(speed == 0){ 
			ObjRender_SetAngleXYZ(objEnemy6,0,0,0);
			if(animFrame < 3) { ObjSprite2D_SetSourceRect(objEnemy6, 0, 0, 137, 106); }
			if(animFrame >= 5 && animFrame < 8) { ObjSprite2D_SetSourceRect(objEnemy6,142,0,283,106); }
			
			animFrame2 = 0;
		}
		else if(cos(dir) < 0){ 
			ObjRender_SetAngleXYZ(objEnemy6,0,0,0);	// flip vertical
			
			if(animFrame2 < 3) { ObjSprite2D_SetSourceRect(objEnemy6, 280, 0, 410, 106);}
            if(animFrame2 >= 5 && animFrame2 < 8) { ObjSprite2D_SetSourceRect(objEnemy6, 420, 0, 552, 106); }
			 if(animFrame >= 10) { ObjSprite2D_SetSourceRect(objEnemy6, 280, 0, 410, 106);}
			
		}
		else if(cos(dir) > 0){ 
			ObjRender_SetAngleXYZ(objEnemy6,0,180,0);	// flip vertical
			
			if(animFrame2 < 3) { ObjSprite2D_SetSourceRect(objEnemy6, 280, 0, 410, 106);}
            if(animFrame2 >= 5 && animFrame2 < 8) { ObjSprite2D_SetSourceRect(objEnemy6, 420, 0, 552, 106); }
			 if(animFrame >= 10){ ObjSprite2D_SetSourceRect(objEnemy6, 280, 0, 410, 106);}
		}
		animFrame++;		// count animFrame. (++ is +1)
		animFrame2+=2;		// count animFrame2.
		if(animFrame > 18) { animFrame = 0; }	// reset animFrame when it is higher than 18.
		yield;
		
		            if (ObjMove_GetX(objEnemy6) < Xmin || ObjMove_GetY(objEnemy6) > Xmax || ObjMove_GetY(objEnemy6) < Ymin || ObjMove_GetY(objEnemy6) > Ymax) {
                Obj_Delete(objEnemy6); }

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

		function angleToPlayer {
	let dir = atan2(GetPlayerY-ObjMove_GetY(objEnemy6),GetPlayerX-ObjMove_GetX(objEnemy6));
	return dir;
}
    
    task bulletA{
	
	if (GetCommonData("Difficulty", 3) == 3){
	while(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) > 0){
  let angleT = 90;
    loop(1){   
wait(40);
PlaySE(shootSFX);
ascent(i in 0..5){
	CreateShotA1(ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 3, rand(0, 360), DS_SCALE_A_PURPLE, 0);
angleT += 360/10;
	yield;
    }
		
 }
 }
 }
 
 	if (GetCommonData("Difficulty", 2) == 2){
	while(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) > 0){
  let angleT = 90;
    loop(1){   
wait(45);
PlaySE(shootSFX);
ascent(i in 0..3){
	CreateShotA1(ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 3, rand(0, 360), DS_SCALE_A_PURPLE, 0);
angleT += 360/10;
	yield;
    }
		
 }
 }
 }
 
  	if (GetCommonData("Difficulty", 1) == 1){
	while(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) > 0){
  let angleT = 90;
    loop(1){   
wait(50);
PlaySE(shootSFX);
ascent(i in 0..1){
	CreateShotA1(ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 3, rand(0, 360), DS_SCALE_A_PURPLE, 0);
angleT += 360/10;
	yield;
    }
		
 }
 }
 }
 
  	if (GetCommonData("Difficulty", 0) == 0){
	while(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) > 0){
  let angleT = 90;
    loop(1){   
wait(60);
PlaySE(shootSFX);
ascent(i in 0..1){
	CreateShotA1(ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 3, rand(0, 360), DS_SCALE_A_PURPLE, 0);
angleT += 360/10;
	yield;
    }
		
 }
 }
 
 
 }
 
 }
 
 
 task TExplosion{
    let path = GetCurrentScriptDirectory() ~ "sprite/pow.png";
    let obj = ObjPrim_Create(OBJ_SPRITE_2D);
    ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
    Obj_SetRenderPriority(obj, 0.60);
    ObjPrim_SetTexture(obj, path);
    ObjSprite2D_SetSourceRect(obj, 0, 0, 100, 100);
    ObjSprite2D_SetDestRect(obj, -32, -32, 32, 32);
 
    let alpha = 230;
    let scale = 0.5;
    loop(12)
    {
        scale += 0.2;
        alpha -= 8;
        ObjRender_SetColor(obj, alpha, alpha, alpha);
        ObjRender_SetPosition(obj, GetEnemyX, GetEnemyY, 0);
        ObjRender_SetScaleXYZ(obj, scale, scale, 0.5);
        yield;
    }
    Obj_Delete(obj);
}

        	
    
	task TDrawLoop {
	let imgenemy = GetCurrentScriptDirectory() ~ "sprite/eyechart4.png";
    ObjPrim_SetTexture(objEnemy6, imgenemy);
    ObjSprite2D_SetSourceRect(objEnemy6, 0, 0, 137, 106);
	ObjRender_SetScaleXYZ(objEnemy6, 0.5, 0.5, 0);
    ObjSprite2D_SetDestCenter(objEnemy6);
	}
    task TFinalize 
    {
        //if(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) == 0) 
        while(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) > 0)//this checks if the enemy has still life remaining
        {
            yield;
        }

        if(!Obj_IsDeleted(objEnemy6))//This checks if the enemy is already deleted by other means like leaving the screen and getting killed through a differnt task and no effect is needed
        {
            PlaySE(deadSFX);
            TExplosion;
            wait(12);
            Obj_Delete(objEnemy6);
            DeleteShotInCircle(TYPE_CHILD, TYPE_ITEM, ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 80); 
            yield;
        }
    }
	

}








//------------------------------------------


task CreateStageEnemy62(x, y, speedE, angleE) {
let shootSFX = GetCurrentScriptDirectory ~ "SFX/ATTACK5.wav";
let deadSFX = GetCurrentScriptDirectory ~ "SFX/BEAT.mp3";
let animFrame = 0; 
let animFrame2 = 0;
 let Xmin = -32;
    let Xmax = GetStgFrameWidth + 32;
    let Ymin = -300; 
    let Ymax = GetStgFrameHeight + 32;
	let count = 0; 
    
	let objEnemy6 = ObjEnemy_Create(OBJ_ENEMY);
    TInitialize;
    task TInitialize 
    {
        LoadSound(shootSFX);
        
        LoadSound(deadSFX);
        
        
        ObjEnemy_Regist(objEnemy6);
        ObjEnemy_SetLife(objEnemy6, 300);
        
        ObjEnemy_SetDamageRate(objEnemy6, 200, 200);
        ObjMove_SetPosition(objEnemy6, x, y);
        ObjMove_SetAngle(objEnemy6, angleE);
        ObjMove_SetSpeed(objEnemy6, speedE); 
        ObjMove_SetDestAtSpeed(objEnemy6, x , y+250, 5); //movement function
        TDrawLoop;
        TMainLoop;
        TFinalize;
        wait(500);
        
        let e_dir = GetAngleToPlayer(objEnemy6) > 192;
        ObjMove_AddPatternA2(objEnemy6, 0, 0, 180, 6/120, 0, 6);
        
        //TFinalize;
    }
	function GetEnemyX{
return ObjMove_GetX(objEnemy6);
}
	function GetEnemyY{
return ObjMove_GetY(objEnemy6);
}
     task TMainLoop {
        while(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) > 0) {
            ObjEnemy_SetIntersectionCircleToShot(objEnemy6, ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 32); 
            ObjEnemy_SetIntersectionCircleToPlayer(objEnemy6, ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 8);
            if (count % 60 == 30) {bulletA;}
			
            count++;
			if (count == 300){DeleteShotAll(TYPE_CHILD, TYPE_ITEM);	}
			
			/// animation
			let speed;
            let dir;
			dir = ObjMove_GetAngle(objEnemy6);
		speed = ObjMove_GetSpeed(objEnemy6);
		
			if(speed == 0){ 
			ObjRender_SetAngleXYZ(objEnemy6,0,0,0);
			if(animFrame < 3) { ObjSprite2D_SetSourceRect(objEnemy6, 0, 0, 137, 106); }
			if(animFrame >= 5 && animFrame < 8) { ObjSprite2D_SetSourceRect(objEnemy6,142,0,283,106); }
			
			animFrame2 = 0;
		}
		else if(cos(dir) < 0){ 
			ObjRender_SetAngleXYZ(objEnemy6,0,0,0);	// flip vertical
			
			if(animFrame2 < 3) { ObjSprite2D_SetSourceRect(objEnemy6, 280, 0, 410, 106);}
            if(animFrame2 >= 5 && animFrame2 < 8) { ObjSprite2D_SetSourceRect(objEnemy6, 420, 0, 552, 106); }
			 if(animFrame >= 10) { ObjSprite2D_SetSourceRect(objEnemy6, 280, 0, 410, 106);}
			
		}
		else if(cos(dir) > 0){ 
			ObjRender_SetAngleXYZ(objEnemy6,0,180,0);	// flip vertical
			
			if(animFrame2 < 3) { ObjSprite2D_SetSourceRect(objEnemy6, 280, 0, 410, 106);}
            if(animFrame2 >= 5 && animFrame2 < 8) { ObjSprite2D_SetSourceRect(objEnemy6, 420, 0, 552, 106); }
			 if(animFrame >= 10){ ObjSprite2D_SetSourceRect(objEnemy6, 280, 0, 410, 106);}
		}
		animFrame++;		// count animFrame. (++ is +1)
		animFrame2+=2;		// count animFrame2.
		if(animFrame > 18) { animFrame = 0; }	// reset animFrame when it is higher than 18.
		yield;
		
		            if (ObjMove_GetX(objEnemy6) < Xmin || ObjMove_GetY(objEnemy6) > Xmax || ObjMove_GetY(objEnemy6) < Ymin || ObjMove_GetY(objEnemy6) > Ymax) {
                Obj_Delete(objEnemy6); }

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

		function angleToPlayer {
	let dir = atan2(GetPlayerY-ObjMove_GetY(objEnemy6),GetPlayerX-ObjMove_GetX(objEnemy6));
	return dir;
}
    
    task bulletA{
	
		if (GetCommonData("Difficulty", 3) == 3){
	while(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) > 0){
  let angleT = 90;
    loop(1){ 
wait(40);
PlaySE(shootSFX);
ascent(i in 0..6){
	CreateShotA1(ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 3, rand(0, 360),DS_RICE_M_R_PURPLE, 0);
angleT += 360/10;
	yield;
    }
		
 }
 }
 }
 
 		if (GetCommonData("Difficulty", 2) == 2){
	while(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) > 0){
  let angleT = 90;
    loop(1){ 
wait(40);
PlaySE(shootSFX);
ascent(i in 0..4){
	CreateShotA1(ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 3, rand(0, 360),DS_RICE_M_R_PURPLE, 0);
angleT += 360/10;
	yield;
    }
		
 }
 }
 }
 
  		if (GetCommonData("Difficulty", 1) == 1){
	while(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) > 0){
  let angleT = 90;
    loop(1){ 
wait(40);
PlaySE(shootSFX);
ascent(i in 0..1){
	CreateShotA1(ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 3, rand(0, 360),DS_RICE_M_R_PURPLE, 0);
angleT += 360/10;
	yield;
    }
		
 }
 }
 }
 
   		if (GetCommonData("Difficulty", 0) == 0){
	while(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) > 0){
  let angleT = 90;
    loop(1){ 
wait(60);
PlaySE(shootSFX);
ascent(i in 0..1){
	CreateShotA1(ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 3, rand(0, 360),DS_RICE_M_R_PURPLE, 0);
angleT += 360/10;
	yield;
    }
		
 }
 }
 }
 
 }
 
 
 task TExplosion{
    let path = GetCurrentScriptDirectory() ~ "sprite/pow.png";
    let obj = ObjPrim_Create(OBJ_SPRITE_2D);
    ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
    Obj_SetRenderPriority(obj, 0.60);
    ObjPrim_SetTexture(obj, path);
    ObjSprite2D_SetSourceRect(obj, 0, 0, 100, 100);
    ObjSprite2D_SetDestRect(obj, -32, -32, 32, 32);
 
    let alpha = 230;
    let scale = 0.5;
    loop(12)
    {
        scale += 0.2;
        alpha -= 8;
        ObjRender_SetColor(obj, alpha, alpha, alpha);
        ObjRender_SetPosition(obj, GetEnemyX, GetEnemyY, 0);
        ObjRender_SetScaleXYZ(obj, scale, scale, 0.5);
        yield;
    }
    Obj_Delete(obj);
}

        	
    
	task TDrawLoop {
	let imgenemy = GetCurrentScriptDirectory() ~ "sprite/eyechart4.png";
    ObjPrim_SetTexture(objEnemy6, imgenemy);
    ObjSprite2D_SetSourceRect(objEnemy6, 0, 0, 137, 106);
	ObjRender_SetScaleXYZ(objEnemy6, 0.5, 0.5, 0);
    ObjSprite2D_SetDestCenter(objEnemy6);
	}
    task TFinalize 
    {
        //if(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) == 0) 
        while(ObjEnemy_GetInfo(objEnemy6, INFO_LIFE) > 0)//this checks if the enemy has still life remaining
        {
            yield;
        }

        if(!Obj_IsDeleted(objEnemy6))//This checks if the enemy is already deleted by other means like leaving the screen and getting killed through a differnt task and no effect is needed
        {
            PlaySE(deadSFX);
            TExplosion;
            wait(12);
            Obj_Delete(objEnemy6);
            DeleteShotInCircle(TYPE_CHILD, TYPE_ITEM, ObjMove_GetX(objEnemy6), ObjMove_GetY(objEnemy6), 80); 
            yield;
        }
    }
	

}
