//ajs
let CSD = GetCurrentScriptDirectory;
let objScene = GetEnemyBossSceneObjectID;

let OnSpell = false;

@Initialize{
	SetCameraFocusX(0);
	SetCameraFocusY(0);
	SetCameraFocusZ(0);
	SetCameraRadius(800);
    SetCameraElevationAngle(-10);
	SetCameraAzimuthAngle(90);

	bgcontrol;
	SpellBG1;
	SpellBG2;
	SpellBG3;
	SpellBG4;
	SpellBG5;
}

@MainLoop{
     

OnSpell = (GetEnemyBossSceneObjectID != ID_INVALID && ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_IS_SPELL)); 

	yield;
	}


task bgcontrol{
Background;

}

function SpriteCreate{
let obj = ObjPrim_Create(OBJ_SPRITE_3D);
ObjPrim_SetTexture(obj,CSD~"./img/stgbg.png");
Obj_SetRenderPriorityI(obj,20);
ObjRender_SetAngleX(obj,-30);
ObjSprite3D_SetSourceDestRect(obj,0,0,256,256);
ObjRender_SetScaleXYZ(obj,2,2,1.5);
ObjRender_SetBlendType(obj,BLEND_ALPHA);
ObjRender_SetColor(obj,200,200,200);
return obj
}

task Background{
SetCameraElevationAngle(-20);


let obj = [SpriteCreate];
ObjRender_SetAlpha(obj[0],255);
        let alpha = 0;
	let frameInvisible = 0;
	let movel = 0;
	let movel2 = 0;
	let YAW = 0;
	let ROLL = 0;
	let counter = 0;
	loop
	{
	YAW = 8*sin(counter*0.5);
	ROLL = 12*sin(counter*0.5);
	//YAW = (GetScreenWidth/2-GetPlayerX)/30;
	//ROLL = (GetScreenWidth/2-GetPlayerX)/30;
	
	SetCameraYaw(YAW);
	SetCameraRoll(ROLL);
	counter++;
	
    movel+=0;
    movel2+=1.5;
     ObjSprite3D_SetSourceDestRect(obj[0],0,0+movel2,(256*6)+movel,(256*6)+movel2);
               ascent(i in 0..length(obj)){
	//	ObjRender_SetAlpha(obj[i],alpha);
          //      ObjRender_SetAlpha(objg,alpha);
                }

    	if(alpha > 255){
        	alpha = 255;
        	}
        	if(alpha < 0){
        	alpha = 0;
        	}
                
		yield;
	}
}

task SpellBG1{
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj1, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj1, 21);
	ObjPrim_SetTexture(obj1, GetCurrentScriptDirectory~"./img/splbg1_1.png");
	ObjRender_SetScaleXYZ(obj1, 0.5, 0.5, 1);
	ObjSprite2D_SetSourceRect(obj1, 0, 0, 512, 512);
	ObjSprite2D_SetDestRect(obj1, -256, -256, 256, 256);
	ObjRender_SetPosition(obj1, GetScreenWidth/2, GetScreenHeight/2, 0);
	
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj2, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj2, 22);
	ObjPrim_SetTexture(obj2, GetCurrentScriptDirectory~"./img/splbg1_2.png");
	ObjRender_SetScaleXYZ(obj2, 0.75, 0.75, 1);
	ObjSprite2D_SetSourceRect(obj2, 0, 0, 256, 256);
	ObjSprite2D_SetDestRect(obj2, -256, -256, 256, 256);
	ObjRender_SetPosition(obj2, GetScreenWidth/2, GetScreenHeight/2, 0);
	
	let frame = 0;
	let alpha = 0;
	let alpha2 = 0;
	let angle = 0;
	let angle2 = 0;
	let rect = 800;
	let rect2 = 1000;
	loop{		
		
		if(GetCommonData("SpellCard1",false)==true) {
			if(alpha < 255) { alpha += 255/90;}} 
		else {if(alpha>0){alpha -= 4;}}
		
		frame++;
		ObjRender_SetAlpha(obj1, alpha);
		ObjRender_SetAlpha(obj2, alpha);
		ObjRender_SetAngleZ(obj2,angle);
		angle+=1;
		ObjSprite2D_SetDestRect(obj1, -rect, -rect2, rect, rect2);
		ObjSprite2D_SetSourceRect(obj1, 0, 0, rect, rect2);
		rect+=2;
		//rect2++;
		yield;}
}

