task CreateStageEnemy2(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 objEnemy3 = ObjEnemy_Create(OBJ_ENEMY);
    TInitialize;
   task TInitialize 
    {
        LoadSound(shootSFX);

        LoadSound(deadSFX);

        
        ObjEnemy_Regist(objEnemy3);
        ObjEnemy_SetLife(objEnemy3, 400);
        
        ObjEnemy_SetDamageRate(objEnemy3, 200, 200);
        ObjMove_SetPosition(objEnemy3, x, y);
        ObjMove_SetAngle(objEnemy3, angleE);
        ObjMove_SetSpeed(objEnemy3, speedE);
        ObjMove_SetDestAtSpeed(objEnemy3, x , 150, 3); //movement function
        TDrawLoop;
        TMainLoop;
        TFinalize;
        wait(150);
        
        let e_dir = GetAngleToPlayer(objEnemy3) > 192;
        ObjMove_AddPatternA2(objEnemy3, 0, 0, 90, 6/120, 0, 6);
        
        //TFinalize;
    }
	function GetEnemyX{
return ObjMove_GetX(objEnemy3);
}
	function GetEnemyY{
return ObjMove_GetY(objEnemy3);
}

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

     task TMainLoop {
        while(ObjEnemy_GetInfo(objEnemy3, INFO_LIFE) > 0) {
            ObjEnemy_SetIntersectionCircleToShot(objEnemy3, ObjMove_GetX(objEnemy3), ObjMove_GetY(objEnemy3), 32); 
            ObjEnemy_SetIntersectionCircleToPlayer(objEnemy3, ObjMove_GetX(objEnemy3), ObjMove_GetY(objEnemy3), 8);
            if (count % 60 == 30) {bulletA;}
            count++;
			if (count == 220){DeleteShotAll(TYPE_CHILD, TYPE_ITEM);	}
			
			/// animation
			let speed;
            let dir;
			dir = ObjMove_GetAngle(objEnemy3);
		speed = ObjMove_GetSpeed(objEnemy3);
		
			if(speed == 0){ 
			ObjRender_SetAngleXYZ(objEnemy3,0,0,0);
			if(animFrame < 5) { ObjSprite2D_SetSourceRect(objEnemy3, 0, 0, 116, 120);}
			if(animFrame >= 10) { ObjSprite2D_SetSourceRect(objEnemy3,119,0,240,125); }
            
			
			animFrame2 = 0;
		}
		else if(cos(dir) < 0){ 
			ObjRender_SetAngleXYZ(objEnemy3,0,180,0);	// flip vertical
			
            if(animFrame2 >= 2) { ObjSprite2D_SetSourceRect(objEnemy3,250,0,340,120); }
			
		}
		else if(cos(dir) > 0){ 
			ObjRender_SetAngleXYZ(objEnemy3,0,0,0);	// flip vertical
			if(animFrame2 >= 2) { ObjSprite2D_SetSourceRect(objEnemy3,250,0,340,120); }
		}
		animFrame++;		// count animFrame. (++ is +1)
		animFrame2+=2;		// count animFrame2.
		if(animFrame > 12) { animFrame = 0; }	// reset animFrame when it is higher than 18.
		yield;
		
		            if (ObjMove_GetX(objEnemy3) < Xmin || ObjMove_GetY(objEnemy3) > Xmax || ObjMove_GetY(objEnemy3) < Ymin || ObjMove_GetY(objEnemy3) > Ymax) {
                Obj_Delete(objEnemy3); }

            yield;
        }
		
		
		}
    

		
    
task bulletA{

let angleT = GetAngleToPlayer(objEnemy3);
 
loop(10){
 ascent(i in 0..5){
 PlaySE(shootSFX);
 let obj = CreateShotA2(GetEnemyX, GetEnemyY, 3, angleT, 0.01, 4,DS_STAR_S_SKY, 5);
		
			
			angleT += 360/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/ghost1.png";
    ObjPrim_SetTexture(objEnemy3, imgenemy);
    ObjSprite2D_SetSourceRect(objEnemy3, 0, 0, 108, 120);
	ObjRender_SetScaleXYZ(objEnemy3, 0.5, 0.5, 0);
    ObjSprite2D_SetDestCenter(objEnemy3);
	}

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

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

task CreateStageEnemy1(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, 400);
        
        ObjEnemy_SetDamageRate(objEnemy1, 200, 200);
        ObjMove_SetPosition(objEnemy1, x, y);
        ObjMove_SetAngle(objEnemy1, angleE);
        ObjMove_SetSpeed(objEnemy1, speedE);
        ObjMove_SetDestAtSpeed(objEnemy1, x , 150, 3); //movement function
        TDrawLoop;
        TMainLoop;
        TFinalize;
        wait(150);
        
        let e_dir = GetAngleToPlayer(objEnemy1) > 192;
        ObjMove_AddPatternA2(objEnemy1, 0, 0, 90, 6/120, 0, 6);
        
        //TFinalize;
    }
	function GetEnemyX{
return ObjMove_GetX(objEnemy1);
}
	function GetEnemyY{
return ObjMove_GetY(objEnemy1);
}

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

     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 == 30) {bulletA;}
            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 < 5) { ObjSprite2D_SetSourceRect(objEnemy1, 0, 0, 116, 120);}
			if(animFrame >= 10) { ObjSprite2D_SetSourceRect(objEnemy1,119,0,240,125); }
            
			
			animFrame2 = 0;
		}
		else if(cos(dir) < 0){ 
			ObjRender_SetAngleXYZ(objEnemy1,0,180,0);	// flip vertical
			
            if(animFrame2 >= 2) { ObjSprite2D_SetSourceRect(objEnemy1,250,0,340,120); }
			
		}
		else if(cos(dir) > 0){ 
			ObjRender_SetAngleXYZ(objEnemy1,0,0,0);	// flip vertical
			if(animFrame2 >= 2) { ObjSprite2D_SetSourceRect(objEnemy1,250,0,340,120); }
		}
		animFrame++;		// count animFrame. (++ is +1)
		animFrame2+=2;		// count animFrame2.
		if(animFrame > 12) { 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{

let angleT = GetAngleToPlayer(objEnemy1);
 
loop(10){
 ascent(i in 0..5){
 PlaySE(shootSFX);
 let obj = CreateShotA2(GetEnemyX, GetEnemyY, 3, angleT, 0.01, 4,DS_STAR_S_RED , 5);
		
			
			angleT += 360/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/ghost2.png";
    ObjPrim_SetTexture(objEnemy1, imgenemy);
    ObjSprite2D_SetSourceRect(objEnemy1, 0, 0, 108, 120);
	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), 80);
            yield;
        }
    }
	}
	
		
