//StageBackground goes here

task Elev{
SetCameraElevationAngle(25);
while(GetCommonData("IsBoss", 0) == 0){yield;}
ascent(i in 0..90){
SetCameraElevationAngle(25*sin(i+90));
wait(2);
}
}

task WorldBG{
Elev;
	SetCameraFocusX(0);
	SetCameraFocusY(100);
	SetCameraFocusZ(500);
	SetCameraRadius(250);
	SetCameraAzimuthAngle(90);
	SetFogParam(500,1200,0,0,0);
	SetCameraPerspectiveClip(10, 2400);

	let ground = ObjPrim_Create(OBJ_SPRITE_3D);
	Obj_SetRenderPriorityI(ground, 25);
	ObjPrim_SetTexture(ground, GetCurrentScriptDirectory ~ "/img/Ingame/world1.png");
	ObjRender_SetBlendType(ground, BLEND_ALPHA);
	ObjRender_SetAlpha(ground, 255);
	ObjSprite3D_SetSourceRect(ground, 0, 0, 256, 256);
	ObjRender_SetPosition(ground, 0, 0, 0);
	ObjRender_SetAngleX(ground, 90);
	
	let ground2 = ObjPrim_Create(OBJ_SPRITE_3D);
	Obj_SetRenderPriorityI(ground2, 24);
	ObjPrim_SetTexture(ground2, GetCurrentScriptDirectory ~ "/img/Ingame/world2.png");
	ObjRender_SetBlendType(ground2, BLEND_ALPHA);
	ObjRender_SetAlpha(ground2, 255);
	ObjSprite3D_SetSourceRect(ground2, 0, 0, 256, 256);
	ObjRender_SetPosition(ground2, -55, 0, 0);
	ObjRender_SetAngleX(ground2, 90);
	
	let sky = ObjPrim_Create(OBJ_SPRITE_3D);
	Obj_SetRenderPriorityI(sky, 23);
	ObjPrim_SetTexture(sky, GetCurrentScriptDirectory ~ "/img/Ingame/sky.png");
	ObjSprite3D_SetSourceRect(sky, 0, 0, 512, 512);
	ObjSprite3D_SetDestRect(sky, -0, -0, 1024, 1024);
	ObjRender_SetPosition(sky, -600, 800, -800);
	ObjRender_SetFogEnable(sky, false);
	ObjRender_SetAngleX(sky, 180);
	ObjRender_SetScaleXYZ(sky, 1.5,1, 0);
	
	let star = ObjPrim_Create(OBJ_SPRITE_3D);
	Obj_SetRenderPriorityI(star, 22);
	ObjPrim_SetTexture(star, GetCurrentScriptDirectory ~ "/img/Ingame/world3.png");
	ObjRender_SetBlendType(star, BLEND_ADD_ARGB);
	ObjRender_SetAlpha(star, 255);
	ObjSprite3D_SetSourceRect(star, 0, 0, 2048, 4096);
	ObjSprite3D_SetDestRect(star, -1024, -2048, 1024, 2048);
	ObjRender_SetPosition(star, 0, 400, 0);
	ObjRender_SetFogEnable(star, false);
	ObjRender_SetAngleX(star, 90);

	let pos = 0;
	while(true){
		ObjSprite3D_SetSourceDestRect(ground,0,-256*2+(pos),256,256*5+pos);
		ObjSprite3D_SetSourceDestRect(ground2,0,-256*2+(pos),256*6,256*5+pos);
		
		ObjSprite3D_SetSourceRect(star, 0, pos, 2048, 4096 + pos);
		ObjSprite3D_SetDestRect(star, -1024, -2048, 1024, 2048);
		
		pos -= 2;
		yield;
	}
	//Obj_Delete(ground);
}


//Spellbackground goes here tho

task MidSpell1{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/bg21.png");
	ObjSprite2D_SetSourceRect(obj,0,0,384,448);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(obj, 255);
	loop{
	ObjRender_SetAlpha(obj, count*5);
	count++;
	yield;
	}
	Obj_Delete(obj);
}

task MidSpell2(mult){
	let count = 0;
	let count2 = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/bg22.png");
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,2,2,2);
	ObjRender_SetAngleY(obj, 0*mult*180);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	loop{
	ObjSprite2D_SetSourceRect(obj,0+(count2*mult),0+count2,256+(count2*mult),256+count2);
	if(count<25){ObjRender_SetAlpha(obj, count*5);}
	count++;
	count2+=0.5;
	yield;
	}
	Obj_Delete(obj);
}

