let checkspell = false;

let sceneObj = GetEnemyBossSceneObjectID;

let CSD = GetCurrentScriptDirectory;
let ns = CSD ~ "img/BG.png";
let nso = CSD ~ "img/BGO.png";
let nso2 = CSD ~ "img/BGO2.png";
let nso3 = CSD ~ "img/BGO3.png";
let s = CSD ~ "img/SBG.png";
let so = CSD ~ "img/SBGO.png";

LoadTexture(ns);
LoadTexture(nso);
LoadTexture(nso3);
LoadTexture(nso2);
LoadTexture(s);
LoadTexture(so);

@Initialize{
	SetStgFrame(0,0,GetScreenWidth,GetScreenHeight,20,80);
	SetPlayerClip(8,16,GetScreenWidth-8,GetScreenHeight-16);
	call;
}

@MainLoop{
	if(sceneObj != ID_INVALID && ObjEnemyBossScene_GetInfo(sceneObj, INFO_IS_SPELL)){
		checkspell = true;
	}

	else{
		checkspell = false;
	}
	yield;
}

task call{
	while(!Obj_IsDeleted(sceneObj)){
	
		if(checkspell == false){
		background;
		}
		
		while(checkspell == false){ yield;}
	
		if(checkspell == true){
		spellbackground;
		}
	
		while(checkspell == true){ yield;}
		yield;
	}
}

task background{
	let slide = 0;
			
			let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
			ObjPrim_SetTexture(obj1,ns);
			Obj_SetRenderPriority(obj1, 0.23);
			ObjRender_SetBlendType(obj1,BLEND_ADD_RGB);
			ObjRender_SetAlpha(obj1,255);
			ObjSprite2D_SetSourceRect(obj1,0,0,512,480);
			ObjSprite2D_SetDestRect(obj1,0,0,512,480);
			ObjSprite2D_SetDestCenter(obj1);
			ObjRender_SetScaleX(obj1,1.25);
			ObjRender_SetScaleY(obj1,1.25);
			ObjRender_SetPosition(obj1,GetStgFrameWidth/2,GetStgFrameHeight/2+60,0);
			
			let obj = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj, 0.24);
			ObjPrim_SetTexture(obj,nso);
			ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
			ObjRender_SetAlpha(obj,225);
			ObjSprite2D_SetSourceRect(obj,0,0,256,256);
			ObjSprite2D_SetDestRect(obj,0,0,256,256);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetScaleXYZ(obj,3,3,3);
			ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
			
			let obj8 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj8, 0.24);
			ObjPrim_SetTexture(obj8,nso);
			ObjRender_SetBlendType(obj8,BLEND_ADD_RGB);
			ObjRender_SetAlpha(obj8,225);
			ObjSprite2D_SetSourceRect(obj8,0,0,640,256);
			ObjSprite2D_SetDestRect(obj8,0,0,640,256);
			ObjSprite2D_SetDestCenter(obj8);
			ObjRender_SetScaleXYZ(obj8,1,1,1);
			ObjRender_SetPosition(obj8,GetStgFrameWidth/2,128,0);
			
			let obj5 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj5, 0.24);
			ObjPrim_SetTexture(obj5,nso3);
			ObjRender_SetAlpha(obj5,255);
			ObjSprite2D_SetSourceRect(obj5,0,0,640,384);
			ObjSprite2D_SetDestRect(obj5,0,0,0,480);
			ObjSprite2D_SetDestCenter(obj5);
			ObjRender_SetScaleXYZ(obj5,1,1,1);
			ObjRender_SetColor(obj5,0,0,1);
			ObjRender_SetPosition(obj5,GetStgFrameWidth/2,GetStgFrameHeight/2+64,0);
			
			let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj2, 0.24);
			ObjPrim_SetTexture(obj2,nso2);
			ObjRender_SetAlpha(obj2,255);
			ObjSprite2D_SetSourceRect(obj2,0,0,640,384);
			ObjSprite2D_SetDestRect(obj2,0,0,0,480);
			ObjSprite2D_SetDestCenter(obj2);
			ObjRender_SetScaleXYZ(obj2,1,1,1);
			ObjRender_SetColor(obj2,0,0,1);
			ObjRender_SetPosition(obj2,GetStgFrameWidth/2,GetStgFrameHeight/2+64,0);
			
			let obj6 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj6, 0.24);
			ObjPrim_SetTexture(obj6,nso3);
			ObjRender_SetAlpha(obj6,255);
			ObjSprite2D_SetSourceRect(obj6,-128,0,640,384);
			ObjSprite2D_SetDestRect(obj6,-128,0,640,480);
			ObjSprite2D_SetDestCenter(obj6);
			ObjRender_SetScaleXYZ(obj6,1.2,1.2,1.2);
			ObjRender_SetAngleY(obj6,180);
			ObjRender_SetColor(obj6,32,32,32);
			ObjRender_SetPosition(obj6,GetStgFrameWidth/2-26,GetStgFrameHeight/2+64,0);
			
			let obj3 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj3, 0.24);
			ObjPrim_SetTexture(obj3,nso2);
			ObjRender_SetAlpha(obj3,255);
			ObjSprite2D_SetSourceRect(obj3,-128,0,640,384);
			ObjSprite2D_SetDestRect(obj3,-128,0,640,480);
			ObjSprite2D_SetDestCenter(obj3);
			ObjRender_SetScaleXYZ(obj3,1.2,1.2,1.2);
			ObjRender_SetColor(obj3,32,32,32);
			ObjRender_SetPosition(obj3,GetStgFrameWidth/2+128,GetStgFrameHeight/2+64,0);
			
			let obj7 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj7, 0.24);
			ObjPrim_SetTexture(obj7,nso3);
			ObjRender_SetAlpha(obj7,255);
			ObjSprite2D_SetSourceRect(obj7,-256,0,640,384);
			ObjSprite2D_SetDestRect(obj7,-256,0,640,480);
			ObjSprite2D_SetDestCenter(obj7);
			ObjRender_SetScaleXYZ(obj7,1.4,1.4,1.4);
			ObjRender_SetColor(obj7,64,64,64);
			ObjRender_SetPosition(obj7,GetStgFrameWidth/2+128,GetStgFrameHeight/2+64,0);
			
			let obj4 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj4, 0.24);
			ObjPrim_SetTexture(obj4,nso2);
			ObjRender_SetAlpha(obj4,255);
			ObjSprite2D_SetSourceRect(obj4,-256,0,640,384);
			ObjSprite2D_SetDestRect(obj4,-256,0,640,480);
			ObjSprite2D_SetDestCenter(obj4);
			ObjRender_SetScaleXYZ(obj4,1.4,1.4,1.4);
			ObjRender_SetColor(obj4,64,64,64);
			ObjRender_SetPosition(obj4,GetStgFrameWidth/2+128,GetStgFrameHeight/2+64,0);
			
		while(checkspell == false && !Obj_IsDeleted(GetEnemyBossObjectID)){
			
			ObjRender_SetAlpha(obj,255);
			ObjSprite2D_SetSourceRect(obj,0+slide,0,256+slide,256);	
			ObjSprite2D_SetSourceRect(obj8,0+slide*1.5,0,640+slide*1.5,256);	
			ObjSprite2D_SetSourceRect(obj2,0+slide/3,0,640+slide/3,480);	
			ObjSprite2D_SetSourceRect(obj3,-128+slide/2,0,640+slide/2,480);	
			ObjSprite2D_SetSourceRect(obj4,-256+slide,0,640+slide,480);	
			ObjSprite2D_SetSourceRect(obj5,0+slide/3,0,640+slide/3,480);	
			ObjSprite2D_SetSourceRect(obj6,-128-slide/2,0,640-slide/2,480);	
			ObjSprite2D_SetSourceRect(obj7,-256+slide,0,640+slide,480);	
			
			slide+=3;
			yield;
		}
	Obj_Delete(obj);
	Obj_Delete(obj1);
	Obj_Delete(obj2);
	Obj_Delete(obj3);
	Obj_Delete(obj4);
	Obj_Delete(obj5);
	Obj_Delete(obj6);
	Obj_Delete(obj7);
	Obj_Delete(obj8);
	yield;
}