//---------------------------------------------

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 objEnemy2 = ObjEnemy_Create(OBJ_ENEMY);
    TInitialize;
   task TInitialize 
    {
        LoadSound(shootSFX);

        LoadSound(deadSFX);

        
        ObjEnemy_Regist(objEnemy2);
        ObjEnemy_SetLife(objEnemy2, 400);
        
        ObjEnemy_SetDamageRate(objEnemy2, 200, 200);
        ObjMove_SetPosition(objEnemy2, x, y);
        ObjMove_SetAngle(objEnemy2, angleE);
        ObjMove_SetSpeed(objEnemy2, speedE);
        ObjMove_SetDestAtSpeed(objEnemy2, x , 150, 3); //movement function
        TDrawLoop;
        TMainLoop;
        TFinalize;
        wait(150);
        
        let e_dir = GetAngleToPlayer(objEnemy2) > 192;
        ObjMove_AddPatternA2(objEnemy2, 0, 0, 90, 6/120, 0, 6);
        
        //TFinalize;
    }
	function GetEnemyX{
return ObjMove_GetX(objEnemy2);
}
	function GetEnemyY{
return ObjMove_GetY(objEnemy2);
}

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

     task TMainLoop {
        while(ObjEnemy_GetInfo(objEnemy2, INFO_LIFE) > 0) {
            ObjEnemy_SetIntersectionCircleToShot(objEnemy2, ObjMove_GetX(objEnemy2), ObjMove_GetY(objEnemy2), 32); 
            ObjEnemy_SetIntersectionCircleToPlayer(objEnemy2, ObjMove_GetX(objEnemy2), ObjMove_GetY(objEnemy2), 8);
            if (count % 60 == 30) {bulletA;}
            count++;
			if (count == 220){DeleteShotAll(TYPE_CHILD, TYPE_ITEM);	}
			
			/// animation
			let speed;
            let dir;
			dir = ObjMove_GetAngle(objEnemy2);
		speed = ObjMove_GetSpeed(objEnemy2);
		
			if(speed == 0){ 
			ObjRender_SetAngleXYZ(objEnemy2,0,0,0);
			if(animFrame < 5) { ObjSprite2D_SetSourceRect(objEnemy2, 0, 0, 116, 120);}
			if(animFrame >= 10) { ObjSprite2D_SetSourceRect(objEnemy2,119,0,240,125); }
            
			
			animFrame2 = 0;
		}
		else if(cos(dir) < 0){ 
			ObjRender_SetAngleXYZ(objEnemy2,0,180,0);	// flip vertical
			
            if(animFrame2 >= 2) { ObjSprite2D_SetSourceRect(objEnemy2,250,0,340,120); }
			
		}
		else if(cos(dir) > 0){ 
			ObjRender_SetAngleXYZ(objEnemy2,0,0,0);	// flip vertical
			if(animFrame2 >= 2) { ObjSprite2D_SetSourceRect(objEnemy2,250,0,340,120); }
		}
		animFrame++;		// count animFrame. (++ is +1)
		animFrame2+=2;		// count animFrame2.
		if(animFrame > 12) { animFrame = 0; }	// reset animFrame when it is higher than 18.
		yield;
		
		            if (ObjMove_GetX(objEnemy2) < Xmin || ObjMove_GetY(objEnemy2) > Xmax || ObjMove_GetY(objEnemy2) < Ymin || ObjMove_GetY(objEnemy2) > Ymax) {
                Obj_Delete(objEnemy2); }

            yield;
        }
		
		
		}
    

		
    
