let GCSD=GetCurrentScriptDirectory();
let bSpell = false;
let current = GetCurrentScriptDirectory();
let fo = 0;
let nbg1 = GCSD~"img/stg3bg2.png";
let nbg2 = GCSD~"img/stg3bg3.png";
let nbg3 = GCSD~"img/stg3bg1.png";
let nbg4 = GCSD~"img/stg3bg4.png";
let nbg5 = GCSD~"img/stg3bg5.png";
let sbg0 = GCSD~"img/5.png";
let sbg1 = GCSD~"img/cdbg07a00.png";
let sbg2 = GCSD~"img/cdbg07b00.png";
let sbg3 = GCSD~"img/eff05.png";
let sbg4 = GCSD~"img/eff05b.png";
LoadTexture(sbg0);
LoadTexture(nbg1);
LoadTexture(nbg2);
LoadTexture(nbg3);
LoadTexture(sbg1);
LoadTexture(sbg2);
@Initialize
{
	SetCameraFocusX(0);
	SetCameraFocusY(0);
	SetCameraFocusZ(0);
	SetCameraRadius(65);
	SetCameraElevationAngle(230);
	SetCameraAzimuthAngle(86);
	TCallBg;
}

@MainLoop
{

	let objScene = GetEnemyBossSceneObjectID();
	if(ObjEnemyBossScene_GetInfo(objScene, INFO_IS_SPELL))
	{
		bSpell = true;
	}
	else
	{
		bSpell = false;
	}
	fo++;

	yield;
}

task TCallBg{
	yield;
	SetFogParam(0, 400, 32, 0, 64);
	TNormalBackground();
	TNormalBackground2();
	TNormalBackground3();
	TNormalBackground4();
	TNormalBackground5();
	TNormalBackground6();
	TNormalBackground7;
	while(1){
	while(bSpell==false){ yield; }
	if(bSpell==true){
		if( GetCommonData("BossName","Yukari Yakumo") == "Yukari Yakumo" ){
		TSpellBackground0();
		TSpellBackground();
		TSpellBackground2();
			}
		if( GetCommonData("BossName","Rei'sen") == "Rei'sen" ){
		TSpellBackground0();
		TSpellBackground4();
		TSpellBackground5();
			}
		}
	while(bSpell==true){ yield; }
	yield;
	}
}
task TNormalBackground(){ // upmost grid
	let c = 0;
	let s = 0;
	let value = 255;
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_3D);
	Obj_SetRenderPriorityI(obj,22);
	ObjPrim_SetTexture(obj,nbg1);
	ObjSprite3D_SetSourceRect(obj,0,0,512,512);
	ObjSprite3D_SetDestRect(obj,-256*4,-256*4,256*4,256*4);
	ObjRender_SetScaleXYZ(obj,0.3,0.3,0.3);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	//ObjRender_SetColor(obj,255,0,0);
	loop{
	c+=GetCommonData("Scroll",1)*9;
	ObjRender_SetPosition(obj,0,0,0);
	ObjSprite3D_SetSourceRect(obj,-1024,-1024+c,512*2,512*2+c);
	ObjRender_SetAngleXYZ(obj,0,0,12*sin(count/5));
	value++;
	count++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}	

task TNormalBackground2(){ // middle, crane grid
	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,nbg2);
	ObjSprite3D_SetSourceRect(obj,0,0,1024,1024);
	ObjSprite3D_SetDestRect(obj,-512*4,-512*4,512*4,512*4);
	ObjRender_SetScaleXYZ(obj,0.4,0.4,0.4);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetAlpha( obj, 230 );
	ObjRender_SetColor(obj,255,255,255);
	loop{
	c+=GetCommonData("Scroll",1)*9;
	ObjRender_SetPosition(obj,0,0,100);
	ObjSprite3D_SetSourceRect(obj,-1024*2,-1024*2+c,1024*2,1024*2+c);
	ObjRender_SetAngleXYZ(obj,0,0,12*sin(count/5));
	value++;
	count++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}

task TNormalBackground3(){ // background space
	let c = 0;
	let s = 0;
	let value = 255;
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_3D);
	Obj_SetRenderPriorityI(obj,20);
	ObjPrim_SetTexture(obj,nbg3);
	ObjSprite3D_SetSourceRect(obj,0,0,1024,1024);
	ObjSprite3D_SetDestRect(obj,-512,-512,512,512);
	ObjRender_SetScaleXYZ(obj,0.25,0.25,0.25);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetColor(obj,255,255,255);
	loop{
	c+=GetCommonData("Scroll",1)*2.5;
	ObjRender_SetPosition(obj,0,0,0);
	ObjSprite3D_SetSourceRect(obj,-1024*2,-1024*2+c,1024*2,1024*2+c);
	ObjRender_SetAngleXYZ(obj,0,0,5*sin(count/5));
	value++;
	count++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}

