
let bSpell = false;
let current = GetCurrentScriptDirectory();
@Initialize
{
	SetCameraFocusX(0);
	SetCameraFocusY(0);
	SetCameraFocusZ(0);
	SetCameraRadius(550);
	SetCameraElevationAngle(35);
	SetCameraAzimuthAngle(90);

	SetFogParam(0, 1000, 32, 32, 32);

	ascent(let pos in 0..3)
	{
		TNormalBackground(pos);
	}
	TSpellBackground();
}

@MainLoop
{

	let objScene = GetEnemyBossSceneObjectID();
	if(objScene != ID_INVALID && ObjEnemyBossScene_GetInfo(objScene, INFO_IS_SPELL))
	{
		bSpell = true;
	}
	else
	{
		bSpell = false;
	}
	

	yield;
}


task TNormalBackground(pos){//Credits: Helepolis
	let scrollTex = 0;
	let Img_Sky = GetCurrentScriptDirectory ~ "BG/Sky.png";
	let Img_Sea = GetCurrentScriptDirectory ~ "BG/Sea.png";
	// Sky
	let Sky = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(Sky,20); 
	ObjPrim_SetTexture(Sky,Img_Sky); 
	ObjSprite2D_SetSourceRect(Sky,0,0,600,270);
	ObjSprite2D_SetDestRect(Sky,0,0,600,270);
	
	//Sea
	let Sea1 = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(Sea1,21); 
	ObjRender_SetAlpha(Sea1,200);
	ObjPrim_SetTexture(Sea1,Img_Sea); 
	ObjSprite2D_SetSourceRect(Sea1,0,270,600,330);
	ObjSprite2D_SetDestRect(Sea1,0,270,GetStgFrameWidth,GetStgFrameHeight);
	
	loop{
		ObjSprite2D_SetSourceRect(Sea1,0-scrollTex,0,600-scrollTex,330);
		ObjSprite2D_SetSourceRect(Sky,0+scrollTex/4,0,600+scrollTex/4,270);
		scrollTex += 2;
		yield;
	}
	
}

task TSpellBackground{
	let scrollTex = 0;
	let path1 = current ~ "BG/BG1s.png";
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj1,21); 
	ObjRender_SetAlpha(obj1,200);
	ObjPrim_SetTexture(obj1,path1); 
	ObjSprite2D_SetSourceRect(obj1,0,270,503,595);
	ObjSprite2D_SetDestRect(obj1,0,0,GetStgFrameWidth,GetStgFrameHeight);

	let alpha = 0;
	let frame = 0;
	loop{
		if(bSpell)
		{
			alpha += 4;
		}
		else
		{
			alpha = 0;
		}
		ObjRender_SetAlpha(obj1, alpha);
		Obj_SetVisible(obj1, alpha > 0);
		ObjSprite2D_SetSourceRect(obj1,0,0-scrollTex,503,595-scrollTex);

		scrollTex += 2;
		yield;
		}

		
		yield;
	}

