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

	//SetFogParam(0, 1900, 56, 8, 73);

	Tier5BG();
	Tier5BGCherry();
	Tier5BGCherry2();
	TSpellBackground();
	TSpellBackground3();
}

@MainLoop
{

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

	yield;
}

task TNormalBackground
{
SetFogEnable(true);
let param=0;
SetCameraFocusXYZ(GetScreenWidth/2, GetScreenHeight/2, -500);
SetCameraElevationAngle(-60);
Background1; 
SettleIn;


task SettleIn{
let c=(1720-param)/190;
let ang=0;
loop(120){
//SetCameraElevationAngle(-35*sin(ang));
ang+=90/120;
param+=c;
SetFogParam(param, 1200,20, 64, 135);
yield;}
}



	task Background1{
	let bg=ObjPrim_Create(OBJ_SPRITE_3D);
	let t=0;
	let t2=0;
	ObjPrim_SetTexture(bg, GetCurrentScriptDirectory~"/img/stg3bg2.png");
	ObjSprite3D_SetSourceDestRect(bg, 0, 0, 512, 512);
	Obj_SetRenderPriorityI(bg, 0.1);
	
	let alpha=255;
	ObjRender_SetScaleXYZ(bg, 1.25, 1.25, 1.25);
	ObjRender_SetPosition(bg, GetScreenWidth/2, GetScreenHeight/2, -50);
	ObjRender_SetColor(bg,255, 0, 0);
	ObjRender_SetAngleZ(bg, 30);
	while(!Obj_IsDeleted(bg)){
if (bSpell==false&&alpha<255){alpha+=15;}
if (bSpell==true&&alpha>0){alpha-=5;}
ObjRender_SetAlpha(bg, alpha);
	t+=3.75; 
	t2+=1;
	ObjSprite3D_SetSourceDestRect(bg, 0,t, 4096+50*sin(t2), 4096+t);
	yield;}
	}
	
	
}

task Tier5BG
{
		
SetFogEnable(true);
let param=0;
SetCameraFocusXYZ(GetScreenWidth/2, GetScreenHeight/2, -220);
SetCameraElevationAngle(-60);
Background1; 

SettleIn;
task SettleIn{
let c=(1720-param)/120;
let ang=0;
loop(120){
//SetCameraElevationAngle(-35*sin(ang));
ang+=90/120;
param+=c;
SetFogParam(param, 1900, 86, 8, 114);
yield;}
}
			
	task Background1{
		
	let bg=ObjPrim_Create(OBJ_SPRITE_3D);
	let t=0;
	ObjPrim_SetTexture(bg, GetCurrentScriptDirectory~"/img/bgtier5.png");
	ObjSprite3D_SetSourceDestRect(bg, 0, 0, 4096, 4096);
	Obj_SetRenderPriorityI(bg, 0);
	
	let alpha=255;
	ObjRender_SetScaleXYZ(bg, 1, 1, 1);
	ObjRender_SetPosition(bg, GetScreenWidth/2+60, GetScreenHeight/2, -200);
	
	while(!Obj_IsDeleted(bg)){
		
if (bSpell==false&&alpha<255){alpha+=15;}
if (bSpell==true&&alpha>0){alpha-=5;}

ObjRender_SetAlpha(bg, alpha);
	t+=2; 

	ObjSprite3D_SetSourceDestRect(bg, 0, t, 4096, 4096+t);
	yield;}
	
	Obj_Delete(bg);
	
	}
		
	
}

task Tier5BGCherry
{
		
SetFogEnable(true);
let param=0;
SetCameraFocusXYZ(GetScreenWidth/2, GetScreenHeight/2, -220);
SetCameraElevationAngle(-60);
Background1; 

	task Background1{
		
	let bg=ObjPrim_Create(OBJ_SPRITE_3D);
	let t=0;
	ObjPrim_SetTexture(bg, GetCurrentScriptDirectory~"/img/bgcherry3.png");
	ObjSprite3D_SetSourceDestRect(bg, 0, 0, 1024, 1024);
	Obj_SetRenderPriorityI(bg, 0);
	
	let alpha=255;
	ObjRender_SetScaleXYZ(bg, 1, 1, 1);
	
	ObjRender_SetPosition(bg, GetScreenWidth/2-250, GetScreenHeight/2, -120);
	
	while(!Obj_IsDeleted(bg)){
		
if (bSpell==false&&alpha<255){alpha+=15;}
if (bSpell==true&&alpha>0){alpha-=5;}

ObjRender_SetAlpha(bg, alpha);
	t+=1.5; 

	ObjSprite3D_SetSourceDestRect(bg, 0, t, 4096, 4096+t);
	yield;}
	
	Obj_Delete(bg);
	
	}
		
	
}

