
let bSpell = false;
let current = GetCurrentScriptDirectory();
let trailpath = GetCurrentScriptDirectory~"./img/nbg3.png";
let greenpath = GetCurrentScriptDirectory~"./img/nbg1.png";
let tiltangle = 30;
let time = 0;
let objtrees = [];
let objpath = [];
let bloop = true;


let f = 0.5;
let f1 = 0;
let f2 = 0;
let f3 = 0;
let f7 = 0;
let f4 = 0;
let f8 = 0;
let acc1 = 0;
let acc2 = 0;
let acc7 = 0;
let acc6 = -1110;
let ff = 0.5;


@Initialize
{
	SetCameraFocusXYZ(0, -60, 80);
	SetViewFrom(10, -90, 25+10*cos(0));
	 SetFogParam ( 350, 750, 25, 25, 112); 

	

	StartNamelessPath;
	TSpellBackground();
}

@MainLoop
{

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


function SetViewFrom(radius, azimuth, elevation){
SetCameraRadius(radius);
SetCameraAzimuthAngle(azimuth);
SetCameraElevationAngle(elevation);
}

task StartNamelessPath{

let obj = ObjPrim_Create(OBJ_SPRITE_3D);
	  //SetAlpha(255);
      ObjRender_SetBlendType(obj, BLEND_ALPHA);
	  Obj_SetRenderPriorityI(obj,21);
	 ObjRender_SetPermitCamera(obj, true);
      ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./img/nbg1.png");
      ObjSprite3D_SetSourceDestRect(obj, 0, 0+f8, 500, 1500+f8);
      ObjRender_SetAngleXYZ(obj, 90, 0, 0);
      ObjRender_SetScaleXYZ(obj, 1, 1, 1);
      ObjRender_SetPosition(obj, 0, -300, 600);

	   //SetAlpha(255);
	   let obj2 = ObjPrim_Create(OBJ_SPRITE_3D);
	  ObjRender_SetBlendType(obj2, BLEND_ALPHA);
	  Obj_SetRenderPriorityI(obj2,22);
	    ObjRender_SetPermitCamera(obj2, true);
      ObjPrim_SetTexture(obj2,GetCurrentScriptDirectory~"./img/nbg3.png");
      ObjSprite3D_SetSourceDestRect(obj2, 0, 0+f8, 512, 1500+f8);
      ObjRender_SetAngleXYZ(obj2, 90, 0, 0);
      ObjRender_SetScaleXYZ(obj2, 0.5, 1, 1);
      ObjRender_SetPosition(obj2, 0, -300, 600);
	
	
	
	  let obj5 = ObjPrim_Create(OBJ_SPRITE_3D);
      ObjRender_SetBlendType(obj5, BLEND_ALPHA);
	   Obj_SetRenderPriorityI(obj5,20);
      ObjPrim_SetTexture(obj5,GetCurrentScriptDirectory~"./img/nbg2.png");
	  ObjSprite3D_SetSourceDestRect(obj5, 1, 1, 256, 256);
	  ObjRender_SetAngleXYZ(obj5, 0, 180, 180);
      ObjRender_SetScaleXYZ(obj5, 10, 10, 1);
	  ObjRender_SetPosition(obj5, 0, 0, 1900); 
	   ObjRender_SetPermitCamera(obj5, true);
	  

	loop(10){
	  let obj3 = ObjPrim_Create(OBJ_SPRITE_3D);
      ObjRender_SetBlendType(obj3, BLEND_ALPHA);
	  Obj_SetRenderPriorityI(obj3,23);
	  objtrees = objtrees ~ [obj3];
      ObjPrim_SetTexture(obj3,GetCurrentScriptDirectory~"./img/nbg5.png");
	  ObjSprite3D_SetSourceDestRect(obj3, 0, 0, 512, 700);
	  ObjRender_SetAngleXYZ(obj3, 0, 0, 180);
      ObjRender_SetScaleXYZ(obj3, 0.5,0.5, 1);
	  ObjRender_SetPosition(obj3, 180, -150, 1200-f+acc6);
		 ObjRender_SetPermitCamera(obj3, true);

	  let obj4 = ObjPrim_Create(OBJ_SPRITE_3D);
      ObjRender_SetBlendType(obj4, BLEND_ALPHA);
	   Obj_SetRenderPriorityI(obj4,23);
      ObjPrim_SetTexture(obj4,GetCurrentScriptDirectory~"./img/nbg5.png");
	  ObjSprite3D_SetSourceDestRect(obj4, 0, 0, 512, 700);
	  ObjRender_SetAngleXYZ(obj4, 0, 0, 180);
	  objpath = objpath ~ [obj4];
      ObjRender_SetScaleXYZ(obj4, 0.5,0.5, 1);
	  ObjRender_SetPosition(obj4, -180, -150, 1200-f+acc6);  
 ObjRender_SetPermitCamera(obj4, true);	  
acc6-=110;
}


acc6 = 0;
	  loop{
	  if(time>=90){
	   if(ff<2){ ff+=0.02; }
	  if(f>110){ f=0; }
	  if(acc7 < 180){acc7 += 1;}
	  SetViewFrom(10, -90, 25+10*cos(acc7));
	  }
	  acc2+=0.1;
	 time++;
	 
	 
	  
      ObjRender_SetBlendType(obj, BLEND_ALPHA);
	  Obj_SetRenderPriorityI(obj,21);
	 
      ObjPrim_SetTexture(obj,GetCurrentScriptDirectory~"./img/nbg1.png");
      ObjSprite3D_SetSourceDestRect(obj, 0, 0+f8, 500, 1500+f8);
      ObjRender_SetAngleXYZ(obj, 90, 0, 0);
      ObjRender_SetScaleXYZ(obj, 1, 1, 1);
      ObjRender_SetPosition(obj, 0, -300, 600);
	  
	  ObjRender_SetBlendType(obj2, BLEND_ALPHA);
	  Obj_SetRenderPriorityI(obj2,22);
	   
      ObjPrim_SetTexture(obj2,GetCurrentScriptDirectory~"./img/nbg3.png");
      ObjSprite3D_SetSourceDestRect(obj2, 0, 0+f8, 512, 1500+f8);
      ObjRender_SetAngleXYZ(obj2, 90, 0, 0);
      ObjRender_SetScaleXYZ(obj2, 0.5, 1, 1);
      ObjRender_SetPosition(obj2, 0, -300, 600);
	
      ObjRender_SetBlendType(obj5, BLEND_ALPHA);
	   Obj_SetRenderPriorityI(obj5,20);
      ObjPrim_SetTexture(obj5,GetCurrentScriptDirectory~"./img/nbg2.png");
	  ObjSprite3D_SetSourceDestRect(obj5, 1, 1, 256, 256);
	  ObjRender_SetAngleXYZ(obj5, 0, 180, 180);
      ObjRender_SetScaleXYZ(obj5, 10, 10, 1);
	  ObjRender_SetPosition(obj5, 0, 0, 1900); 
	  
	  

	ascent(i in 0..length(objtrees)){
		
     
	  ObjRender_SetPosition(objtrees[i], 180, -150, 1200-f+acc6);
	  ObjRender_SetPosition(objpath[i], -180, -150, 1200-f+acc6);
	  acc6-=110;
   
}
	acc6 = 0;	

wait(1);
}
}


function wait(w){ loop(w){ yield; } }

task TSpellBackground
{
	let path1 = current ~ "img/youmu.png";
	let path2 = current ~ "img/sakura02.png";
	
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj1, BLEND_ALPHA);
	Obj_SetRenderPriority(obj1, 0.24);
	ObjPrim_SetTexture(obj1, path1);
	ObjSprite2D_SetDestRect(obj1, -10, -10, 522, 522);
	ObjRender_SetScaleX(obj1, 384/512);
	ObjRender_SetScaleY(obj1, 448/512);
	
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj2, BLEND_ALPHA);
	Obj_SetRenderPriority(obj2, 0.24);
	ObjPrim_SetTexture(obj2, path2);
	ObjSprite2D_SetSourceRect(obj2, 0, 0, 1024, 1024);
	ObjSprite2D_SetDestRect(obj2, -512/2, -512/2, 512/2, 512/2);
	ObjRender_SetScaleX(obj2, 1.5);
	ObjRender_SetAlpha(obj2, 255/3.35);
	ObjRender_SetScaleY(obj2, 1.5);
	ObjRender_SetColor(obj2, 186, 85, 211);
	ObjRender_SetX(obj2, GetStgFrameWidth/2);
	ObjRender_SetY(obj2, GetStgFrameHeight/2);
	Obj_SetVisible(obj2, false);

	
	let u1 = 0;
	let v1 = 0;
	let u2 = 0;
	let v2 = 0;
	let su2 = rand(0.25, 1);
	let sv2 = rand(0.25, 1);
	let alpha = 0;
	let frame = 0;
	let turn = 3;
	let turnacc = 3.10;
	loop
	{
	if(GetCommonData("MimaSama", false)==true &&  bloop==true){ path1 = current ~ "img/mima.png";  ObjPrim_SetTexture(obj1, path1); bloop=false;}
		if(bSpell)
		{
			if(alpha<255){
			alpha += 4;
			}
		}
		else if(alpha>0){
			alpha -=8;
		}

		v1 -= 1;
		if(v1 < 256){v1+=256;}
		u2 += su2;
		if((su2 > 0 && u2 > 256) || (su2 < 0 && u2 < -256))
		{
			u2=0;
			//su2 = rand(0.25, 1);
			if(rand(0, 1) < 0.5){su2 *= -1;}
		}
		v2 += sv2;
		if((sv2 > 0 && v2 > 256) || (sv2 < 0 && v2 < -256))
		{
			v2 = 0;
			//sv2 = rand(0.25, 1);
			if(rand(0, 1) < 0.5){sv2 *= -1;}
		}

		ObjRender_SetAlpha(obj1, alpha);
		Obj_SetVisible(obj1, alpha > 0);
		ObjSprite2D_SetSourceRect(obj1, 0, 0, 512, 512);
		
		if(GetCommonData("petals", false)==true){
		Obj_SetVisible(obj2, true);
		ObjRender_SetAngleXYZ(obj2, 0, 0, 0+turn);
		turn+=turnacc;
		turnacc-=1.5/30;
		}
		else{
		turnacc = 3.10;
		Obj_SetVisible(obj2, false);
		}
		
		frame++;
		yield;
	}
	

}