task bulletA{

let angleT = GetAngleToPlayer(objEnemy2);
 
loop(10){
 ascent(i in 0..5){
 PlaySE(shootSFX);
 let obj = CreateShotA2(GetEnemyX, GetEnemyY, 3, angleT, 0.01, 4,DS_STAR_S_YELLOW, 5);
		
			
			angleT += 360/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/ghost3.png";
    ObjPrim_SetTexture(objEnemy2, imgenemy);
    ObjSprite2D_SetSourceRect(objEnemy2, 0, 0, 108, 120);
	ObjRender_SetScaleXYZ(objEnemy2, 0.5, 0.5, 0);
    ObjSprite2D_SetDestCenter(objEnemy2);
	}

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

        if(!Obj_IsDeleted(objEnemy2))//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(objEnemy2);
            DeleteShotInCircle(TYPE_CHILD, TYPE_ITEM, ObjMove_GetX(objEnemy2), ObjMove_GetY(objEnemy2), 80);
            yield;
        }
    }
	}
	
	
	//---------------------
	
	
	task CreateStageEnemy8(x, y, speedE, angleE) {
let shootSFX = GetCurrentScriptDirectory ~ "SFX/TWINKLE.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 objEnemy3 = ObjEnemy_Create(OBJ_ENEMY);
    TInitialize;
   task TInitialize 
    {
        LoadSound(shootSFX);

        LoadSound(deadSFX);

        
        ObjEnemy_Regist(objEnemy3);
        ObjEnemy_SetLife(objEnemy3, 400);
        
        ObjEnemy_SetDamageRate(objEnemy3, 200, 200);
        ObjMove_SetPosition(objEnemy3, x, y);
        ObjMove_SetAngle(objEnemy3, angleE);
        ObjMove_SetSpeed(objEnemy3, speedE);
        ObjMove_SetDestAtSpeed(objEnemy3, x , 150, 3); //movement function
        TDrawLoop;
        TMainLoop;
        TFinalize;
        wait(150);
        
        let e_dir = GetAngleToPlayer(objEnemy3) > 192;
        ObjMove_AddPatternA2(objEnemy3, 0, 0, 180, 6/120, 0, 6);
        
        //TFinalize;
    }
	function GetEnemyX{
return ObjMove_GetX(objEnemy3);
}
	function GetEnemyY{
return ObjMove_GetY(objEnemy3);
}

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

     task TMainLoop {
        while(ObjEnemy_GetInfo(objEnemy3, INFO_LIFE) > 0) {
            ObjEnemy_SetIntersectionCircleToShot(objEnemy3, ObjMove_GetX(objEnemy3), ObjMove_GetY(objEnemy3), 32); 
            ObjEnemy_SetIntersectionCircleToPlayer(objEnemy3, ObjMove_GetX(objEnemy3), ObjMove_GetY(objEnemy3), 8);
            if (count % 10 == 1) {bulletA; wait(5);
			bulletA;
			wait(5);
			bulletA;
			wait(5);
			bulletA;
			wait(5);
			bulletA;}
            count++;
			if (count == 220){DeleteShotAll(TYPE_CHILD, TYPE_ITEM);	}
			
			/// animation
			let speed;
            let dir;
			dir = ObjMove_GetAngle(objEnemy3);
		speed = ObjMove_GetSpeed(objEnemy3);
		
			if(speed == 0){ 
			ObjRender_SetAngleXYZ(objEnemy3,0,0,0);
			if(animFrame < 5) { ObjSprite2D_SetSourceRect(objEnemy3, 0, 0, 116, 120);}
			if(animFrame >= 10) { ObjSprite2D_SetSourceRect(objEnemy3,119,0,240,125); }
            
			
			animFrame2 = 0;
		}
		else if(cos(dir) < 0){ 
			ObjRender_SetAngleXYZ(objEnemy3,0,0,0);	// flip vertical
			
            if(animFrame2 >= 2) { ObjSprite2D_SetSourceRect(objEnemy3,250,0,340,120); }
			
		}
		else if(cos(dir) > 0){ 
			ObjRender_SetAngleXYZ(objEnemy3,0,180,0);	// flip vertical
			if(animFrame2 >= 2) { ObjSprite2D_SetSourceRect(objEnemy3,250,0,340,120); }
		}
		animFrame++;		// count animFrame. (++ is +1)
		animFrame2+=2;		// count animFrame2.
		if(animFrame > 12) { animFrame = 0; }	// reset animFrame when it is higher than 18.
		yield;
		
		            if (ObjMove_GetX(objEnemy3) < Xmin || ObjMove_GetY(objEnemy3) > Xmax || ObjMove_GetY(objEnemy3) < Ymin || ObjMove_GetY(objEnemy3) > Ymax) {
                Obj_Delete(objEnemy3); }

            yield;
        }
		
		
		}
    

		
    
task bulletA{

let angleT = GetAngleToPlayer(objEnemy3);
 


 PlaySE(shootSFX);
 let obj = CreateShotA2(GetEnemyX, GetEnemyY, 3, angleT, 0.01, 4,DS_STAR_S_SKY, 5);
 CreateShotA2(GetEnemyX, GetEnemyY, 3, angleT, 0.01, 4,DS_STAR_S_SKY, 10);
 CreateShotA2(GetEnemyX, GetEnemyY, 3, angleT, 0.01, 4,DS_STAR_S_SKY, 15);
		
			
	


}
	
 
 
 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/ghost1.png";
    ObjPrim_SetTexture(objEnemy3, imgenemy);
    ObjSprite2D_SetSourceRect(objEnemy3, 0, 0, 108, 120);
	ObjRender_SetScaleXYZ(objEnemy3, 0.5, 0.5, 0);
    ObjSprite2D_SetDestCenter(objEnemy3);
	}

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

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

