	let color = 0;
	let bgy = 0;
	let bgperspective = -50;
	let spawn = 0;
	let bgspeed = 1;
	let bgfade = 1;
	let controlbgspell1 = 0;
	let controlbgspell2 = 0;
	let controlbgspell3 = 0;
	let controlbgspell4 = 0;
	let controlbgspell5 = 0;
	let spellalpha = 0;
	sub BGLogic {
		bgy+=1+bgspeed*8; bgy%=256;
		bgperspective+=1/2*(1-bgspeed); bgperspective%=360;
		color+=2/pi; color%=360;
		if(bgspeed < 0.5) {
			if(spawn == 0 && spellalpha == 0) {
				CreateSnowEffect;
			}
			spawn+=1; spawn%=4;
		}
		if(bgspeed > 1/180) { bgspeed-=1/180; } else { bgspeed = 0; }
		if(bgfade > 1/120) { bgfade-=1/120; } else { bgfade = 0; }
	}
	@BackGround { if(GetCommonDataDefaultEx("Config", "Background", true)) {
		SetViewTo(0, 0, 0);
		SetViewFrom(400, 90+(15+160*(1-cos(90*bgspeed)))*sin(bgperspective), 40);
		SetFog(300, 700, 75+70*sin(color), 75+70*sin(180+color), 255);
		SetPerspectiveClip(15, 1024);
		WriteZBuffer(true);
		UseZBuffer(true);
		if(spellalpha < 1) { ascent(i in -6..7) {
			SetTexture(bgNon2);
			SetGraphicRect(0, 0, 256, 256);
			SetGraphicAngle(90, 0, 0);
			SetGraphicScale(1, 1);
			SetRenderState(ALPHA);
			SetAlpha(255);
			SetColor(255, 255, 255);
			ascent(k in -3..4) { DrawGraphic3D(254*k, 0, bgy+i*254); }
			SetTexture(bgNon1);
			SetGraphicRect(0, 0, 256, 256);
			SetGraphicAngle(90, 0, 0);
			SetGraphicScale(1, 1);
			SetRenderState(ALPHA);
			SetAlpha(255);
			SetColor(255, 255, 255);
			DrawGraphic3D(0, 0, bgy+i*254);
			SetTexture(bgNon3);
			SetGraphicRect(0, 0, 32, 256);
			SetGraphicScale(3/4, 1);
			SetRenderState(ALPHA);
			SetAlpha(255);
			SetColor(255, 255, 255);
			ascent(k in 0..6) { ascent(j in 0..1+ceil(bgspeed)) {
				SetGraphicAngle(180, 90+k*360/3, 0);
				DrawGraphic3D(-112+20*cos(k*360/6), 128+256*j, 120+20*sin(k*360/6)+bgy+i*254);
				DrawGraphic3D(112+20*cos(k*360/6), 128+256*j, 120+20*sin(k*360/6)+bgy+i*254);
			} }
		} }
	} }
	@DrawBottomObject {
		SetTexture(white);
		SetGraphicRect(0, 0, 512, 512);
		SetGraphicAngle(0, 0, 0);
		SetGraphicScale(1, 1);
		SetRenderState(ALPHA);
		SetAlpha(255*bgfade);
		SetColor(5, 5, 5);
		DrawGraphic(GetCenterX, GetCenterY);
		SetTexture(bgSpell2b);
		SetGraphicRect(0, 0, 384, 448);
		SetGraphicAngle(0, 0, 0);
		SetGraphicScale(1, 1);
		SetRenderState(ALPHA);
		SetAlpha(255*spellalpha);
		SetColor(255, 255, 255);
		DrawGraphic(GetCenterX, GetCenterY);
		if(GetCommonDataDefault("Spell Background Type", 0) != 1) {
			SetTexture(bgSpell1a);
			SetGraphicRect(0, 0, 512, 512);
			SetGraphicAngle(0, 0, 0);
			SetGraphicScale(1, 1);
			SetRenderState(ALPHA);
			SetAlpha((255-[0,160][GetCommonDataDefault("Spell Background Type", 0) == 2])*spellalpha);
			SetColor(128+64*sin(controlbgspell2), 128+64*sin(controlbgspell2+120), 128+64*sin(controlbgspell2+240));
			ascent(i in -1..2) { DrawGraphic(GetCenterX+controlbgspell1+i*512, GetCenterY); }
		}
		if(GetCommonDataDefault("Spell Background Type", 0) != 0) {
			SetTexture(bgSpell2a);
			SetGraphicRect(0, 0, 1024, 1024);
			SetGraphicAngle(0, 0, controlbgspell4);
			SetGraphicScale(1, 1);
			SetRenderState(ADD);
			SetAlpha(255);
			SetColor(255*spellalpha, 255*spellalpha, 255*spellalpha);
			DrawGraphic(GetCenterX+200*cos(controlbgspell5), GetCenterY+200*sin(controlbgspell5));
		}
		if(GetCommonDataDefault("Spell Background Type", 0) != 1) {
			SetTexture(bgSpell1b);
			SetGraphicRect(0, 0, 255, 255);
			SetGraphicAngle(0, 0, controlbgspell3);
			SetGraphicScale(3/2, 3/2);
			SetRenderState(ALPHA);
			SetAlpha((255-[0,160][GetCommonDataDefault("Spell Background Type", 0) == 2])*spellalpha);
			SetColor(255, 255, 255);
			DrawGraphic(GetCenterX, GetCenterY);
		}
	}
	task CreateSnowEffect {
		yield;
		let a = rand(-150, 150);
		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj, GetCenterX-a, 0);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetLayer(obj, 0);
		ObjEffect_SetTexture(obj, bgNon4);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexUV(obj, 0, 0, 0);
		ObjEffect_SetVertexUV(obj, 1, 32, 0);
		ObjEffect_SetVertexUV(obj, 2, 32, 32);
		ObjEffect_SetVertexUV(obj, 3, 0, 32);
		ObjEffect_SetVertexXY(obj, 0, -16, -16);
		ObjEffect_SetVertexXY(obj, 1, 16, -16);
		ObjEffect_SetVertexXY(obj, 2, 16, 16);
		ObjEffect_SetVertexXY(obj, 3, -16, 16);
		let angle = rand(0,360);
		let b = rand(-1,1)*3;
		ascent(n in 0..150) {
			let v = 2+n/40;
			ObjEffect_SetAngle(obj, 0, 0, angle);
			Obj_SetPosition(obj, Obj_GetX(obj)+v*cos(90+a/10), Obj_GetY(obj)+v*sin(90+a/10));
			ObjEffect_SetScale(obj, n/180, n/180);
			let alpha = (30+n*60/90)/90*128*(1-spellalpha);
			ascent(j in 0..4) { ObjEffect_SetVertexColor(obj, j, alpha, alpha, alpha, alpha); }
			a+=b;
			angle+=b;
			yield;
		} Obj_Delete(obj);
	}