let checkspell = false;

let sceneObj = GetEnemyBossSceneObjectID;

let lay = GetCurrentScriptDirectory ~ "IMG/Lay.png";
let lay1 = GetCurrentScriptDirectory ~ "IMG/Lay 1.png";
let lay2 = GetCurrentScriptDirectory ~ "IMG/Lay 2.png";
let bg = GetCurrentScriptDirectory ~ "IMG/BG.png";
let slay = GetCurrentScriptDirectory ~ "IMG/sclay.png";
let slay1 = GetCurrentScriptDirectory ~ "IMG/sclay1.png";
let sbg = GetCurrentScriptDirectory ~ "IMG/scbg.png";

LoadTexture(lay);
LoadTexture(lay1);
LoadTexture(bg);
LoadTexture(slay);
LoadTexture(slay1);
LoadTexture(sbg);

@Initialize{
	SetCameraFocusX(180);
	SetCameraFocusY(0);
	SetCameraFocusZ(0);
	SetCameraRadius(500);
	SetCameraElevationAngle(220);
	SetCameraAzimuthAngle(90);
	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 down = 255;
	let angleX = 10*cos(slide/4);
	let angleY = 20*cos(slide/6);
	let angleZ = 10*cos(slide/4);
	
			let obj = ObjPrim_Create(OBJ_SPRITE_3D);
			Obj_SetRenderPriority(obj, 0.21);
			ObjPrim_SetTexture(obj,bg);
			ObjRender_SetBlendType(obj,BLEND_ALPHA);
			ObjRender_SetAlpha(obj,255-slide/9);
			ObjSprite3D_SetSourceRect(obj,0,0,1024,1280);
			ObjSprite3D_SetSourceDestRect(obj,0,0,1024,1280+slide*2);
			ObjRender_SetScaleXYZ(obj,1.25,1,1);
			ObjRender_SetPosition(obj,GetStgFrameWidth/2-16,GetStgFrameHeight/2,0);
			
			let obj1 = ObjPrim_Create(OBJ_SPRITE_3D);
			Obj_SetRenderPriority(obj1, 0.23);
			ObjPrim_SetTexture(obj1,lay);
			ObjRender_SetBlendType(obj1,BLEND_ALPHA);
			ObjRender_SetAlpha(obj1,255-slide/9);
			ObjSprite3D_SetDestRect(obj1,0,0,-512-slide*3,-2560-slide*3);
			ObjSprite3D_SetSourceRect(obj1,0,0,-512-slide*3,-2560-slide*3);
			ObjSprite3D_SetSourceDestRect(obj1,0,0,-512-slide*3,-2560-slide*3);
			ObjRender_SetColor(obj1,105,10,65);
			ObjRender_SetScaleX(obj1,1);
			ObjRender_SetScaleY(obj1,1);
			ObjRender_SetPosition(obj1,GetStgFrameWidth/2,GetStgFrameHeight/2,100);
			
			let obj2 = ObjPrim_Create(OBJ_SPRITE_3D);
			Obj_SetRenderPriority(obj2, 0.22);
			ObjPrim_SetTexture(obj2,lay1);
			ObjRender_SetBlendType(obj2,BLEND_ALPHA);
			ObjRender_SetAlpha(obj2,255-slide/9);
			ObjSprite3D_SetDestRect(obj2,0,0,-512-slide*2,-2560-slide*2);
			ObjSprite3D_SetSourceRect(obj2,0,0,-512-slide*2,-2560-slide*2);
			ObjSprite3D_SetSourceDestRect(obj2,0,0,-512-slide*2,-2560-slide*2);
			ObjRender_SetColor(obj2,175,0,20);
			ObjRender_SetScaleX(obj2,1);
			ObjRender_SetScaleY(obj2,1);
			ObjRender_SetPosition(obj2,GetStgFrameWidth/2,GetStgFrameHeight/2,60);
			
			let obj3 = ObjPrim_Create(OBJ_SPRITE_3D);
			Obj_SetRenderPriority(obj3, 0.225);
			ObjPrim_SetTexture(obj3,lay2);
			ObjRender_SetBlendType(obj3,BLEND_ALPHA);
			ObjRender_SetAlpha(obj3,255-slide/9);
			ObjSprite3D_SetDestRect(obj3,0,0,-512-slide*5,-2560-slide*5);
			ObjSprite3D_SetSourceRect(obj3,0,0,-512-slide*5,-2560-slide*5);
			ObjSprite3D_SetSourceDestRect(obj3,0,0,-512-slide*5,-2560-slide*5);
			ObjRender_SetColor(obj3,255,155,255);
			ObjRender_SetScaleX(obj3,1);
			ObjRender_SetScaleY(obj3,1);
			ObjRender_SetPosition(obj3,GetStgFrameWidth/2,GetStgFrameHeight/2,20);
			
		while(checkspell == false){
		
			angleX = 10*cos(slide/6);
			angleY = 20*cos(slide/4.5);
			angleZ = 10*cos(slide/4.5);

			ObjRender_SetAlpha(obj,down);
			ObjSprite3D_SetSourceDestRect(obj,0,-64,1536,1280+slide*3);
			ObjRender_SetAngleXYZ(obj,angleX,angleY,angleZ);
			
			ObjRender_SetAlpha(obj1,down);
			ObjSprite3D_SetSourceDestRect(obj1,0,-64,1536+slide*2,1280+slide*5);
			ObjRender_SetAngleXYZ(obj1,angleX,angleY,angleZ);
			
			ObjRender_SetAlpha(obj2,down);
			ObjSprite3D_SetSourceDestRect(obj2,0,-64,1536+slide*2,1280+slide*3);
			ObjRender_SetAngleXYZ(obj2,angleX,angleY,angleZ);
			
			ObjRender_SetAlpha(obj3,down);
			ObjSprite3D_SetSourceDestRect(obj3,0,-64,1536+slide*2,1280+slide*4);
			ObjRender_SetAngleXYZ(obj3,angleX,angleY,angleZ);

			slide+=3;
			if(down <= 255 && down >= 155){
				down-=2;
			}
			if(down <= 155){
				down-=0.1;
			}
			
			if(down <= 30){
				down = 255;
			}
			yield;
	}
	Obj_Delete(obj);
	Obj_Delete(obj1);
	Obj_Delete(obj2);
	Obj_Delete(obj3);
}