task CreateStageEnemy7(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, 400);
        
        ObjEnemy_SetDamageRate(objEnemy1, 200, 200);
        ObjMove_SetPosition(objEnemy1, x, y);
        ObjMove_SetAngle(objEnemy1, angleE);
        ObjMove_SetSpeed(objEnemy1, speedE);
        ObjMove_SetDestAtSpeed(objEnemy1, x , 150, 3); //movement function
        TDrawLoop;
        TMainLoop;
        TFinalize;
        wait(150);
        
        let e_dir = GetAngleToPlayer(objEnemy1) > 192;
        ObjMove_AddPatternA2(objEnemy1, 0, 0, 180, 6/120, 0, 6);
        
        //TFinalize;
    }
	function GetEnemyX{
return ObjMove_GetX(objEnemy1);
}
	function GetEnemyY{
return ObjMove_GetY(objEnemy1);
}

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

     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 == 30) {bulletA;}
            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 < 5) { ObjSprite2D_SetSourceRect(objEnemy1, 0, 0, 116, 120);}
			if(animFrame >= 10) { ObjSprite2D_SetSourceRect(objEnemy1,119,0,240,125); }
            
			
			animFrame2 = 0;
		}
		else if(cos(dir) < 0){ 
			ObjRender_SetAngleXYZ(objEnemy1,0,0,0);	// flip vertical
			
            if(animFrame2 >= 2) { ObjSprite2D_SetSourceRect(objEnemy1,250,0,340,120); }
			
		}
		else if(cos(dir) > 0){ 
			ObjRender_SetAngleXYZ(objEnemy1,0,180,0);	// flip vertical
			if(animFrame2 >= 2) { ObjSprite2D_SetSourceRect(objEnemy1,250,0,340,120); }
		}
		animFrame++;		// count animFrame. (++ is +1)
		animFrame2+=2;		// count animFrame2.
		if(animFrame > 12) { 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{

let angleT = GetAngleToPlayer(objEnemy1);
 
loop(10){
 ascent(i in 0..5){
 PlaySE(shootSFX);
 let obj = CreateShotA2(GetEnemyX, GetEnemyY, 3, angleT, 0.01, 4,DS_STAR_S_RED , 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/ghost2.png";
    ObjPrim_SetTexture(objEnemy1, imgenemy);
    ObjSprite2D_SetSourceRect(objEnemy1, 0, 0, 108, 120);
	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), 80);
            yield;
        }
    }
	}
	
		
