//iddyea
let s10bg1=GPSD~"img\dreamclouds.png";
function S10init(delay){
	s12bg1=GPSD~"img\extrabg1b.png";
	s12bg2=GPSD~"img\extrabg2b.png";
	s12bgcolor=[60,40,60];
	CloudLayer(80,255,0.5,1, 0,  ADD);
	S12init(delay);
}
function S10BGLogic{
	S12BGLogic;
}
function S10BG{
	S12BG;
}
function S10final{
}

task ExtraBoss(num){
	IncTimesPlayed(num,10,3);
	numcontinues=2;
	let num2=num;
	num=[3,7,8][num];
	CreateBossNoDelay(GetCenterX,-100,num,"lw",["n1","s1","n2","s2","n3","s3","n4","s4","n5","s5"],[[0],[0],[0],[1,1,1,1,1,1,1,1,1,1]],diff,10, 3);
	Music(8);
	Wait(120);
	SpawnBoss;
	Wait(60);
	while(lifebarsremaining>0){yield;}
	Wait(240);
	DisplayResults(num2+10);
}



//patchy
let s10bg2=GPSD~"img\default2.png";
let s10bg3=GPSD~"img\gradient.png";
let s10bg4=GPSD~"img\bookcase.png";
let s10bg5=GPSD~"img\bookcase2.png";
let pbgspeed=2;
let pbgs=0;
let pbgk=0;
let pbgc=0;

let fogcolor=[20,20,50];

function S11init(delay){
	s12bg1=GPSD~"img\extrabg1c.png";
	s12bg2=GPSD~"img\extrabg2c.png";
	s12bgcolor=[0,0,0];
	S12init(delay);
}
function S11BGLogic{
	S12BGLogic;
}
function S11BGLogicOld{
	pbgs+=pbgspeed;
	pbgc++;
}
function S11BG{
	S12BG;
}
function S11BGOld{
	SetViewTo(0+cos(pbgc)*20,300,100);
	SetViewFrom(1,90-GetPan*0.04,25+sin(pbgc)*2);

	SetTexture(stgwhite);
	SetGraphicRect(0,0,500,500);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(1,1);
	SetAlpha(255);
	SetColor(fogcolor[0],fogcolor[1],fogcolor[2]);
	DrawGraphic(GetCenterX,GetCenterY);

	SetTexture(s10bg2);	//floor
	SetGraphicRect(0,0-pbgs,500,1280-pbgs);
	SetGraphicScale(1,1);
	SetGraphicAngle(90,0,0);
	SetColor(255,255,255);
	SetAlpha(255);
	DrawGraphic3D(0,0,-600);
	SetColor(150,150,150);
	SetGraphicAngle(0,90,90);
	DrawGraphic3D(230,250,-600);
	DrawGraphic3D(-230,250,-600);

	SetTexture(s10bg3);	//gradient

	SetColor(fogcolor[0],fogcolor[1],fogcolor[2]);
	SetGraphicRect(0,0,500,128);
	SetGraphicScale(1,-10);
	SetGraphicAngle(90,0,0);
	SetAlpha(255);
	DrawGraphic3D(0,0,-600);
	SetGraphicAngle(0,90,90);
	DrawGraphic3D(230,250,-600);
	DrawGraphic3D(-230,250,-600);

	SetGraphicScale(1,1);
	WriteZBuffer(true);
	UseZBuffer(true);
	pbgk=0;
	loop(4){
		DrawBookcase(150,0,-1280+(pbgs+pbgk)%1600,-1, (pbgs+pbgk)%1600);
		DrawBookcase(-150,0,-1280+(pbgs+pbgk)%1600,1, (pbgs+pbgk)%1600);
		pbgk+=400;
	}
	WriteZBuffer(false);
	UseZBuffer(false);

}
function DrawBookcase(x,y,z,dir,alpha){

	alpha=lower(alpha/2,255)/255;

	SetTexture(s10bg5);//bookcase2
	SetColor(255,255,255);
	SetGraphicScale(1,1);
	SetAlpha(alpha*100);
	SetGraphicRect(0,0,512,512);
	DrawGraphic3D(x+176,y+1,z-256);

	SetTexture(s10bg4);//bookcase

	SetAlpha(alpha*255);
	SetColor(255*alpha,255*alpha,255*alpha);
	SetGraphicScale(0.5,0.5);
	SetGraphicRect(1,1,161*2,201*2);
	SetGraphicAngle(0,0,0);
	DrawGraphic3D(x,y+100,z);	//front


	SetColor(200*alpha,200*alpha,200*alpha);
	SetGraphicRect(1,1,81*2,201*2);
	SetGraphicAngle(0,90,0);
	DrawGraphic3D(x+80*dir,y+100,z-40);	//side

	SetColor(225*alpha,225*alpha,225*alpha);
	SetGraphicRect(1,1,161*2,81*2);
	SetGraphicAngle(90,0,0);
	DrawGraphic3D(x,y+200,z-40);	//top

}

function S11final{

}


let s12scroll=0;

let s12bg1=GPSD~"img\extrabg1.png";
let s12bg2=GPSD~"img\extrabg2.png";
let s12bg3=GPSD~"img\gradient.png";

