let GCSD=GetCurrentScriptDirectory();
let bSpell = false;
let current = GetCurrentScriptDirectory();
let fo = 0;
let nbg1 = GCSD~"img/Handmade_White-Black.png";
let nbg2 = GCSD~"img/stage02b.png";
let nbg3 = GCSD~"img/3_4.png";
let nbg4 = GCSD~"img/BG_B1_c.png";
let nbg5 = GCSD~"img/BG_B1_b.png";
let sbg1 = GCSD~"img/Shion_00.png";
let sbg2 = GCSD~"img/Shion_01.png";
let sbg3 = GCSD~"img/Shion_10.png";
let sbg4 = GCSD~"img/Aoji_02.png";
let sbg5 = GCSD~"img/Aoji_03.png";
LoadTexture(nbg1);
LoadTexture(nbg2);
LoadTexture(nbg3);
LoadTexture(nbg4);
LoadTexture(nbg5);
LoadTexture(sbg1);
LoadTexture(sbg2);
LoadTexture(sbg3);
LoadTexture(sbg4);
LoadTexture(sbg5);
@Initialize
{
	SetCameraFocusX(-0);
	SetCameraFocusY(0);
	SetCameraFocusZ(0);
	SetCameraRadius(1000);
	SetCameraAzimuthAngle(-90);
	SetCameraElevationAngle(-5);
	TCallBg;
	//TreeGenerator;
}

@MainLoop
{

	let objScene = GetEnemyBossSceneObjectID();
	if(ObjEnemyBossScene_GetInfo(objScene, INFO_IS_SPELL))
	{
		bSpell = true;
	}
	else
	{
		bSpell = false;
	}
	fo++;
	SetCameraElevationAngle(30);
    SetCameraAzimuthAngle(90);
	yield;
}

task TCallBg{
	yield;
	SetFogParam(800,1800, 155, 255, 255);
	while(1){

	
	VeryBackground();
	TNormalBackground(-0,-7);
	TNormalBackground(-0,-2);
	TNormalBackground(-0,-5);
	BackgroundS;
	//TNormalBackgroundS;

		
	while(bSpell==false){ yield; }
	if(bSpell==true){
		//TSpellBackground5();
		//TSpellBackground6();
		//VerySpellBackground;
		TSpellBackground();
		TSpellBackground3();
		TSpellBackground3B();
		VerySpellBackground;
		VerySpellBackgroundB;
		loop
		{
		//TSpellBackground2();
		loop(60){yield;};
		}
		//TSpellBackground2();
		//TSpellBackground4();
		}
	while(bSpell==true){ yield; }
	yield;
	}
}

task VeryBackground(){ // White
	let c = 0;
	let s = 0;
	let value = 255;
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,20);
	ObjPrim_SetTexture(obj,nbg1);
	ObjSprite2D_SetSourceRect(obj,0,0,2024,2024);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetPosition(obj,0,0,1200);
	while( !Obj_IsDeleted(obj) ){
	c+=GetCommonData("Scroll",1)*0;
	ObjRender_SetColor(obj,155, 255, 255);
	ObjSprite2D_SetSourceRect(obj,0,0,2024,2024);
	value++;
	count++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}	

task BackgroundS(){ // sun
	let c = 0;
	let s = 0;
	let value = 255;
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,21);
	ObjPrim_SetTexture(obj,nbg3);
	ObjSprite2D_SetSourceRect(obj,0,0,2024,2024);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,-0,0);
	while( !Obj_IsDeleted(obj) ){
	c+=GetCommonData("Scroll",1)*0;
	ObjRender_SetColor(obj,255, 255, 255);
	ObjRender_SetAngleXYZ(obj,0,0,count*0);
	ObjRender_SetScaleXYZ(obj,0.5,0.5,count*20);
	ObjSprite2D_SetSourceRect(obj,0,0,800,800);
	value++;
	count++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}	