//---------------------------------------------

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

        LoadSound(deadSFX);

        
        ObjEnemy_Regist(objEnemy2);
        ObjEnemy_SetLife(objEnemy2, 400);
        
        ObjEnemy_SetDamageRate(objEnemy2, 200, 200);
        ObjMove_SetPosition(objEnemy2, x, y);
        ObjMove_SetAngle(objEnemy2, angleE);
        ObjMove_SetSpeed(objEnemy2, speedE);
        ObjMove_SetDestAtSpeed(objEnemy2, x , 150, 3); //movement function
        TDrawLoop;
        TMainLoop;
        TFinalize;
        wait(150);
        
        let e_dir = GetAngleToPlayer(objEnemy2) > 192;
        ObjMove_AddPatternA2(objEnemy2, 0, 0, 180, 6/120, 0, 6);
        
        //TFinalize;
    }
	function GetEnemyX{
return ObjMove_GetX(objEnemy2);
}
	function GetEnemyY{
return ObjMove_GetY(objEnemy2);
}

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

     task TMainLoop {
        while(ObjEnemy_GetInfo(objEnemy2, INFO_LIFE) > 0) {
            ObjEnemy_SetIntersectionCircleToShot(objEnemy2, ObjMove_GetX(objEnemy2), ObjMove_GetY(objEnemy2), 32); 
            ObjEnemy_SetIntersectionCircleToPlayer(objEnemy2, ObjMove_GetX(objEnemy2), ObjMove_GetY(objEnemy2), 8);
            if (count % 60 == 30) {bulletA;}
            count++;
			if (count == 220){DeleteShotAll(TYPE_CHILD, TYPE_ITEM);	}
			
			/// animation
			let speed;
            let dir;
			dir = ObjMove_GetAngle(objEnemy2);
		speed = ObjMove_GetSpeed(objEnemy2);
		
			if(speed == 0){ 
			ObjRender_SetAngleXYZ(objEnemy2,0,0,0);
			if(animFrame < 5) { ObjSprite2D_SetSourceRect(objEnemy2, 0, 0, 116, 120);}
			if(animFrame >= 10) { ObjSprite2D_SetSourceRect(objEnemy2,119,0,240,125); }
            
			
			animFrame2 = 0;
		}
		else if(cos(dir) < 0){ 
			ObjRender_SetAngleXYZ(objEnemy2,0,0,0);	// flip vertical
			
            if(animFrame2 >= 2) { ObjSprite2D_SetSourceRect(objEnemy2,250,0,340,120); }
			
		}
		else if(cos(dir) > 0){ 
			ObjRender_SetAngleXYZ(objEnemy2,0,180,0);	// flip vertical
			if(animFrame2 >= 2) { ObjSprite2D_SetSourceRect(objEnemy2,250,0,340,120); }
		}
		animFrame++;		// count animFrame. (++ is +1)
		animFrame2+=2;		// count animFrame2.
		if(animFrame > 12) { animFrame = 0; }	// reset animFrame when it is higher than 18.
		yield;
		
		            if (ObjMove_GetX(objEnemy2) < Xmin || ObjMove_GetY(objEnemy2) > Xmax || ObjMove_GetY(objEnemy2) < Ymin || ObjMove_GetY(objEnemy2) > Ymax) {
                Obj_Delete(objEnemy2); }

            yield;
        }
		
		
		}
    

		
    