let snowx=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
let snowy=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
let snowz=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
let snowxv=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
let snowzv=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
let snowa1=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
let snowa2=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
let snowa3=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];

let s12bgcolor=[0,10,10];

function S12init(delay){
	i=0;
	loop(16){
		snowx[i]=rand(-100,100);
		snowxv[i]=rand(-0.2,0.2);
		snowzv[i]=rand(0.5,1);
		snowy[i]=rand(200,0);
		snowz[i]=rand(0,-300);
		snowa1[i]=rand(-4,4);
		snowa2[i]=rand(-4,4);
		snowa3[i]=rand(-4,4);
		i++;
	}
	SetStagePanSpeed(0.05);
}
function S12BGLogic{
	s12scroll++;
	i=0;
	loop(16){
		snowy[i]=snowy[i]-0.33;	
		snowx[i]=snowx[i]+snowxv[i];
		snowz[i]=snowz[i]+snowzv[i];
		if((snowy[i]<0||snowz[i]>100)){
			snowy[i]=200;
			snowx[i]=rand(-100,100);
			snowz[i]=-300;
			snowxv[i]=rand(-1,1);
			snowzv[i]=rand(0.5,1);
			snowa1[i]=rand(-4,4);
			snowa2[i]=rand(-4,4);
			snowa3[i]=rand(-4,4);
		}
		i++;
	}


}
function S12BG{
	SetViewTo(0-GetPan/8+ScreenShakeX,300+ScreenShakeY,100);
	SetViewFrom(80,90-GetPan*0.02,40);

	SetTexture(stgwhite);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(1,1);
	SetRenderState(ALPHA);
	SetColor(s12bgcolor[0],s12bgcolor[1],s12bgcolor[2]);
	SetGraphicRect(0,0,390,450);
	DrawGraphic(GetCenterX,GetCenterY);

	SetTexture(s12bg1);
	SetGraphicRect(0,0-s12scroll/3,512,1100-s12scroll/3);
	SetGraphicAngle(90,0,0);
	SetGraphicScale(1,1);
	SetColor(255,255,255);
	SetAlpha(255);
	DrawGraphic3D(0,0,-440+(s12scroll%3)/3);

	SetTexture(s12bg3);
	SetGraphicRect(0,1,256,255);
	SetGraphicScale(2,-4);
	SetColor(s12bgcolor[0],s12bgcolor[1],s12bgcolor[2]);
	SetAlpha(160);
	DrawGraphic3D(0,0,-490);

	SetColor(255,255,255);
	SetTexture(s12bg2);
	SetAlpha(40);
	SetGraphicScale(1,1);
	SetGraphicRect(0,0-s12scroll/3,256,512-s12scroll/3);
	DrawGraphic3D(0,200,-100+(s12scroll%3)/3);

	SetAlpha(22);
	SetGraphicScale(0.5,0.5);
	SetGraphicRect(0,0-s12scroll/1.5,256,512-s12scroll/1.5);
	DrawGraphic3D(0,300,100);

	SetTexture(s12bg2);
	SetRenderState(ADD);
	SetGraphicScale(0.2,0.2);
	SetGraphicRect(290,1,351,63);

	i=0;
	let alpha=0;
	loop(16){
		alpha=center(0,snowy[i]*5,255);
		SetColor(alpha*0.4,alpha*0.4,alpha*0.4);
		SetGraphicAngle(snowa1[i]*s12scroll,snowa2[i]*s12scroll,snowa3[i]*s12scroll);
		DrawGraphic3D(snowx[i],snowy[i],snowz[i]);
		i++;
	}

	SetColor(30,30,30);
	SetGraphicAngle(90,0,0);
	SetGraphicRect(289,65,289+126,65+126);
	SetGraphicScale(1,1);
	DrawGraphic3D(0,130,-150);

	SetTexture(s12bg3);
	SetGraphicRect(0,1,500,255);
	SetGraphicScale(2,-4);
	SetColor(s12bgcolor[0],s12bgcolor[1],s12bgcolor[2]);
	SetGraphicAngle(90,0,0);
	SetRenderState(ALPHA);
	SetAlpha(160);
	DrawGraphic3D(0,0,-490);

}

function S12final{
}



task CloudLayer(alpha,color,scrollspeed,flip, alphaphase,renderstate){
	yield;
	let obj=InitEffect(GetCenterX,0,GPSD~"img\dreamclouds.png",4,ADD,5);
	ObjEffect_SetXYRect(obj,-200,0,200,500);
	ObjEffect_SetScale(obj,flip,1);

	let xscrollspeed=rand(0.3,0.5);
	let frame=rand_int(0,360);
	let x;
	let y=0;
	Obj_SetColor(obj,4,0,0,0,0);
	while(!timefrozen){
		alphaphase+=1.3;
		if(GetOption(5)==0){
			Obj_SetColor(obj,4,alpha*(sin(alphaphase)*0.5+0.5),color,color,color);
		}
		if(rand_int(0,600)==0){
			xscrollspeed=rand(0.3,0.5);
		}	
		frame+=xscrollspeed;
		x=sin(frame)*100;
		y+=scrollspeed;
		ObjEffect_SetUVRect(obj,x,y,x+400,500+y);	
		yield;
	}
	Obj_Delete(obj);
}