let GCSD=GetCurrentScriptDirectory();
let bSpell = false;
let current = GetCurrentScriptDirectory();
let fo = 0;
let nbg1 = GCSD~"img/stage05a.png";
let nbg2 = GCSD~"img/stage05b.png";
let nbg3 = GCSD~"img/stg3bg1.png";
let nbg4 = GCSD~"img/stg3bg4.png";
let sbg1 = GCSD~"img/cdbg05a00.png";
let sbg2 = GCSD~"img/cdbg05b00.png";
LoadTexture(nbg1);
LoadTexture(nbg2);
LoadTexture(nbg3);
LoadTexture(sbg1);
LoadTexture(sbg2);
@Initialize
{
	SetCameraFocusX(0);
	SetCameraFocusY(0);
	SetCameraFocusZ(0);
	SetCameraRadius(140);
	SetCameraElevationAngle(230);
	SetCameraAzimuthAngle(90);
	TCallBg;
}

@MainLoop
{

	let objScene = GetEnemyBossSceneObjectID();
	if(ObjEnemyBossScene_GetInfo(objScene, INFO_IS_SPELL))
	{
		bSpell = true;
	}
	else
	{
		bSpell = false;
	}
	fo++;
	SetCameraAzimuthAngle(85+5*sin(fo/2));
	yield;
}

task TCallBg{
	yield;
	SetFogParam(100, 200, 0, 0, 0);
	while(1){
	if(bSpell==false){
	TNormalBackground();
	TNormalBackground2();
		}
	while(bSpell==false){ yield; }
	if(bSpell==true){
		TSpellBackground();
		TSpellBackground2();
		}
	while(bSpell==true){ yield; }
	yield;
	}
}
task TNormalBackground(){ // floor
	let c = 0;
	let s = 0;
	let value = 255;
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_3D);
	Obj_SetRenderPriorityI(obj,21);
	ObjPrim_SetTexture(obj,nbg1);
	ObjSprite3D_SetSourceRect(obj,0,0,1024,1024);
	ObjSprite3D_SetDestRect(obj,-512,-512,512,512);
	ObjRender_SetScaleXYZ(obj,0.2,0.2,0.2);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetColor(obj,255,255,255);
	while( !Obj_IsDeleted(obj) && bSpell == false){
	c+=GetCommonData("Scroll",1)*1.5;
	ObjRender_SetPosition(obj,0,0,0);
	ObjSprite3D_SetSourceRect(obj,0,c,512,512+c);
	ObjRender_SetAngleXYZ(obj,0,0,2*sin(count/5));
	value++;
	count++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}	

task TNormalBackground2(){ // Earth
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,20);
	ObjPrim_SetTexture(obj,nbg2);
	ObjSprite2D_SetSourceRect(obj,0,0,512,256);
	ObjSprite2D_SetDestRect(obj,-256,-128,256,128);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetColor(obj,160,160,160);
	ObjRender_SetPosition(obj,384/2+60,448/2-256/2,0);
	while( !Obj_IsDeleted(obj) && bSpell == false){
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}

task TSpellBackground(){
	let c = 0;
	let s = 0;
	let value = 0;
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,21);
	ObjPrim_SetTexture(obj,sbg1);
	ObjSprite2D_SetSourceRect(obj,0,0,384,448);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetColor(obj,255,255,255);
	ObjRender_SetPosition(obj,384/2,448/2,0);
	while( !Obj_IsDeleted(obj) && bSpell == true){
	ObjRender_SetColor(obj,value,value,value);
	if(value<255){value+=5;}
	count++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}	

task TSpellBackground2(){
	let c = 0;
	let s = 0;
	let value = 0;
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,21);
	ObjPrim_SetTexture(obj,sbg2);
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1.5,1.5,1.5);
	ObjRender_SetBlendType(obj,BLEND_MULTIPLY);
	ObjRender_SetPosition(obj,384/2,448/2,0);
	while( !Obj_IsDeleted(obj) && bSpell == true){
	ObjRender_SetColor(obj,value,value/2,value);
	if(value<255){value+=5;}
	ObjRender_SetAngleXYZ(obj,0,0,count/4);
	count++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}