task bulletA{

let angleT = GetAngleToPlayer(objEnemy2);
 
loop(10){
 ascent(i in 0..5){
 PlaySE(shootSFX);
 let obj = CreateShotA2(GetEnemyX, GetEnemyY, 3, angleT, 0.01, 4,DS_STAR_S_YELLOW, 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/ghost3.png";
    ObjPrim_SetTexture(objEnemy2, imgenemy);
    ObjSprite2D_SetSourceRect(objEnemy2, 0, 0, 108, 120);
	ObjRender_SetScaleXYZ(objEnemy2, 0.5, 0.5, 0);
    ObjSprite2D_SetDestCenter(objEnemy2);
	}

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

        if(!Obj_IsDeleted(objEnemy2))//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(objEnemy2);
            DeleteShotInCircle(TYPE_CHILD, TYPE_ITEM, ObjMove_GetX(objEnemy2), ObjMove_GetY(objEnemy2), 80);
            yield;
        }
    }
	}
	
	
	
	
	
	
	
	
	
	//------------------------------------
	
	
	task CreateStageEnemy4(x, y, speedE, angleE) {
let shootSFX = GetCurrentScriptDirectory ~ "SFX/PINGAS.mp3";
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 objEnemy2 = ObjEnemy_Create(OBJ_ENEMY);
    TInitialize;
    task TInitialize 
    {
        LoadSound(shootSFX);
        
        LoadSound(deadSFX);
        
        
        ObjEnemy_Regist(objEnemy2);
        ObjEnemy_SetLife(objEnemy2, 1000);
        
        ObjEnemy_SetDamageRate(objEnemy2, 200, 200);
        ObjMove_SetPosition(objEnemy2, x, y);
        ObjMove_SetAngle(objEnemy2, angleE);
        ObjMove_SetSpeed(objEnemy2, speedE);
        ObjMove_SetDestAtSpeed(objEnemy2, x , 150, 3); //movement function
        TDrawLoop;
        TMainLoop;
        TFinalize;
        wait(500);
        
        let e_dir = GetAngleToPlayer(objEnemy2) > 192;
        ObjMove_AddPatternA2(objEnemy2, 0, 0, 180, 6/120, 0, 6);
        
        //TFinalize;
    }
	function GetEnemyX{
return ObjMove_GetX(objEnemy2);
}
	function GetEnemyY{
return ObjMove_GetY(objEnemy2);
}
     task TMainLoop {
        while(ObjEnemy_GetInfo(objEnemy2, INFO_LIFE) > 0) {
            ObjEnemy_SetIntersectionCircleToShot(objEnemy2, ObjMove_GetX(objEnemy2), ObjMove_GetY(objEnemy2), 32); 
            ObjEnemy_SetIntersectionCircleToPlayer(objEnemy2, ObjMove_GetX(objEnemy2), ObjMove_GetY(objEnemy2), 8);
            if (count % 60 == 30) {bulletA;
			wait(10);
			bulletA;
			wait(10);
			bulletA;
			wait(10);
			bulletA;}
			
            count++;
			if (count == 300){DeleteShotAll(TYPE_CHILD, TYPE_ITEM);	}
			
			/// animation
			let speed;
            let dir;
			dir = ObjMove_GetAngle(objEnemy2);
		speed = ObjMove_GetSpeed(objEnemy2);
		
			if(speed == 0){ 
			ObjRender_SetAngleXYZ(objEnemy2,0,0,0);
			if(animFrame < 3) { ObjSprite2D_SetSourceRect(objEnemy2, 0, 0, 200, 170); }
			if(animFrame >= 5 && animFrame < 8) { ObjSprite2D_SetSourceRect(objEnemy2,0,0,200,170); }
			
			animFrame2 = 0;
		}
		
		animFrame++;		// count animFrame. (++ is +1)
	
		if(animFrame > 18) { animFrame = 0; }	// reset animFrame when it is higher than 18.
		yield;
		
		            if (ObjMove_GetX(objEnemy2) < Xmin || ObjMove_GetY(objEnemy2) > Xmax || ObjMove_GetY(objEnemy2) < Ymin || ObjMove_GetY(objEnemy2) > Ymax) {
                Obj_Delete(objEnemy2); }

            yield;
        }
		
		
		}
    

		
    
    task bulletA{
	

  let angleT = 90;
   
     ascent(i in 0..90){
	 PlaySE(shootSFX);
        CreateShotA1(GetEnemyX, GetEnemyY, 2 , angleT, DS_KNIFE_YOUMU_ORANGE, 0);
		angleT += 360/20;
		
 }
 }
 
 
 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/robotnik.png";
    ObjPrim_SetTexture(objEnemy2, imgenemy);
    ObjSprite2D_SetSourceRect(objEnemy2, 0, 0, 200, 200);
	ObjRender_SetScaleXYZ(objEnemy2, 0.5, 0.5, 0);
    ObjSprite2D_SetDestCenter(objEnemy2);
	}
    task TFinalize 
    {
        //if(ObjEnemy_GetInfo(objEnemy2, INFO_LIFE) == 0) 
        while(ObjEnemy_GetInfo(objEnemy2, INFO_LIFE) > 0)//this checks if the enemy has still life remaining
        {
            yield;
        }

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

}


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



