task CreateStageEnemy3(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 = -32; 
    let Ymax = GetStgFrameHeight + 32;
	let count = 0; 
    let objEnemy1 = ObjEnemy_Create(OBJ_ENEMY);
    TInitialize;
    task TInitialize {
	 LoadSound(shootSFX);
	  LoadSound(deadSFX);
	  

        
        ObjEnemy_Regist(objEnemy1);
        ObjEnemy_SetLife(objEnemy1, 40);
		let dir = GetAngleToPlayer(objEnemy1) > 192;
        ObjEnemy_SetDamageRate(objEnemy1, 200, 200);
        ObjMove_SetPosition(objEnemy1, x, y);
        ObjMove_SetAngle(objEnemy1, angleE);
        ObjMove_SetSpeed(objEnemy1, speedE);
        ObjMove_SetDestAtSpeed(objEnemy1, 600 , 600, 3); //movement function
        TDrawLoop;
        TMainLoop;
		
        TFinalize;
    }
	function GetEnemyX{
return ObjMove_GetX(objEnemy1);
}
	function GetEnemyY{
return ObjMove_GetY(objEnemy1);
}
     task TMainLoop {
        while(ObjEnemy_GetInfo(objEnemy1, INFO_LIFE) > 0) {
            ObjEnemy_SetIntersectionCircleToShot(objEnemy1, ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 32); 
            ObjEnemy_SetIntersectionCircleToPlayer(objEnemy1, ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 8);
            if (count % 60 == 15){
			bulletA;
			wait(20);
			bulletA;
			wait(20);
			bulletA;
			wait(20);}
            count++;
			if (count == 60){DeleteShotAll(TYPE_CHILD, TYPE_ITEM);	}
			
			/// animation
			let speed;
            let dir;
			dir = ObjMove_GetAngle(objEnemy1);
		speed = ObjMove_GetSpeed(objEnemy1);
		
			if(speed == 0){ 
			ObjRender_SetAngleXYZ(objEnemy1,0,0,0);
			if(animFrame < 3) { ObjSprite2D_SetSourceRect(objEnemy1, 0, 0, 137, 106); }
			if(animFrame >= 5 && animFrame < 8) { ObjSprite2D_SetSourceRect(objEnemy1,142,0,283,106); }
			
			animFrame2 = 0;
		}
		else if(cos(dir) < 0){ 
			ObjRender_SetAngleXYZ(objEnemy1,0,0,0);	// flip vertical
			if(animFrame2 < 3) { ObjSprite2D_SetSourceRect(objEnemy1, 280, 0, 410, 106);}
            if(animFrame2 >= 5) { ObjSprite2D_SetSourceRect(objEnemy1, 420, 0, 552, 106); }
			
		}
		else if(cos(dir) > 0){ 
			ObjRender_SetAngleXYZ(objEnemy1,0,180,0);	// flip vertical
			if(animFrame2 < 3) { ObjSprite2D_SetSourceRect(objEnemy1, 280, 0, 410, 106);}
            if(animFrame2 >= 5) { ObjSprite2D_SetSourceRect(objEnemy1, 420, 0, 552, 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(objEnemy1) < Xmin || ObjMove_GetY(objEnemy1) > Xmax || ObjMove_GetY(objEnemy1) < Ymin || ObjMove_GetY(objEnemy1) > Ymax) {
                Obj_Delete(objEnemy1); }

            yield;
        }
		
		
		}
    

		
    
    task bulletA{
	if (GetCommonData("Difficulty", 0) == 0){

   let angleT = GetAngleToPlayer(objEnemy1);
   
    
	
     ascent(i in 0..2){
	 wait(5);
	 PlaySE(shootSFX);
        CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT+20,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT,DS_BALL_BS_SKY + i, 5);
        
		
    }
	}
	
		if (GetCommonData("Difficulty", 1) == 1){

   let angleT = GetAngleToPlayer(objEnemy1);
   
    
	
     ascent(i in 0..4){
	 PlaySE(shootSFX);
	 wait(5);
        CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT+20,DS_BALL_BS_SKY + i, 5);
        CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT,DS_BALL_BS_SKY + i, 5);
		
    }
	}
	
			if (GetCommonData("Difficulty", 2) == 2){

   let angleT = GetAngleToPlayer(objEnemy1);
   
    
	
     ascent(i in 0..4){
	 PlaySE(shootSFX);
        CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT-20,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT+20,DS_BALL_BS_SKY + i, 5);
		
        
		
    }
	}
	
	
			if (GetCommonData("Difficulty", 3) == 3){

   let angleT = GetAngleToPlayer(objEnemy1);
   
    
	
     ascent(i in 0..4){
	 PlaySE(shootSFX);
        CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT-20,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT+20,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT-20,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT+20,DS_BALL_BS_SKY + i, 5);
        
		
    }
	}
 }
 
 
 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/eyechart.png";
    ObjPrim_SetTexture(objEnemy1, imgenemy);
    ObjSprite2D_SetSourceRect(objEnemy1, 0, 0, 137, 106);
	ObjRender_SetScaleXYZ(objEnemy1, 0.5, 0.5, 0);
    ObjSprite2D_SetDestCenter(objEnemy1);

	}
    task TFinalize {
        //if(ObjEnemy_GetInfo(objEnemy1, INFO_LIFE) == 0) 
        while(ObjEnemy_GetInfo(objEnemy1, INFO_LIFE) > 0)//this checks if the enemy has still life remaining
        {
            yield;
        }

        if(!Obj_IsDeleted(objEnemy1))//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(objEnemy1);
            DeleteShotInCircle(TYPE_CHILD, TYPE_ITEM, ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 200); 
            yield;
        }
    }

}



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

