let GCSD=GetCurrentScriptDirectory();
let bSpell = false;
let current = GetCurrentScriptDirectory();
let stgbg = GCSD~"./img/stg2bg.png";
let stgbg2 = GCSD~"./img/stg2bg2.png";

let fo = 0;

@Initialize
{
	SetCameraFocusX(0);
	SetCameraFocusY(0);
	SetCameraFocusZ(40);
	SetCameraRadius(500);
	SetCameraElevationAngle(250);
	SetCameraAzimuthAngle(90);
	TCallBg;
}

@MainLoop
{

	let objScene = GetEnemyBossSceneObjectID();
	if(ObjEnemyBossScene_GetInfo(objScene, INFO_IS_SPELL) || GetCommonData("FairySpell",false))
	{
		bSpell = true;
	}
	else
	{
		bSpell = false;
	}
	fo++;
	SetCameraFocusY(180+5*sin(fo));
	SetCameraAzimuthAngle(90+3*sin(fo/2));
	SetCameraElevationAngle(250+3*sin(fo/4));

	yield;
}

task TCallBg{
	yield;
	while(1){
	if(bSpell==false){

	TFloor;
	TForest(0.45,0);
	TForest(0.65,-45.73);
	
	//TFalling;
		}
	while(bSpell==false){ yield; }
	yield; //Spellbghere
	while(bSpell==true){ yield; }
	yield;
	}
}


task TFloor{
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let c = 0;
	let s = 0;
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj,22);
	ObjPrim_SetTexture(obj,stgbg);
	ObjSprite2D_SetSourceRect(obj,0,0,1024,1024);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetX(obj,GetStgFrameWidth()/2);
	ObjRender_SetY(obj,GetStgFrameHeight()/2);
	while(bSpell==false){
	if(2<255){s+=2;}
	ObjSprite2D_SetSourceRect(obj,0,0+(-0.35)*c,1024,1024+(-0.35)*c);
	ObjRender_SetAlpha(obj,s);
	ObjRender_SetX(obj,GetStgFrameWidth()/2);
	ObjRender_SetY(obj,GetStgFrameHeight()/2);
	c+=1;
	yield;
	}
	descent(i in 0..60){
	ObjRender_SetAlpha(obj,i*2);
	yield;
	}
	Obj_Delete(obj);
}

task TForest(v,offset){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let c = 0;
	let s = 0;
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj,22);
	ObjPrim_SetTexture(obj,stgbg2);
	ObjSprite2D_SetSourceRect(obj,0,0+offset,509,512+offset);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetX(obj,GetStgFrameWidth()/4);
	ObjRender_SetY(obj,GetStgFrameHeight()/2);
	while(bSpell==false){
	if(2<255){s+=2;}
	ObjSprite2D_SetSourceRect(obj,0,0+(-v)*c+offset,509,512+(-v)*c+offset);
	ObjRender_SetAlpha(obj,s);
	ObjRender_SetX(obj,GetStgFrameWidth()/4);
	ObjRender_SetY(obj,GetStgFrameHeight()/2);
	c+=1;
	yield;
	}
	descent(i in 0..60){
	ObjRender_SetAlpha(obj,i*2);
	yield;
	}
	Obj_Delete(obj);
}