task TNormalBackground4(){ // farthest grid
	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,-1024,-1024,1024,1024);
	ObjSprite3D_SetDestRect(obj,-512*4,-512*4,512*4,512*4);
	ObjRender_SetScaleXYZ(obj,0.8,0.8,0.8);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetAlpha( obj, 150 );
	ObjRender_SetColor(obj,255,255,255);
	loop{
	c+=GetCommonData("Scroll",1)*9;
	ObjRender_SetPosition(obj,30,0,100);
	ObjSprite3D_SetSourceRect(obj,-1024*9,-1024*9 + c,1024*9,1024*9+c);
	ObjRender_SetAngleXYZ(obj,0,0,12*sin(count/5));
	value++;
	count++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}

task TNormalBackground5(){ //moon
	let c = 0;
	let s = 0;
	let value = 0;
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,20);
	ObjPrim_SetTexture(obj,nbg4);
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1.2,1.2,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetColor(obj,255,255,255);
	ObjRender_SetPosition(obj,640/2,60,0);
}

task TNormalBackground6(){ //black space effect
	let c = 0;
	let s = 0;
	let value = 255;
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_3D);
	Obj_SetRenderPriorityI(obj,20);
	ObjPrim_SetTexture(obj,nbg5);
	ObjSprite3D_SetSourceRect(obj,0,0,512,512);
	ObjSprite3D_SetDestRect(obj,-256,-256,256,256);
	ObjRender_SetScaleXYZ(obj,0.6,0.6,0.6);
	ObjRender_SetBlendType(obj,BLEND_SUBTRACT);
	loop{
	c+=GetCommonData("Scroll",1)*1.5;
	ObjRender_SetPosition(obj,0,0,0);
	ObjSprite3D_SetSourceRect(obj,-512*2,-512*2+c,512*2,512*2+c);
	ObjRender_SetAngleXYZ(obj,0,0,5*sin(count/5));
	value++;
	count++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}

task TNormalBackground7{
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,21);
	ObjPrim_SetTexture(obj,sbg0);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,3,2,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,640/2,450/2,0);
	ObjRender_SetAlpha( obj, 255 );
	loop( 900 ){ yield; }
	descent( i in 0..255/2 ){
	ObjRender_SetAlpha( obj, i*2 );
	yield;
	}
	Obj_Delete(obj);
}


task TSpellBackground0(){
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,26);
	ObjPrim_SetTexture(obj,sbg0);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,3,2,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,640/2,450/2,0);
	ObjRender_SetAlpha( obj, 255 );
	ascent( i in 0..255/3.5 ){
	ObjRender_SetAlpha( obj, i*3.5 );
	yield;
	}
	loop( 10 ){ yield; }
	descent( i in 0..255/2.5 ){
	ObjRender_SetAlpha( obj, i*2.5 );
	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,24);
	ObjPrim_SetTexture(obj,sbg1);
	ObjSprite2D_SetSourceRect(obj,0,0,384,448);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1.67,1.67,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetColor(obj,255,255,255);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	Seek( obj );
	while( !Obj_IsDeleted(obj) && bSpell == true){
	ObjRender_SetColor(obj,value,value,value);
	if(value<255){value+=10;}
	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,25);
	ObjPrim_SetTexture(obj,sbg2);
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1.67,1.67,1.67);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetColor(obj,255,255,255);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	Seek( obj );
	while( !Obj_IsDeleted(obj) && bSpell == true){
	ObjRender_SetColor(obj,value,value,value);
	if(value<200){value+=10;}
	ObjRender_SetAngleXYZ(obj,0,0,count);
	count -= 0.5;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}

	task Seek( obj ){
	ObjRender_SetAlpha( obj, 0 );
	loop( 75 ){ yield; }
	ObjRender_SetAlpha( obj, 255 );
	}

task TSpellBackground4(){
	let c = 0;
	let s = 0;
	let value = 0;
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,23);
	ObjPrim_SetTexture(obj,sbg3);
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1.4,1.4,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	Seek2( obj );
	while( !Obj_IsDeleted(obj) && bSpell == true){
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}	

task TSpellBackground5(){
	let c = 0;
	let s = 0;
	let value = 0;
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,24);
	ObjPrim_SetTexture(obj,sbg4);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,3,3,3);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	Seek2( obj );
	while( !Obj_IsDeleted(obj) && bSpell == true){
	ObjRender_SetAngleXYZ(obj,0,0,count);
	count += 0.5;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}

	task Seek2( obj ){
	ObjRender_SetAlpha( obj, 0 );
	loop( 75 ){ yield; }
	ObjRender_SetAlpha( obj, 135 );
	}