task spellbackground{
	
	let slide = 0;
	let down = 255;
	let angleX = 10*cos(slide/4);
	let angleY = 20*cos(slide/6);
	let angleZ = 10*cos(slide/4);
	
			let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj1, 0.22);
			ObjPrim_SetTexture(obj1,slay);
			ObjRender_SetBlendType(obj1,BLEND_ALPHA);
			ObjSprite2D_SetDestCenter(obj1);
			ObjRender_SetColor(obj1,255,205,255);
			ObjRender_SetScaleX(obj1,1);
			ObjRender_SetScaleY(obj1,1);
			ObjRender_SetPosition(obj1,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
			
			let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj2, 0.22);
			ObjPrim_SetTexture(obj2,slay1);
			ObjRender_SetBlendType(obj2,BLEND_ALPHA);
			ObjSprite2D_SetDestCenter(obj2);
			ObjRender_SetColor(obj2,100,0,255);
			ObjRender_SetScaleX(obj2,1);
			ObjRender_SetScaleY(obj2,1);
			ObjRender_SetPosition(obj2,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
		
			let obj = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj, 0.23);
			ObjPrim_SetTexture(obj,sbg);
			ObjRender_SetBlendType(obj,BLEND_ALPHA);
			ObjRender_SetAlpha(obj,20);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetColor(obj,0,0,155);
			ObjRender_SetScaleXYZ(obj,1.25,1.25,1.25);
			ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
			
		while(checkspell == true){
		
			angleX = 40*cos(slide/6);
			angleY = 10*cos(slide/6);
			angleZ = 10*cos(slide/4);
			let yay = 255*cos(slide/1);

			ObjRender_SetAlpha(obj1,200);
			ObjSprite2D_SetDestRect(obj1,0,0,1024,768);
			ObjSprite2D_SetSourceRect(obj1,0,0,1024,768);
			ObjRender_SetAngleXYZ(obj1,0,0,slide/6);
			ObjSprite2D_SetDestCenter(obj1);
			
			ObjRender_SetAlpha(obj2,100);
			ObjRender_SetColor(obj,0,yay,0);
			ObjSprite2D_SetDestRect(obj2,0,0,1024,1024);
			ObjSprite2D_SetSourceRect(obj2,0,0,1024,1024);
			ObjRender_SetAngleXYZ(obj2,0,0,-slide/12);
			ObjSprite2D_SetDestCenter(obj2);
			
			ObjRender_SetColor(obj,255,99,0);
			ObjSprite2D_SetSourceRect(obj,0,0,500,500);
			ObjSprite2D_SetDestRect(obj,0,0,500,500);
			ObjRender_SetAngleXYZ(obj,0,0,slide/3);
			ObjSprite2D_SetDestCenter(obj);

			slide+=3;
			yield;
		}
	Obj_Delete(obj);
	Obj_Delete(obj1);
	Obj_Delete(obj2);
}

