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/stage06a.png";
let nbg5 = GCSD~"img/stage06b.png";
let nbg6 = GCSD~"img/stage05a.png";
let nbg4 = GCSD~"img/stg3bg4.png";
let sbg1 = GCSD~"img/stg3bg5.png";
let sbg2 = GCSD~"img/stg3bg1.png";
LoadTexture(nbg1);
LoadTexture(nbg2);
LoadTexture(nbg3);
LoadTexture(nbg6);
LoadTexture(nbg5);
LoadTexture(sbg1);
LoadTexture(sbg2);
@Initialize
{
	SetCameraFocusX(0);
	SetCameraFocusY(0);
	SetCameraFocusZ(0);
	SetCameraRadius(105);
	SetCameraElevationAngle(215);
	SetCameraAzimuthAngle(90);
	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);
	while(1){
	if(bSpell==false){
        TNormalBackground6();
	TNormalBackground3();
	TNormalBackground5();
	TNormalBackground4();
	TNormalBackground7();
		}
	while(bSpell==false){ yield; }
	if(bSpell==true){

		TSpellBackground3();
		}
	while(bSpell==true){ yield; }
	yield;
	}
}

task TNormalBackground7(){ // sea red
	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,1024,1024);
	ObjSprite3D_SetDestRect(obj,-512,-512,512,512);
	ObjRender_SetScaleXYZ(obj,0.15,0.15,0.15);
	ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetColor(obj,555,0,0);
	while( !Obj_IsDeleted(obj) && bSpell == false){
	c+=GetCommonData("Scroll",2)*-4;
	ObjRender_SetPosition(obj,0,0,0);
	ObjSprite3D_SetSourceRect(obj,0,c,1024,1024+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 TNormalBackground6(){ // yelo
	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,512,512);
	ObjSprite3D_SetDestRect(obj,-256,-256,256,256);
	ObjRender_SetScaleXYZ(obj,0.4,0.4,0.4);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetColor(obj,155,155,0);
	while( !Obj_IsDeleted(obj) && bSpell == false){
	c+=GetCommonData("Scroll",1)*-2;
	ObjRender_SetPosition(obj,0,0,0);
	ObjSprite3D_SetSourceRect(obj,0,c,512,512+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 TNormalBackground(){ // purp
	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,512,512);
	ObjSprite3D_SetDestRect(obj,-256,-256,256,256);
	ObjRender_SetScaleXYZ(obj,0.4,0.4,0.4);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetAngleXYZ(obj,0,0,150);
	ObjRender_SetColor(obj,155,0,155);
	while( !Obj_IsDeleted(obj) && bSpell == false){
	c+=GetCommonData("Scroll",1)*4;
	ObjRender_SetPosition(obj,0,0,0);
	ObjSprite3D_SetSourceRect(obj,0,c,512,512+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(){ // sea
	let c = 0;
	let s = 0;
	let value = 155;
	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.15,0.15,0.15);
	ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetColor(obj,555,555,555);
	while( !Obj_IsDeleted(obj) && bSpell == false){
	c+=GetCommonData("Scroll",9)*5;
	ObjRender_SetPosition(obj,0,0,0);
	ObjSprite3D_SetSourceRect(obj,0,c,1024,1024+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(){ // purple
	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.5,0.5,0.5);
	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)*7;
	ObjRender_SetPosition(obj,30,0,100);
	ObjSprite3D_SetSourceRect(obj,0,c,1024,1024+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,21);
	ObjPrim_SetTexture(obj,nbg4);
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,0.5,0.5,0.5);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetAngleXYZ(obj,0,0,0);
	ObjRender_SetColor(obj,15,15,15);
	ObjRender_SetPosition(obj,384/2,60,0);
	while( !Obj_IsDeleted(obj) && bSpell == false){
	ObjRender_SetColor(obj,100,100,100);
	value++;
	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,sbg2);
	ObjSprite2D_SetSourceRect(obj,0,0,1024,1024);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,0.5,0.5,0.5);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	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,sbg1);
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	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,0,0);
	if(value<255){value+=5;}
	ObjSprite2D_SetSourceRect(obj,0,count,512,512+count);
	count+=3;
	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 obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,21);
	ObjPrim_SetTexture(obj,sbg1);
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetAngleXYZ(obj,0,0,180);
	ObjRender_SetColor(obj,255,255,255);
	ObjRender_SetPosition(obj,384/2,448/2,0);
	while( !Obj_IsDeleted(obj) && bSpell == true){
	ObjRender_SetColor(obj,value,0,value);
	if(value<255){value+=5;}
	ObjSprite2D_SetSourceRect(obj,0,count,512,512+count);
	count+=3;
	yield;
	}
	descent(i in 0..30){
	ObjRender_SetAlpha(obj,i);
	yield;
	}
	Obj_Delete(obj);
}