task SpellBG2{
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj1, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj1, 21);
	ObjPrim_SetTexture(obj1, GetCurrentScriptDirectory~"./img/splbg2_1.png");
	ObjRender_SetScaleXYZ(obj1, 1.4, 1.4, 1);
	ObjSprite2D_SetSourceRect(obj1, 0, 0, 256, 256);
	ObjSprite2D_SetDestRect(obj1, -256, -256, 256, 256);
	ObjRender_SetPosition(obj1, GetScreenWidth/2, GetScreenHeight/2, 0);
	
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj2, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj2, 22);
	ObjPrim_SetTexture(obj2, GetCurrentScriptDirectory~"./img/splbg2_2.png");
	ObjRender_SetScaleXYZ(obj2, 1.4, 1.4, 1);
	ObjSprite2D_SetSourceRect(obj2, 0, 0, 256, 256);
	ObjSprite2D_SetDestRect(obj2, -256, -256, 256, 256);
	ObjRender_SetPosition(obj2, GetScreenWidth/2, GetScreenHeight/2, 0);
	
	let frame = 0;
	let alpha = 0;
	let alpha2 = 0;
	let angle = 0;
	let angle2 = 0;
	let rect = 800;
	let rect2 = 1000;
	loop{		
		
		if(GetCommonData("SpellCard2",false)==true) {
			if(alpha < 255) { alpha += 255/90;}} 
		else {if(alpha>0){alpha -= 4;}}
		
		frame++;
		ObjRender_SetAlpha(obj1, alpha);
		ObjRender_SetAlpha(obj2, alpha);
		ObjRender_SetAngleZ(obj2,angle);
		angle+=0.5;
		//ObjSprite2D_SetDestRect(obj1, -rect, -rect2, rect, rect2);
		//ObjSprite2D_SetSourceRect(obj1, 0, 0, rect, rect2);
		rect+=2;
		//rect2++;
		yield;}
}

task SpellBG3{
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj1, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj1, 22);
	ObjPrim_SetTexture(obj1, GetCurrentScriptDirectory~"./img/splbg3_1.png");
	ObjRender_SetScaleXYZ(obj1, 1.4, 1.4, 1);
	ObjSprite2D_SetSourceRect(obj1, 0, 0, 384, 448);
	ObjSprite2D_SetDestRect(obj1, -256, -256, 256, 256);
	ObjRender_SetPosition(obj1, GetScreenWidth/2, GetScreenHeight/2, 0);
	ObjRender_SetColor(obj1,200,200,200);
	
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj2, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj2, 21);
	ObjPrim_SetTexture(obj2, GetCurrentScriptDirectory~"./img/splbg3_2.png");
	ObjRender_SetScaleXYZ(obj2, 3, 3, 1);
	ObjSprite2D_SetSourceRect(obj2, 0, 0, 256, 256);
	ObjSprite2D_SetDestRect(obj2, -256, -256, 256, 256);
	ObjRender_SetPosition(obj2, GetScreenWidth/2, GetScreenHeight/2, 0);
	
	let frame = 0;
	let alpha = 0;
	let alpha2 = 0;
	let angle = 0;
	let angle2 = 0;
	let rect = 800;
	let rect2 = 1000;
	let slide = 0;
	loop{		
		
		if(GetCommonData("SpellCard3",false)==true) {
			if(alpha < 255) { alpha += 255/90;}} 
		else {if(alpha>0){alpha -= 4;}}
		
		frame++;
		ObjRender_SetAlpha(obj1, alpha);
		ObjRender_SetAlpha(obj2, alpha);
		ObjRender_SetAngleZ(obj2,angle);
		//angle+=0.5;
		slide+=1;
		ObjSprite2D_SetSourceRect(obj2,0,0,256,20000+slide);
		ObjSprite2D_SetDestCenter(obj2);
		ObjRender_SetPosition(obj2,GetScreenWidth/2,GetScreenHeight/2-(slide*1.5),0);
		rect+=1;
		//rect2++;
		yield;}
}