task CreateStageEnemy44(x, y, speedE, angleE) {
let shootSFX = GetCurrentScriptDirectory ~ "SFX/DINNER.mp3";
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 objEnemy2 = ObjEnemy_Create(OBJ_ENEMY);
    TInitialize;
    task TInitialize 
    {
        LoadSound(shootSFX);
        
        LoadSound(deadSFX);
        
        
        ObjEnemy_Regist(objEnemy2);
        ObjEnemy_SetLife(objEnemy2, 1000);
        
        ObjEnemy_SetDamageRate(objEnemy2, 200, 200);
        ObjMove_SetPosition(objEnemy2, x, y);
        ObjMove_SetAngle(objEnemy2, angleE);
        ObjMove_SetSpeed(objEnemy2, speedE);
        ObjMove_SetDestAtSpeed(objEnemy2, x , 150, 3); //movement function
        TDrawLoop;
        TMainLoop;
        TFinalize;
        wait(500);
        
        let e_dir = GetAngleToPlayer(objEnemy2) > 192;
        ObjMove_AddPatternA2(objEnemy2, 0, 0, 180, 6/120, 0, 6);
        
        //TFinalize;
    }
	function GetEnemyX{
return ObjMove_GetX(objEnemy2);
}
	function GetEnemyY{
return ObjMove_GetY(objEnemy2);
}
     task TMainLoop {
        while(ObjEnemy_GetInfo(objEnemy2, INFO_LIFE) > 0) {
            ObjEnemy_SetIntersectionCircleToShot(objEnemy2, ObjMove_GetX(objEnemy2), ObjMove_GetY(objEnemy2), 32); 
            ObjEnemy_SetIntersectionCircleToPlayer(objEnemy2, ObjMove_GetX(objEnemy2), ObjMove_GetY(objEnemy2), 8);
            if (count % 60 == 30) {bulletA;
			wait(10);
			}
			
            count++;
			if (count == 300){DeleteShotAll(TYPE_CHILD, TYPE_ITEM);	}
			
			/// animation
			let speed;
            let dir;
			dir = ObjMove_GetAngle(objEnemy2);
		speed = ObjMove_GetSpeed(objEnemy2);
		
			if(speed == 0){ 
			ObjRender_SetAngleXYZ(objEnemy2,0,0,0);
			if(animFrame < 3) { ObjSprite2D_SetSourceRect(objEnemy2, 0, 0, 200, 170); }
			if(animFrame >= 5 && animFrame < 8) { ObjSprite2D_SetSourceRect(objEnemy2,0,0,200,170); }
			
			animFrame2 = 0;
		}
		
		animFrame++;		// count animFrame. (++ is +1)
	
		if(animFrame > 18) { animFrame = 0; }	// reset animFrame when it is higher than 18.
		yield;
		
		            if (ObjMove_GetX(objEnemy2) < Xmin || ObjMove_GetY(objEnemy2) > Xmax || ObjMove_GetY(objEnemy2) < Ymin || ObjMove_GetY(objEnemy2) > Ymax) {
                Obj_Delete(objEnemy2); }

            yield;
        }
		
		
		}
    

		
    
    task bulletA{
	

  let angleT = 90;
   
     ascent(i in 0..90){
	 PlaySE(shootSFX);
        CreateShotA1(GetEnemyX, GetEnemyY, 2 , angleT, DS_COIN_YELLOW, 0);
		angleT += 360/50;
		
		
 }
 }
 
 
 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/king.png";
    ObjPrim_SetTexture(objEnemy2, imgenemy);
    ObjSprite2D_SetSourceRect(objEnemy2, 0, 0, 80, 80);
	ObjRender_SetScaleXYZ(objEnemy2, 1, 1, 0);
    ObjSprite2D_SetDestCenter(objEnemy2);
	}
    task TFinalize 
    {
        //if(ObjEnemy_GetInfo(objEnemy2, INFO_LIFE) == 0) 
        while(ObjEnemy_GetInfo(objEnemy2, INFO_LIFE) > 0)//this checks if the enemy has still life remaining
        {
            yield;
        }

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

}
	