var g_exit_level = -1;

function GoToLevel(numm,load)
{
	//if not a loaded game,
		//fadeout
		//screen change???  Maybe just show the level name?
		
	//save info of current level if not a load	
		
		
	//load info left in file if exists
	//load normally.
	//Fade in


		SetDefaultMapScript(SCRIPT_ON_ENTER_MAP, "StartFunct("+numm+");");
		g_exit_level = numm;
}


var layer_scripts = new Array(10);


function LayerShiftClear()
{
	for (sli=0;sli<10;sli++)
	{
		layer_scripts[sli] = "";
	}
}

function SetLayerXShift(layer,amount)
{
	
	layer_scripts[layer-1]+="SetCameraX(GetCameraX()+"+(-1*amount)+");";
	layer_scripts[layer]+="SetCameraX(GetCameraX()+"+(amount)+");";
}
function SetLayerYShift(layer,amount)
{
	layer_scripts[layer-1]+="SetCameraY(GetCameraY()+"+(-1*amount)+");";
	layer_scripts[layer]+="SetCameraY(GetCameraY()+"+(amount)+");";
}

function DoLayerScripts()
{
	for (sli=0;sli<10;sli++)
	{
		if (layer_scripts[sli] != "")
		{
			SetLayerRenderer(sli, layer_scripts[sli])
		}
	}
}


function DoLevel14BreakZone()
{
var tw = GetTileWidth();
var th = GetTileHeight();

	for (zi=0;zi<14;zi++)
	{
		for (zj=0;zj<2;zj++)
		{
			Queue_Command("SpawnExplosion("+(269*tw+zi*tw+GetTileWidth())+","+(122*th+zj*th+GetTileHeight()/2)+", 0.5, 0, "+(1*(Math.random()*0.75+0.75))+");", 1+Math.floor(Math.random()*6));
	//SpawnExplosion(269+zi+GetTileWidth()/2,122+zj+GetTileHeight()/2, damage, 0, 1*(Math.random()*0.5+0.75))
		}
	}
	Queue_Command("DoLevel14BreakZone1Tiles()", 8);
}

function DoLevel14BreakZone1Tiles()
{
	for (dl=0;dl<max_entities;dl++)
		entities[dl].stop = false;


for (zi=0;zi<14;zi++)
{
  for (zj=0;zj<2;zj++)
  {
    SetTile(269+zi,122+zj,0,1174);
  }
}
for (zi=0;zi<16;zi++)
{
  for (zj=0;zj<3;zj++)
  {
    SetTile(268+zi,121+zj,2,0)
  }
}
for (zi=0;zi<22;zi++)
{
  for (zj=0;zj<22;zj++)
  {
    SetTile(266+zi,116+zj,3,0)
    SetTile(266+zi,116+zj,4,0)
    SetTile(266+zi,116+zj,5,0)
  }
}

}

function DoLevel14BreakZone2()
{
var tw = GetTileWidth();
var th = GetTileHeight();

	for (zi=0;zi<14;zi++)
	{
		for (zj=0;zj<2;zj++)
		{
			Queue_Command("SpawnExplosion("+(269*tw+zi*tw+GetTileWidth())+","+(128*th+zj*th+GetTileHeight()/2)+", 0.5, 0, "+(1*(Math.random()*0.75+0.75))+");", 1+Math.floor(Math.random()*6));
	//SpawnExplosion(269+zi+GetTileWidth()/2,122+zj+GetTileHeight()/2, damage, 0, 1*(Math.random()*0.5+0.75))
		}
	}
	Queue_Command("DoLevel14BreakZone2Tiles()", 8);
}


function DoLevel14BreakZone2Tiles()
{
	for (dl=0;dl<max_entities;dl++)
		entities[dl].stop = false;


var tw = GetTileWidth();
var th = GetTileHeight();

for (zi=0;zi<14;zi++)
{
  for (zj=0;zj<2;zj++)
  {
    SetTile(269+zi,128+zj,0,1174)
  }
}
for (zi=0;zi<16;zi++)
{
  for (zj=0;zj<3;zj++)
  {
    SetTile(268+zi,127+zj,2,0)
  }
}
for (zi=0;zi<22;zi++)
{
  for (zj=0;zj<22;zj++)
  {
    SetTile(266+zi,116+zj,3,0)
    SetTile(266+zi,116+zj,4,0)
    SetTile(266+zi,116+zj,5,0)
  }
}

}

function DoLevel14BreakZone3()
{
var tw = GetTileWidth();
var th = GetTileHeight();

	for (zi=0;zi<14;zi++)
	{
		for (zj=0;zj<2;zj++)
		{
   	Queue_Command("SpawnExplosion("+(269*tw+zi*tw+GetTileWidth())+","+(134*th+zj*th+GetTileHeight()/2)+", 0.5, 0, "+(1*(Math.random()*0.75+0.75))+");", 1+Math.floor(Math.random()*6));
	//SpawnExplosion(269+zi+GetTileWidth()/2,122+zj+GetTileHeight()/2, damage, 0, 1*(Math.random()*0.5+0.75))
		}
	}
	Queue_Command("DoLevel14BreakZone3Tiles()", 8);
}

function DoLevel14BreakZone3Tiles()
{
	for (dl=0;dl<max_entities;dl++)
		entities[dl].stop = false;


for (zi=0;zi<14;zi++)
{
  for (zj=0;zj<2;zj++)
  {
    SetTile(269+zi,134+zj,0,1174);

  }
}
for (zi=0;zi<16;zi++)
{
  for (zj=0;zj<2;zj++)
  {
		if (zj == 0)
			SetTile(268+zi,134+zj,2,0)
		if (zj == 1)
			SetTile(268+zi,134+zj,6,0)
  }
}
for (zi=0;zi<22;zi++)
{
  for (zj=0;zj<22;zj++)
  {
    SetTile(266+zi,116+zj,3,0)
    SetTile(266+zi,116+zj,4,0)
    SetTile(266+zi,116+zj,5,0)
  }
}

}