task Tier5BGCherry2
{
		
SetFogEnable(true);
let param=0;
SetCameraFocusXYZ(GetScreenWidth/2, GetScreenHeight/2, -220);
SetCameraElevationAngle(-60);
Background1; 

	task Background1{
		
	let bg=ObjPrim_Create(OBJ_SPRITE_3D);
	let t=0;
	ObjPrim_SetTexture(bg, GetCurrentScriptDirectory~"/img/bgcherry4.png");
	ObjSprite3D_SetSourceDestRect(bg, 0, 0, 1024, 1024);
	Obj_SetRenderPriorityI(bg, 0);
	
	let alpha=255;
	ObjRender_SetScaleXYZ(bg, 0.7, 0.7, 0.7);
	
	ObjRender_SetPosition(bg, GetScreenWidth/2-250, GetScreenHeight/2+10, -120);
	
	while(!Obj_IsDeleted(bg)){
		
if (bSpell==false&&alpha<255){alpha+=15;}
if (bSpell==true&&alpha>0){alpha-=5;}

ObjRender_SetAlpha(bg, alpha);
	t+=1.5; 

	ObjSprite3D_SetSourceDestRect(bg, 0, t, 4096, 4096+t);
	yield;}
	

	Obj_Delete(bg);
	}
		
	
}



task TSpellBackground
{
let obj=ObjPrim_Create(OBJ_SPRITE_2D);


ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/cdbg13.png");


ObjRender_SetPosition(obj, GetScreenWidth/2+60, GetScreenHeight/2+30, 0);


ObjSprite2D_SetSourceRect(obj, 0, 0, 512, 512);
ObjRender_SetBlendType(obj, BLEND_ALPHA);

ObjRender_SetScaleXYZ(obj, 1.1, 1.1, 1.1);

ObjSprite2D_SetDestCenter(obj);



Obj_SetRenderPriorityI(obj, 20);

let t=0;
let angle=0;


while(!Obj_IsDeleted(obj)){


if (bSpell==true&&alpha<200){alpha+=5;}
if (bSpell==false&&alpha>0){alpha-=15;}
ObjRender_SetAlpha(obj, alpha);

yield;}
}

task TSpellBackground3{
	
	let v = 384;
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/cdbg05b.png");
	ObjPrim_SetVertexCount(obj, (v+1)*2);
	ObjRender_SetPosition(obj, GetScreenWidth/2, GetScreenHeight/2, 0);
	Obj_SetRenderPriorityI(obj, 20);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjSprite2D_SetDestCenter(obj);
	let x = 0;
	Color(obj);
		while(!Obj_IsDeleted(obj)){

loop{
		ascent(i in 0..v+1){
			ObjPrim_SetVertexUVT(obj, i*2, 64+x, 0+(512/v)*i);
			ObjPrim_SetVertexUVT(obj, i*2-1, 448+x, 0+(512/v)*i);
		}

		ascent(i in 0..v+1){
			ObjPrim_SetVertexPosition(obj, i*2, 450*cos((360/v)*i-90), 450*sin((360/v)*i-90), 0	);
			ObjPrim_SetVertexPosition(obj, i*2-1, 0, 0, 0);
		}

		x++;
		yield;
if (bSpell==true&&alpha<200){alpha+=5;}
if (bSpell==false&&alpha>0){alpha-=15;}
ObjRender_SetAlpha(obj, alpha);

yield;}
		}
		
		task Color(obj){
	let alpha=255;
	let c=0;
	loop{
	 ObjRender_SetColorHSV(obj, c, 255, alpha);

	c += 0.5;

	yield;}
}

}