let CSD = GetCurrentScriptDirectory;

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

	BackgroundRoad;
	BackgroundSky;}
 
@MainLoop{yield;}

function SpriteCreateRoad{
	let obj = ObjPrim_Create(OBJ_SPRITE_3D);
	ObjPrim_SetTexture(obj,CSD~"./bg1.png");
	Obj_SetRenderPriorityI(obj,20);
	ObjRender_SetAngleX(obj,-40);
	ObjSprite3D_SetSourceDestRect(obj,0,0,512,128);
	ObjRender_SetScaleXYZ(obj,1.8,1.8,1.8);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);

ObjRender_SetAlpha(obj,255);
	return obj;}

function SpriteCreateSky{
	let obj2 = ObjPrim_Create(OBJ_SPRITE_3D);
	ObjPrim_SetTexture(obj2,CSD~"./bg2.png");
	Obj_SetRenderPriorityI(obj2,20);
ObjRender_SetAlpha(obj2,10);
	ObjRender_SetAngleX(obj2,-40);
	ObjSprite3D_SetSourceDestRect(obj2,0,0,128,128);
	ObjRender_SetScaleXYZ(obj2,1.5,1.5,1.5);
	ObjRender_SetBlendType(obj2,BLEND_ALPHA);
	return obj2;}

task BackgroundRoad{
	let obj = [SpriteCreateRoad];
	ObjRender_SetAlpha(obj[0],255);
        let alpha = 0;
	let frameInvisible = 0;
	let move = 0;
	let movel = 0;
	let movel2 = 0;
	loop{
     	ObjSprite3D_SetSourceDestRect(obj[0],0,0+movel2,(256*6)+movel,(256*6)+movel2);
		ObjRender_SetAngleY(obj[0],10*sin(move));
		move+=0.5;
		movel+=0;
		movel2+=1.5;
		yield;}}

task BackgroundSky{
	let obj2 = [SpriteCreateSky];
	ObjRender_SetAlpha(obj2[0],120);

        let alpha = 0;
	let frameInvisible = 0;
	let movel = 0;
	let movel2 = 0;
	loop{
     	ObjSprite3D_SetSourceDestRect(obj2[0],0,0+movel2,(256*6)+movel,(256*6)+movel2);


		movel+=0;
		movel2+=2.5;
		yield;}}

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