let frame = 0;
let frame2 = 0;
let angle = 0;

@Initialize{

	SetCameraFocusX(-250);
	SetCameraFocusY(100);
	SetCameraFocusZ(0);
	SetCameraRadius(450);
	SetCameraElevationAngle(45);
	SetCameraAzimuthAngle(180);
	
	SetFogParam(500,750,135,190,229);
	Background;
	
}

@MainLoop{
   yield;
}

task Background{
	let texture1 = GetCurrentScriptDirectory~"img/bg1.png";
	let texture2 = GetCurrentScriptDirectory~"img/sky.png";
	let texture3 = GetCurrentScriptDirectory~"img/bg3.png";
	
	let sky = ObjPrim_Create(OBJ_SPRITE_2D);
	let bg1 = ObjPrim_Create(OBJ_SPRITE_3D);
	let bg2 = ObjPrim_Create(OBJ_SPRITE_3D);
	let bg3 = ObjPrim_Create(OBJ_SPRITE_3D);
	
	Obj_SetRenderPriority(sky,0.21);
	ObjPrim_SetTexture(sky,texture2);
	ObjSprite2D_SetSourceRect(sky,0,0,1024,1024);
	ObjSprite2D_SetDestRect(sky,0,0,1024,1024);
	ObjSprite2D_SetDestCenter(sky);
	ObjRender_SetPosition(sky,GetStgFrameWidth/2,0,0);
	ObjRender_SetAngleXYZ(sky,0,0,0);
	ObjRender_SetColor(sky,255,255,255);
	
	Obj_SetRenderPriority(bg1,0.21);
	ObjPrim_SetTexture(bg1,texture1);
	ObjSprite3D_SetSourceRect(bg1,0,0,2048,2048);
	ObjSprite3D_SetDestRect(bg1,0,0,1024,1024);
	ObjRender_SetAlpha(bg1, 128);
	ObjRender_SetPosition(bg1,512,0,-512);
	ObjRender_SetAngleXYZ(bg1,90,0,90);
	
	Obj_SetRenderPriority(bg2,0.21);
	ObjPrim_SetTexture(bg2,texture1);
	ObjSprite3D_SetSourceRect(bg2,0,0,2048,2048);
	ObjSprite3D_SetDestRect(bg2,0,0,1024,1024);
	ObjRender_SetAlpha(bg2, 128);
	ObjRender_SetPosition(bg2,512,25,-512);
	ObjRender_SetAngleXYZ(bg2,90,0,90);
	
	Obj_SetRenderPriority(bg3,0.23);
	ObjPrim_SetTexture(bg3,texture3);
	ObjSprite3D_SetSourceDestRect(bg3, 0, 0, 256, 256);
	ObjSprite3D_SetBillboard(bg3, true);
	ObjRender_SetAlpha(bg3, 255);
	ObjRender_SetPosition(bg3, 100, 0, -200);
	ObjRender_SetBlendType(bg3, BLEND_ADD_ARGB);
	ObjRender_SetScaleXYZ(bg3, 3, 3, 3);
	
	loop{
		frame += 4;
		frame2 += 2;
		angle += 2;
		if(frame >= 1024){frame = 0;}
		if(frame % 256 == 0){cloud;}
		ObjSprite3D_SetSourceRect(bg1,frame2/1.5,-frame2,1024 + frame2/1.5,1024 - frame2);
		ObjSprite3D_SetSourceRect(bg2,-frame2/2,-frame2/4,1024 - frame2/2,1024 - frame2/4);
		ObjRender_SetAngleXYZ(sky,0,0,5*cos(frame2/8));
		ObjRender_SetAngleXYZ(bg3, 0, 45, frame2/8);
		yield;
	}
	yield;
}

task cloud{
	let texture = GetCurrentScriptDirectory~"img/bg2.png";
	let cloud = ObjPrim_Create(OBJ_SPRITE_3D);
	let cloudNo = round(rand(0,2));
	let count = -600;
	let speed = rand(0.5, 2);
	let cx = rand(-400, 400);
	let cy = rand(0, 200);
	
	Obj_SetRenderPriority(cloud, 0.22);
	ObjPrim_SetTexture(cloud, texture);
	ObjSprite3D_SetBillboard(cloud, true);
	
	alternative(cloudNo)
	case(0){
		ObjSprite3D_SetSourceDestRect(cloud, 0, 0, 256, 256);
	}
	case(1){
		ObjSprite3D_SetSourceDestRect(cloud, 256, 0, 512, 256);
	}
	case(2){
		ObjSprite3D_SetSourceDestRect(cloud, 0, 256, 512, 512);
	}
	
	while(!Obj_IsDeleted(cloud)){
		count += speed;
		
		ObjRender_SetPosition(cloud, count, cy, cx);
		ObjRender_SetAlpha(cloud, 128);
		
		if(count >= 200){
			Obj_Delete(cloud);
		}
		
		yield;
	}
}
