
let current = GetCurrentScriptDirectory;
let SpellActive = false;
let bg1 = GetMainStgScriptDirectory~"source/Stage/stage01a.png";
let bg2 = GetMainStgScriptDirectory~"source/Stage/stage01b.png";
let spbg1 = GetMainStgScriptDirectory~"source/Boss/cdbg1.png";
let spbg2 = GetMainStgScriptDirectory~"source/Boss/cdbg2.png";

@Initialize{	
	StageExBg;
	SpellBG;
}
@MainLoop{
	let asdasd = GetEnemyBossSceneObjectID;
	if(asdasd != ID_INVALID && ObjEnemyBossScene_GetInfo(asdasd, INFO_IS_SPELL)){
		SpellActive = true;
	}else{
		SpellActive = false;
	}
	
	yield;
}


task StageExBg{
	//i suck at this so bear with me
	let StageBG1;	
	let StageBG2;	
	let StageBG3;	
	
	let osize = 0;
	let obj_sizeset = 0;
	let sizeinc = 0;
	
	let osize2 = 0;
	let obj_sizeset2 = 0;
	let sizeinc2 = 0;
	
	SetCameraFocusX(0);
	SetCameraFocusY(0);
	SetCameraFocusZ(0);
	SetCameraRadius(350);
	SetCameraElevationAngle(76);
	SetCameraAzimuthAngle(90);	
	
	StageBG1 = Create3DProperties(255, 1024, bg1, 0.73);
	StageBG2 = Create3DProperties(75, 1024, bg2, 0.74);
	StageBG3 = Create3DProperties(75, 1024, bg2, 0.74);
	
	ObjRender_SetPosition(StageBG1, 0, -871, -580);
	ObjRender_SetAngleXYZ(StageBG1, 50, 0, 90);
	
	ObjRender_SetPosition(StageBG2, 0, -615, -350);
	ObjRender_SetAngleXYZ(StageBG2, 50, 0, 180);
	
	ObjRender_SetPosition(StageBG3, 0, -620, -465);
	ObjRender_SetAngleXYZ(StageBG3, 50, 0, 180);
	
	loop{		
		if(GetCommonData("SelectionSet", 0) == 2){
			Obj_SetRenderPriority(StageBG1, 0.20);
			Obj_SetRenderPriority(StageBG2, 0.21);
			Obj_SetRenderPriority(StageBG3, 0.21);
		}
		
		SetCameraFocusX(osize-75);
		SetCameraFocusZ(osize2);
		CameraShiftX;
		CameraShiftY;
		yield;
	}
	
	task CameraShiftX{
		let ax2 = 0.01;
		let bx2 = 1.25;
		
		if(obj_sizeset==0){sizeinc+=ax2}
		if(obj_sizeset==1){sizeinc-=ax2}		
		if(sizeinc<-bx2){obj_sizeset=0}
		if(sizeinc>bx2){obj_sizeset=1}
		
		osize+=sizeinc;		
	}
	
	task CameraShiftY{
		let ax2 = 0.005;
		let bx2 = 0.2;
		
		if(obj_sizeset2==0){sizeinc2+=ax2}
		if(obj_sizeset2==1){sizeinc2-=ax2}		
		if(sizeinc2<-bx2){obj_sizeset2=0}
		if(sizeinc2>bx2){obj_sizeset2=1}
		
		osize2+=sizeinc2;		
	}
	
	function Create3DProperties(alpha, srcrect, image, priority){
		let StageProp = ObjPrim_Create(OBJ_SPRITE_3D);
		ObjRender_SetBlendType(StageProp, BLEND_ALPHA);
		ObjRender_SetAlpha(StageProp, alpha);
		ObjPrim_SetTexture(StageProp, image);
		Obj_SetRenderPriority(StageProp, priority);
		ObjSprite3D_SetSourceRect(StageProp, 0, 0, srcrect, srcrect);
		ObjSprite3D_SetDestRect(StageProp, -srcrect, -srcrect, srcrect, srcrect);
		ObjRender_SetZWrite(StageProp, true);
		ObjRender_SetZTest(StageProp, true);
		return StageProp;
	}
}