//Rainbow Background Code Made By TalosMistake. Thanks!
task spellbackground{

	let slide = 0;
	let down = 255;
	let c = 0;
	let d = 0;
			
			let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj1, 0.24);
			ObjPrim_SetTexture(obj1,so);
			ObjSprite2D_SetSourceRect(obj1,0,0,640,480);
			ObjSprite2D_SetDestRect(obj1,0,0,640,480);
			ObjRender_SetAlpha(obj1,255);
			ObjSprite2D_SetDestCenter(obj1);
			ObjRender_SetScaleXYZ(obj1,1.25,1.25,1);
			ObjRender_SetPosition(obj1,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
		
			let obj = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj, 0.23);
			ObjPrim_SetTexture(obj,s);
			ObjSprite2D_SetSourceRect(obj,0,0,384,448);
			ObjSprite2D_SetDestRect(obj,0,0,384,448);
			ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
			ObjRender_SetAlpha(obj,255);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetScaleXYZ(obj,1.7,1.1,1);
			ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
			
		while(checkspell == true && !Obj_IsDeleted(GetEnemyBossObjectID)){
	
			ObjSprite2D_SetSourceRect(obj1,0,0+slide,640,480+slide);
			if(c<60){d+=1;}
			ObjRender_SetColor(obj1,d*1.5+60*sin(c),d*1.5+60*sin(c+120),d*1.5+60*sin(c+240));
			c++;

			slide+=0.5;
			yield;
		}
	Obj_Delete(obj);
	Obj_Delete(obj1);
	yield;
}