task CreateStageEnemy32(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 = -32; 
    let Ymax = GetStgFrameHeight + 32;
	let count = 0; 
    let objEnemy1 = ObjEnemy_Create(OBJ_ENEMY);
    TInitialize;
    task TInitialize {
	 LoadSound(shootSFX);
	  LoadSound(deadSFX);
	  

        
        ObjEnemy_Regist(objEnemy1);
        ObjEnemy_SetLife(objEnemy1, 30);
		let dir = GetAngleToPlayer(objEnemy1) > 192;
        ObjEnemy_SetDamageRate(objEnemy1, 200, 200);
        ObjMove_SetPosition(objEnemy1, x, y);
        ObjMove_SetAngle(objEnemy1, angleE);
        ObjMove_SetSpeed(objEnemy1, speedE);
        ObjMove_SetDestAtSpeed(objEnemy1, -600 , 600, 3); //movement function
        TDrawLoop;
        TMainLoop;
		
        TFinalize;
    }
	function GetEnemyX{
return ObjMove_GetX(objEnemy1);
}
	function GetEnemyY{
return ObjMove_GetY(objEnemy1);
}
     task TMainLoop {
        while(ObjEnemy_GetInfo(objEnemy1, INFO_LIFE) > 0) {
            ObjEnemy_SetIntersectionCircleToShot(objEnemy1, ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 32); 
            ObjEnemy_SetIntersectionCircleToPlayer(objEnemy1, ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 8);
            if (count % 60 == 15){
			bulletA;
			wait(20);
			bulletA;
			wait(20);
			bulletA;
			wait(20);}
            count++;
			if (count == 220){DeleteShotAll(TYPE_CHILD, TYPE_ITEM);	}
			
			/// animation
			let speed;
            let dir;
			dir = ObjMove_GetAngle(objEnemy1);
		speed = ObjMove_GetSpeed(objEnemy1);
		
			if(speed == 0){ 
			ObjRender_SetAngleXYZ(objEnemy1,0,0,0);
			if(animFrame < 3) { ObjSprite2D_SetSourceRect(objEnemy1, 0, 0, 137, 106); }
			if(animFrame >= 5 && animFrame < 8) { ObjSprite2D_SetSourceRect(objEnemy1,142,0,283,106); }
			
			animFrame2 = 0;
		}
		else if(cos(dir) < 0){ 
			ObjRender_SetAngleXYZ(objEnemy1,0,0,0);	// flip vertical
			if(animFrame2 < 3) { ObjSprite2D_SetSourceRect(objEnemy1, 280, 0, 410, 106);}
            if(animFrame2 >= 5) { ObjSprite2D_SetSourceRect(objEnemy1, 420, 0, 552, 106); }
			
		}
		else if(cos(dir) > 0){ 
			ObjRender_SetAngleXYZ(objEnemy1,0,180,0);	// flip vertical
			if(animFrame2 < 3) { ObjSprite2D_SetSourceRect(objEnemy1, 280, 0, 410, 106);}
            if(animFrame2 >= 5) { ObjSprite2D_SetSourceRect(objEnemy1, 420, 0, 552, 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(objEnemy1) < Xmin || ObjMove_GetY(objEnemy1) > Xmax || ObjMove_GetY(objEnemy1) < Ymin || ObjMove_GetY(objEnemy1) > Ymax) {
                Obj_Delete(objEnemy1); }

            yield;
        }
		
		
		}
    

		
    
    task bulletA{
	
	if (GetCommonData("Difficulty", 0) == 0){

   let angleT = GetAngleToPlayer(objEnemy1);
   
    
	
     ascent(i in 0..2){
	 wait(5);
	 PlaySE(shootSFX);
        CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT+20,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT,DS_BALL_BS_SKY + i, 5);
        
		
    }
	}
	
		if (GetCommonData("Difficulty", 1) == 1){

   let angleT = GetAngleToPlayer(objEnemy1);
   
    
	
     ascent(i in 0..4){
	 PlaySE(shootSFX);
	 wait(5);
        CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT+20,DS_BALL_BS_SKY + i, 5);
        CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT,DS_BALL_BS_SKY + i, 5);
		
    }
	}
	
			if (GetCommonData("Difficulty", 2) == 2){

   let angleT = GetAngleToPlayer(objEnemy1);
   
    
	
     ascent(i in 0..4){
	 PlaySE(shootSFX);
        CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT-20,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT+20,DS_BALL_BS_SKY + i, 5);
		
        
		
    }
	}
	
	
			if (GetCommonData("Difficulty", 3) == 3){

   let angleT = GetAngleToPlayer(objEnemy1);
   
    
	
     ascent(i in 0..4){
	 PlaySE(shootSFX);
        CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT-20,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT+20,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT-20,DS_BALL_BS_SKY + i, 5);
		CreateShotA1(ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 2.5 - i/2, angleT+20,DS_BALL_BS_SKY + i, 5);
        
		
    }
	}
 }
 
 
 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/eyechart.png";
    ObjPrim_SetTexture(objEnemy1, imgenemy);
    ObjSprite2D_SetSourceRect(objEnemy1, 0, 0, 137, 106);
	ObjRender_SetScaleXYZ(objEnemy1, 0.5, 0.5, 0);
    ObjSprite2D_SetDestCenter(objEnemy1);

	}
    task TFinalize {
        //if(ObjEnemy_GetInfo(objEnemy1, INFO_LIFE) == 0) 
        while(ObjEnemy_GetInfo(objEnemy1, INFO_LIFE) > 0)//this checks if the enemy has still life remaining
        {
            yield;
        }

        if(!Obj_IsDeleted(objEnemy1))//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(objEnemy1);
            DeleteShotInCircle(TYPE_CHILD, TYPE_ITEM, ObjMove_GetX(objEnemy1), ObjMove_GetY(objEnemy1), 200); 
            yield;
        }
    }

}