task SpellBG4{
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj1, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj1, 21);
	ObjPrim_SetTexture(obj1, GetCurrentScriptDirectory~"./img/splbg4.png");
	ObjRender_SetScaleXYZ(obj1, 1.3, 1.3, 1);
	ObjSprite2D_SetSourceRect(obj1, 0, 0, 500, 500);
	ObjSprite2D_SetDestRect(obj1, -256, -256, 256, 256);
	ObjRender_SetPosition(obj1, GetScreenWidth/2, GetScreenHeight/2, 0);
		
	let frame = 0;
	let alpha = 0;
	let angle = 0;
	let scaleX = 2.0;
	let scaleY = 2.0;
	loop{		
		
		if(GetCommonData("SpellCard4",false)==true) {
			if(alpha < 255) { alpha += 255/90;}} 
		else {if(alpha>0){alpha -= 4;}}
		
		frame++;
		ObjRender_SetAlpha(obj1, alpha);
		
		scaleX = 2.2+0.7*sin(frame*0.5);
		scaleY = 2.2-0.7*sin(frame*0.5);
		
		ObjRender_SetScaleXYZ(obj1,scaleX,scaleY,1);
		
		angle+=0.5;
		ObjRender_SetAngleZ(obj1,angle);
		
		yield;}
}

task SpellBG5{
	let obj1 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj1, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj1, 21);
	ObjPrim_SetTexture(obj1, GetCurrentScriptDirectory~"./img/splbg5_1.png");
	ObjRender_SetScaleXYZ(obj1, 1, 1, 2);
	ObjSprite2D_SetSourceRect(obj1, 0, 0, 512, 256);
	ObjSprite2D_SetDestRect(obj1, -256, -256, 256, 256);
	ObjRender_SetPosition(obj1, GetScreenWidth/2, GetScreenHeight/2, 0);
	ObjRender_SetColor(obj1,200,200,200);
	
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(obj2, BLEND_ALPHA);
	Obj_SetRenderPriorityI(obj2, 22);
	ObjPrim_SetTexture(obj2, GetCurrentScriptDirectory~"./img/splbg5_2.png");
	ObjRender_SetScaleXYZ(obj2, 1, 1, 2);
	ObjSprite2D_SetSourceRect(obj2, 0, 0, 256, 256);
	ObjSprite2D_SetDestRect(obj2, -256, -256, 256, 256);
	ObjRender_SetPosition(obj2, GetScreenWidth/2, GetScreenHeight/2, 0);
	
	let frame = 0;
	let alpha = 0;
	let alpha2 = 0;
	let angle = 0;
	let angle2 = 0;
	let rect = 800;
	let rect2 = 1000;
	let slide = 0;
	loop{		
		
		if(GetCommonData("SpellCard5",false)==true) {
			if(alpha < 255) { alpha += 255/90;}
			if(alpha2 < 150) {alpha2 += 180/90;}
			slide+=0.5;} 
		else {if(alpha>0){alpha -= 4;}
		if(alpha2>0){alpha2 -= 2;}}
		
		frame++;
		ObjRender_SetAlpha(obj1, alpha);
		ObjRender_SetAlpha(obj2, alpha2);
		
		ObjSprite2D_SetSourceRect(obj1,0,0,768,20000+slide);
		ObjSprite2D_SetDestCenter(obj1);
		ObjRender_SetPosition(obj1,GetScreenWidth/2,GetScreenHeight/2+(slide*1.5),0);
		
		ObjSprite2D_SetSourceRect(obj2,0,0,768+slide,20000+slide);
		ObjSprite2D_SetDestCenter(obj2);
		ObjRender_SetPosition(obj2,GetStgFrameWidth/2-(slide*0.5),GetStgFrameHeight/2-(slide*0.5),0);
		yield;}
}


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