task TNormalBackground(z,spd){ // 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,nbg2);
	ObjSprite3D_SetSourceRect(obj,0,0,256,256*3);
	ObjSprite3D_SetSourceDestRect(obj,0,0,512*5,256*10);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAngleXYZ(obj,90,0,0);
	ObjRender_SetPosition(obj,-0,45,z);
	while( !Obj_IsDeleted(obj) ){
	c+=GetCommonData("Scroll",1)*spd;
	//ObjRender_SetAlpha(obj,72);
	ObjSprite3D_SetSourceRect(obj,0,c,512*5,256*10+c);
	value++;
	count++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}	

task VerySpellBackground(){ // White
	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,2500,2500);
	ObjSprite2D_SetDestCenter(obj);
	//ObjRender_SetBlendType(obj,BLEND_SUBTRACT);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	//ObjRender_SetPosition(obj,0,GetStgFrameHeight/2,0);
	while( !Obj_IsDeleted(obj) && bSpell == true){
	c+=GetCommonData("Scroll",1)*1;
	ObjRender_SetColor(obj,value,value,value);
	if(value<200){value+=10;}
	ObjSprite2D_SetSourceRect(obj,0,0,512,580);
	ObjRender_SetPosition(obj,0+200*sin(count),GetStgFrameHeight/2+400-100*sin(count*7),0);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetAlpha(obj,255-255*sin(-count));
	value++;
	count++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}	

task VerySpellBackgroundB(){ // White
	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,2500,2500);
	ObjSprite2D_SetDestCenter(obj);
	//ObjRender_SetBlendType(obj,BLEND_SUBTRACT);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	//ObjRender_SetPosition(obj,0,GetStgFrameHeight/2,0);
	while( !Obj_IsDeleted(obj) && bSpell == true){
	c+=GetCommonData("Scroll",1)*1;
	ObjRender_SetColor(obj,value,value,value);
	if(value<200){value+=10;}
	ObjSprite2D_SetSourceRect(obj,0,0,512,580);
	ObjRender_SetPosition(obj,GetStgFrameWidth-200*sin(-count),GetStgFrameHeight/2+400-100*sin(count*7),0);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetAlpha(obj,255-255*sin(count));
	value++;
	count++;
	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,23);
	ObjPrim_SetTexture(obj,sbg1);
	ObjSprite2D_SetSourceRect(obj,0,0,512,580);
	ObjSprite2D_SetDestCenter(obj);
	//ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetColor(obj,255,255,255);
	while( !Obj_IsDeleted(obj) && bSpell == true){
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
	ObjRender_SetColor(obj,value,value,value);
	ObjRender_SetScaleXYZ(obj,0.5+0.25*sin(count*5),1,1);
	if(value<0){value+=5;}
	count++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}	

task TSpellBackground3(){
	let c = 0;
	let s = 0;
	let value = 0;
	let count = 0;
	let t = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,22);
	ObjPrim_SetTexture(obj,sbg2);
	ObjSprite2D_SetSourceRect(obj,0,0,824,730);
	ObjSprite2D_SetDestCenter(obj);
	//ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,640/2,450/2,0);
	while( !Obj_IsDeleted(obj) && bSpell == true){
	c+=GetCommonData("Scroll",1)*1;
	ObjRender_SetColor(obj,value,value,value);
	if(value<255){value+=5;}
	ObjRender_SetScaleXYZ(obj,1.25-0.25*sin(count*2),1.25-0.25*sin(count*2),0);
	ObjSprite2D_SetSourceRect(obj,0,0,1024,1024);
	ObjRender_SetAngleXYZ(obj,0,0,count*1);
	count += 1;
	t++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}

task TSpellBackground3B(){
	let c = 0;
	let s = 0;
	let value = 0;
	let count = 0;
	let t = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,23);
	ObjPrim_SetTexture(obj,sbg2);
	ObjSprite2D_SetSourceRect(obj,0,0,824,730);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,640/2,450/2,0);
	while( !Obj_IsDeleted(obj) && bSpell == true){
	c+=GetCommonData("Scroll",1)*1;
	ObjRender_SetColor(obj,value,value,value);
	if(value<155){value+=5;}
	ObjRender_SetScaleXYZ(obj,1.25-0.25*sin(count*-2),1.25-0.25*sin(count*-2),0);
	ObjSprite2D_SetSourceRect(obj,0,0,1024,1024);
	ObjRender_SetAngleXYZ(obj,0,0,count*-1);
	count += 1;
	t++;
	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 t = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,20);
	ObjPrim_SetTexture(obj,sbg5);
	ObjSprite2D_SetSourceRect(obj,0,0,800,800);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,640/2,0,0);
	while( !Obj_IsDeleted(obj) && bSpell == true){
	c+=GetCommonData("Scroll",1)*0;
	ObjRender_SetColor(obj,value,value,value);
	if(value<255){value+=5;}
	ObjRender_SetScaleXYZ(obj,3,3,0);
	ObjSprite2D_SetSourceRect(obj,0,0,800,800);
	ObjRender_SetAngleXYZ(obj,0,0,count*-0.5);
	ObjRender_SetAlpha(obj,255+255*sin(count*0.75));
	count++;
	t++;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}

task TSpellBackground6(){
	let c = 0;
	let s = 0;
	let value = 0;
	let count = 0;
	let t = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,20);
	ObjPrim_SetTexture(obj,sbg5);
	ObjSprite2D_SetSourceRect(obj,0,0,800,800);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,640/2,0,0);
	while( !Obj_IsDeleted(obj) && bSpell == true){
	c+=GetCommonData("Scroll",1)*0;
	ObjRender_SetColor(obj,value,value,value);
	if(value<255){value+=5;}
	ObjRender_SetScaleXYZ(obj,3,3,0);
	ObjSprite2D_SetSourceRect(obj,0,0,800,800);
	ObjRender_SetAngleXYZ(obj,0,0,count*0.5);
	ObjRender_SetAlpha(obj,255+255*sin(count*0.75));
	count++;
	t++;
	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 t = 0;
	let x = rand(0,GetStgFrameWidth);
	let y = GetStgFrameHeight+100;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,22);
	ObjPrim_SetTexture(obj,sbg3);
	ObjSprite2D_SetSourceRect(obj,0,0,500,494);
	ObjSprite2D_SetDestCenter(obj);
	//ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	while( !Obj_IsDeleted(obj) && bSpell == true){
	c+=GetCommonData("Scroll",1)*-0.25;
	ObjRender_SetPosition(obj,x,y-count*2,0);
	//ObjRender_SetAlpha(obj,150+155*sin(c));
	ObjRender_SetColor(obj,255,255,255);
	ObjRender_SetScaleXYZ(obj,0.35,0.35,0);
	ObjSprite2D_SetSourceRect(obj,0,0,500,494);
	ObjRender_SetAngleXYZ(obj,0,count*2,0);
	count++;
	if(ObjRender_GetY(obj)<-100){
	break;
	}
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}

task TSpellBackground4(){
	let c = 0;
	let s = 0;
	let value = 0;
	let count = 0;
	let t = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,22);
	ObjPrim_SetTexture(obj,sbg4);
	ObjSprite2D_SetSourceRect(obj,0,0,685,800);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,640/2,450/2,0);
	while( !Obj_IsDeleted(obj) && bSpell == true){
	c+=GetCommonData("Scroll",1)*0.25;
	ObjRender_SetAlpha(obj,150+155*sin(c));
	ObjRender_SetColor(obj,155,155,255);
	ObjSprite2D_SetSourceRect(obj,685/2*sin(c),0,685+685/2*sin(c),800);
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}