task Mid2Spell1{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/bg31.png");
	ObjSprite2D_SetSourceRect(obj,0,0,384,448);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(obj, 255);
	loop{
	ObjSprite2D_SetSourceRect(obj,0,0+count/2,256,256+count/2);
	ObjRender_SetAlpha(obj, count*5);
	count++;
	yield;
	}
	Obj_Delete(obj);
}

task Mid2Spell2(mult){
	let count = 0;
	let count2 = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/bg32.png");
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,2.25,2.25,2);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	loop{
	ObjRender_SetAngleZ(obj, count2*mult);
	if(count<35){ObjRender_SetAlpha(obj, count*5);}
	count++;
	count2+=0.5;
	yield;
	}
	Obj_Delete(obj);
}

task Spell1{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/bg1.png");
	ObjSprite2D_SetSourceRect(obj,0,0,384,448);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(obj, 255);
	loop{
	ObjRender_SetAlpha(obj, count*5);
	count++;
	yield;
	}
	Obj_Delete(obj);
}

task Spell2{
	let vertexcount = 64*8;
	let innerrad = 0;
	let outerrad = 256*1.75;
	let mov = 1;
	let alpha = 0;
    let obj = ObjPrim_Create(OBJ_PRIMITIVE_2D);
    ObjPrim_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
    ObjPrim_SetTexture(obj, GetCurrentScriptDirectory ~ "/img/Ingame/bg2.png");
    Obj_SetRenderPriorityI(obj, 26);
    ObjPrim_SetVertexCount(obj, vertexcount);
	ObjRender_SetBlendType(obj, BLEND_MULTIPLY);
 
    ascent(i in 0..vertexcount/2){
        let indexvert = i*2;
        let angle = 360/(vertexcount/2-1)*i;
        ObjPrim_SetVertexPosition(obj,indexvert+0,innerrad+25*cos(angle),innerrad+25*sin(angle),0);
        ObjPrim_SetVertexPosition(obj,indexvert+1,outerrad*cos(angle),outerrad*sin(angle),0);
		ObjPrim_SetVertexColor(obj, indexvert+1, 255, 0, 0);
    }
   
    while(!Obj_IsDeleted(obj)){
	let X = GetStgFrameWidth/2+100-20;
	let Y = GetStgFrameHeight/2-100-20;
        ascent(i in 0..vertexcount/2){
            let indexvert = i*2;
            let angle = 360/(vertexcount/2-1)*i;
            ObjPrim_SetVertexUVT(obj, indexvert, 512/(vertexcount/2-1)*i, 0+mov);
            ObjPrim_SetVertexUVT(obj, indexvert+1, 512/(vertexcount/2-1)*i, 384+mov);
        }
		ObjRender_SetPosition(obj, X, Y, 0);
		mov-=3.5;
		yield;
    }
}

task SanSpell1{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/bgsan1.png");
	ObjSprite2D_SetSourceRect(obj,0,0,384,448);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(obj, 255);
	loop{
	if(count<255){ObjRender_SetAlpha(obj, count*5);}
	count++;
	yield;
	}
	Obj_Delete(obj);
}

task SanSpell2{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/bgsan2.png");
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(obj, 255);
	loop{
	ObjSprite2D_SetSourceRect(obj,0,0+count/2,512,512+count/2);
	ObjRender_SetColorHSV(obj, 255+count, 255, 255);
	if(count<122/5){ObjRender_SetAlpha(obj, count*5);}
	count++;
	yield;
	}
	Obj_Delete(obj);
}

task ReiSpell1{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/bgrei1.png");
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,2,2.2,1);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(obj, 255);
	loop{
	if(count<255){ObjRender_SetAlpha(obj, count*5);}
	count++;
	yield;
	}
	Obj_Delete(obj);
}

task ReiSpell2{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/bgrei2.png");
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,2.3,2.3,1);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(obj, 255);
	loop{
	ObjRender_SetAngleZ(obj, count/2);
	ObjRender_SetAlpha(obj, count*5);
	count++;
	yield;
	}
	Obj_Delete(obj);
}

task MarSpell1{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/bgmar1.png");
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1.75,1.75,1);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(obj, 255);
	loop{
	if(count<255){ObjRender_SetAlpha(obj, count*5);}
	count++;
	yield;
	}
	Obj_Delete(obj);
}

task MarSpell2{
	let count = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "/img/Ingame/bgmar2.png");
	ObjSprite2D_SetSourceRect(obj,0,0,512,512);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,1);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2, GetStgFrameHeight/2,0);
	ObjRender_SetAlpha(obj, 255);
	loop{
	ObjSprite2D_SetSourceRect(obj,0,0+count,512,512+count);
	if(count<170/5){ObjRender_SetAlpha(obj, count*5);}
	count++;
	yield;
	}
	Obj_Delete(obj);
}

