let checkspell = false;

let sceneObj = GetEnemyBossSceneObjectID;

let CSD = GetCurrentScriptDirectory;
let ns = CSD ~ "img/NonSpellA.png";
let nso = CSD ~ "img/NonSpellB.png";
let s = CSD ~ "img/SpellA.png";
let so = CSD ~ "img/SpellB.png";

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

@Initialize{
	SetFogEnable(true);
	SetCameraFocusX(360);
	SetCameraFocusY(0);
	SetCameraFocusZ(0);
	SetCameraRadius(700);
	SetCameraElevationAngle(205);
	SetCameraAzimuthAngle(90);
	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 angleX = 10*cos(slide/4);
	let angleY = 20*cos(slide/6);
	let angleZ = 10*cos(slide/4);
			
			let obj1 = ObjPrim_Create(OBJ_SPRITE_3D);
			ObjPrim_SetTexture(obj1,ns);
			Obj_SetRenderPriority(obj1, 0.23);
			ObjRender_SetBlendType(obj1,BLEND_ADD_RGB);
			ObjRender_SetAlpha(obj1,0);
			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_SetScaleX(obj1,2);
			ObjRender_SetScaleY(obj1,2);
			ObjRender_SetColor(obj1,255,255,255);
			ObjRender_SetPosition(obj1,GetStgFrameWidth/2,GetStgFrameHeight/2,100);
			
			let obj2 = ObjPrim_Create(OBJ_SPRITE_3D);
			ObjPrim_SetTexture(obj2,ns);
			Obj_SetRenderPriority(obj2, 0.22);
			ObjRender_SetBlendType(obj2,BLEND_ADD_RGB);
			ObjRender_SetAlpha(obj1,0);
			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(obj2,128,192,255);
			ObjRender_SetScaleX(obj1,2);
			ObjRender_SetScaleY(obj1,2);
			ObjRender_SetPosition(obj1,GetStgFrameWidth/2,GetStgFrameHeight/2,100);
			
			let obj = ObjPrim_Create(OBJ_SPRITE_3D);
			Obj_SetRenderPriority(obj, 0.24);
			ObjPrim_SetTexture(obj,nso);
			ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
			ObjRender_SetAlpha(obj,20);
			ObjSprite3D_SetSourceRect(obj,0,0,1024,1280);
			ObjSprite3D_SetSourceDestRect(obj,0,0,1024,1280+slide*2);
			ObjRender_SetScaleXYZ(obj,1,1,1);
			ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
			
		while(checkspell == false && !Obj_IsDeleted(GetEnemyBossObjectID)){
		
			angleX = 10*cos(slide/6);
			angleY = 20*cos(slide/4.5);
			angleZ = 10*cos(slide/4.5);
			
			ObjRender_SetAlpha(obj,255);
			ObjSprite3D_SetSourceDestRect(obj,0,-64,1536,1280+slide*3);
			ObjRender_SetAngleXYZ(obj,angleX,angleY,angleZ);
			
			ObjSprite3D_SetSourceDestRect(obj1,0,-64,1536+slide*2,1280+slide*5);
			ObjRender_SetAngleXYZ(obj1,angleX,angleY,angleZ);
			
			ObjSprite3D_SetSourceDestRect(obj2,0,-64,-1536-slide*2,1280+slide*5);
			ObjRender_SetAngleXYZ(obj2,angleX,angleY,angleZ);
			
			SetFogParam(250,700+slide*2,0,0,0);
			slide+=3;
			yield;
		}
	Obj_Delete(obj);
	Obj_Delete(obj1);
	Obj_Delete(obj2);
	yield;
}

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,s);
			ObjRender_SetBlendType(obj1,BLEND_ADD_RGB);
			ObjSprite2D_SetDestCenter(obj1);
			ObjRender_SetScaleXYZ(obj1,3.25,3.25,3.25);
			ObjRender_SetPosition(obj1,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
			
			let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj2, 0.24);
			ObjPrim_SetTexture(obj2,so);
			ObjRender_SetBlendType(obj2,BLEND_ADD_RGB);
			ObjSprite2D_SetDestCenter(obj2);
			ObjRender_SetScaleXYZ(obj2,3.25,3.25,3.25);
			ObjRender_SetPosition(obj2,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
		
			let obj = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriority(obj, 0.23);
			ObjPrim_SetTexture(obj,s);
			ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
			ObjRender_SetAlpha(obj,20);
			ObjSprite2D_SetDestCenter(obj);
			ObjRender_SetScaleXYZ(obj,3.25,3.25,3.25);
			ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
			
		while(checkspell == true && !Obj_IsDeleted(GetEnemyBossObjectID)){
		
			angleX = 40*cos(slide/6);
			angleY = 10*cos(slide/6);
			angleZ = 10*cos(slide/4);

			ObjRender_SetAlpha(obj2,200);
			ObjSprite2D_SetDestRect(obj2,0,0,256,256);
			ObjSprite2D_SetSourceRect(obj2,0,0,256,256);
			ObjRender_SetAngleXYZ(obj2,0,0,-slide/4);
			ObjSprite2D_SetDestCenter(obj2);
			
			ObjSprite2D_SetSourceRect(obj1,0,0,256,256);
			ObjSprite2D_SetDestRect(obj1,0,0,256,256);
			ObjRender_SetAngleXYZ(obj1,0,0,slide/3);
			ObjSprite2D_SetDestCenter(obj1);
			
			ObjSprite2D_SetSourceRect(obj,0,0,256,256);
			ObjSprite2D_SetDestRect(obj,0,0,256,256);
			ObjRender_SetAngleXYZ(obj,0,0,-slide/3);
			ObjSprite2D_SetDestCenter(obj);

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