task SpellBG{
	let cdbg2X = 0;
	let fade = 0;
	let spin = 0;
	let position = 256;
	
	let cdbg1Obj = ObjPrim_Create(OBJ_SPRITE_2D);
	let cdbg2Obj1;
	
	SetBG1Properties;
	cdbg2Obj1 = SetBG2Properties;
	
	loop{
	
		if(SpellActive == true){
			if(fade<255){
				fade+=12.75;
			}
		}else{
			fade=0;
		}
		
		if(cdbg2X<=-512){cdbg2X = 0;}
		cdbg2X-=3.5;
		
		ObjRender_SetY(cdbg2Obj1, cdbg2X);
		
		ObjRender_SetAlpha(cdbg1Obj, fade);
		ObjRender_SetAlpha(cdbg2Obj1, fade/1.35);
		
		yield;
	}
	
	task SetBG1Properties{
		ObjRender_SetBlendType(cdbg1Obj, BLEND_ALPHA);
		ObjRender_SetAlpha(cdbg1Obj, fade);
		Obj_SetRenderPriority(cdbg1Obj, 0.22);
		ObjPrim_SetTexture(cdbg1Obj, spbg1);
		ObjSprite2D_SetSourceRect(cdbg1Obj, 0, 0, 256, 256);
		ObjSprite2D_SetDestRect(cdbg1Obj, -36, -36, 484, 516);
	}
	function SetBG2Properties{
		let BG2PropObj = ObjPrim_Create(OBJ_SPRITE_2D);
		ObjRender_SetBlendType(BG2PropObj, BLEND_ALPHA);
		ObjRender_SetAlpha(BG2PropObj, fade);
		ObjRender_SetX(BG2PropObj, 0);
		Obj_SetRenderPriority(BG2PropObj, 0.23);
		ObjPrim_SetTexture(BG2PropObj, spbg2);
		ObjSprite2D_SetSourceRect(BG2PropObj, 0, 0, 256, 512);
		ObjSprite2D_SetDestRect(BG2PropObj, -48, -48, 464, 976);
		return BG2PropObj;
	}
}


function DrawText(txtStr, txtX, txtY, txtSize, txtWidth, presetTxtColor, txtPriority){
	let SnowDrawText = ObjText_Create;
	ObjText_SetText(SnowDrawText,txtStr);
	ObjText_SetFontSize(SnowDrawText,txtSize);
	ObjText_SetHorizontalAlignment(SnowDrawText, ALIGNMENT_LEFT);
	ObjText_SetFontBorderWidth(SnowDrawText,1);
	ObjText_SetFontBorderType(SnowDrawText,BORDER_FULL);
	ObjText_SetMaxWidth(SnowDrawText, txtWidth);
	Obj_SetRenderPriority(SnowDrawText, txtPriority);
	ObjRender_SetPosition(SnowDrawText, txtX, txtY, 0);
	
	SetTextColor;
	
	task SetTextColor{
		if(presetTxtColor=="black"){
			ObjText_SetFontColorTop(SnowDrawText,42,42,42);
			ObjText_SetFontColorBottom(SnowDrawText,42,42,42);
			ObjText_SetFontBorderColor(SnowDrawText,142,142,142);
		}
		if(presetTxtColor=="red"){
			ObjText_SetFontColorTop(SnowDrawText,175,20,111);
			ObjText_SetFontColorBottom(SnowDrawText,190,10,123);
			ObjText_SetFontBorderColor(SnowDrawText,142,142,142);
		}
		if(presetTxtColor=="blue"){
			ObjText_SetFontColorTop(SnowDrawText,20,80,175);
			ObjText_SetFontColorBottom(SnowDrawText,80,50,175);
			ObjText_SetFontBorderColor(SnowDrawText,142,142,142);
		}
	}
	
	return SnowDrawText;
}


