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

	SetFogParam(0, 500, 182, 3, 252);

	TNormalBackground();
	TNormalBackground2();
	
	TNormalBackground3();

	//RedEarth();
	//EarthAura();
	TSpellBackground();
	//TSpellBackground2();
	TSpellBackground3();
	TSpellBackground4();
}

@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, -200);
SetCameraElevationAngle(-160);
Background1; 
SettleIn;
task SettleIn{
let ang=0;
loop(120){
//SetCameraElevationAngle(-35*sin(ang));
ang+=90/120;
SetFogParam(param, 2300,154, 33, 207);
yield;}
}
	task Background1{
	let bg=ObjPrim_Create(OBJ_SPRITE_3D);
	let t=0;
	ObjPrim_SetTexture(bg, GetCurrentScriptDirectory~"/img/stage05a.png");
	ObjSprite3D_SetSourceDestRect(bg, 0, 0, 512, 512);
	Obj_SetRenderPriorityI(bg, 0);
	
	let alpha=255;
	ObjRender_SetScaleXYZ(bg, 1, 1, 1);
	ObjRender_SetPosition(bg, GetScreenWidth/2, 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-125);
	t+=0.5; 
	ObjSprite3D_SetSourceDestRect(bg, 0, t, 4096, 4096+t);
	yield;}
	}
	
}

task TNormalBackground2
{

Background1; 

	task Background1{
	let bg=ObjPrim_Create(OBJ_SPRITE_3D);
	let t=0;
	let t2=0;
	ObjPrim_SetTexture(bg, GetCurrentScriptDirectory~"/img/ground.png");
	ObjSprite3D_SetSourceDestRect(bg, 0, 0, 512, 512);
	Obj_SetRenderPriorityI(bg, 0);
	
	let alpha=255;
	ObjRender_SetScaleXYZ(bg, 1, 1, 1);
	ObjRender_SetPosition(bg, GetScreenWidth/2, GetScreenHeight/2, -100);
	
	while(!Obj_IsDeleted(bg)){
if (bSpell==false&&alpha<255){alpha+=15;}
if (bSpell==true&&alpha>0){alpha-=5;}
ObjRender_SetAlpha(bg, alpha-125);
	t+=0.5; 
	
	ObjSprite3D_SetSourceDestRect(bg, 0, t, 4096, 4096+t);
	yield;}
	}
	
	
	
}

task TNormalBackground3
{

Background1; 

	task Background1{
	let bg=ObjPrim_Create(OBJ_SPRITE_3D);
	let t=0;
	let t2=0;
	ObjPrim_SetTexture(bg, GetCurrentScriptDirectory~"/img/leaf.png");
	ObjSprite3D_SetSourceDestRect(bg, 0, 0, 354, 512);
	Obj_SetRenderPriorityI(bg, 0);
	
	let alpha=255;
	ObjRender_SetScaleXYZ(bg, 1.25, 1.25, 1);
	ObjRender_SetPosition(bg, GetScreenWidth/2+60, GetScreenHeight/2, -280);
	while(!Obj_IsDeleted(bg)){
if (bSpell==false&&alpha<255){alpha+=15;}
if (bSpell==true&&alpha>0){alpha-=5;}
ObjRender_SetAlpha(bg, alpha);
	t+=0.5; 
	t2+=0.25;
	ObjSprite3D_SetSourceDestRect(bg, 0, t, 512, 1024+t);
	yield;}
	}
	
}


task TSpellBackground
{
let obj=ObjPrim_Create(OBJ_SPRITE_2D);


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


ObjRender_SetPosition(obj, GetScreenWidth/2-90, GetScreenHeight/2-110, 0);


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


ObjRender_SetScaleXYZ(obj, 2.3, 2.3, 2);

ObjSprite2D_SetDestCenter(obj);

Obj_SetRenderPriorityI(obj, 20);

let t=0;
let angle=0;


while(!Obj_IsDeleted(obj)){
ObjSprite2D_SetSourceRect(obj, 0, t, 1280, 1280+t);
if (bSpell==true&&alpha<200){alpha+=5;}
if (bSpell==false&&alpha>0){alpha-=15;}
ObjRender_SetAlpha(obj, alpha);

yield;}
}

task TSpellBackground3
{
let obj=ObjPrim_Create(OBJ_SPRITE_2D);


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


ObjRender_SetPosition(obj, GetScreenWidth/2, GetScreenHeight/2, 0);

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


ObjRender_SetScaleXYZ(obj, 1, 1, 1);

ObjSprite2D_SetDestCenter(obj);

Obj_SetRenderPriorityI(obj, 20);

let t=0;
let angle=0;

while(!Obj_IsDeleted(obj)){

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

yield;}
}

task TSpellBackground4
{
let obj=ObjPrim_Create(OBJ_SPRITE_2D);


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


ObjRender_SetPosition(obj, GetScreenWidth/2, GetScreenHeight/2, 0);

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


ObjRender_SetScaleXYZ(obj, 1, 1, 1);

ObjSprite2D_SetDestCenter(obj);

Obj_SetRenderPriorityI(obj, 20);

let t=0;
let angle=0;

while(!Obj_IsDeleted(obj)){

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

yield;}
}



task TSpellBackground2{
	
	let v = 384;
	let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
	
	ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"/img/spellbgSeth.png");
	ObjPrim_SetVertexCount(obj, (v+1)*2);
	ObjRender_SetPosition(obj, GetScreenWidth/2, GetScreenHeight/2- 90, 0);
	Obj_SetRenderPriorityI(obj, 15);
	ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	ObjSprite2D_SetDestCenter(obj);
	let x = 0;

		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;}
		}


}

