void Sandbox::init( bool useScreenBounds )
		{	
			// create our world
			mWorld = new b2World( mGravity );

			if( useScreenBounds ){
				createBoundaries( app::getWindowBounds() );
			}

			// Create an empty body for use with a b2MouseJoint

			b2BodyDef bodyDef;
			mGroundBody = mWorld->CreateBody(&bodyDef);
		}
void MyLevel::startBossEncounter() {
	windowPos.x= worldWidth+BOSS_CHAMBER_OFFSET;
	createBoundaries();
	std::map<int,Megaman*>::iterator megIt=megamans.begin();
	for(; megIt!=megamans.end(); megIt++){
		b2Vec2 newSpawn(windowPos.x+2,windowPos.y+5);
		Megaman* megaman=megIt->second;
		megaman->setSpawnPos(newSpawn);
		megaman->spawn();
	}
	spawn();//create new characters and restores spawners outside
	std::map<int,Character*>::iterator characterIt=characters.begin();
	for(; characterIt!=characters.end(); characterIt++){
		Character* character=characterIt->second;
		if( !posInWindow(character->getPos()) ){
			character->kill();
		}
	}
	redrawForClient(false);
}
/*if all megamans are past LEFT or RIGHT zone limit, moves the window.
 * If screen moved spawns new enemies, kills characters outside window,
 * informs client to move all objects*/
void MyLevel::moveScreen() {
	bool inRightZone, inLeftZone;
	inLeftZone= (windowPos.x != 0);//check not left border
	inLeftZone= (!bossEncounter) && inLeftZone;
	std::map<int,Megaman*>::iterator megIt=megamans.begin();
	for(; megIt!=megamans.end(); megIt++){
		Megaman* megaman=megIt->second;
		inLeftZone= inLeftZone && ( megaman->isDead() || megaman->getPos().x <
				(windowPos.x + windowWidth* LEFT_ZONE_LIMIT) );
	}
	if (inLeftZone){
		windowPos.x-=windowWidth*(RIGHT_ZONE_LIMIT-OFFSET);
		if(windowPos.x<0)
			windowPos.x=0;
	}else{
		inRightZone= (windowPos.x+windowWidth)<worldWidth;//check not rigth border
		inRightZone= (!bossEncounter)&& inRightZone;
		megIt=megamans.begin();
		for(; megIt!=megamans.end(); megIt++){
			Megaman* megaman=megIt->second;
			inRightZone= inRightZone && ( megaman->isDead() ||
					megaman->getPos().x >(windowPos.x + windowWidth* RIGHT_ZONE_LIMIT) );
		}
		if (inRightZone){
			windowPos.x+=windowWidth*(RIGHT_ZONE_LIMIT-LEFT_ZONE_LIMIT-OFFSET);
			if((windowPos.x+windowWidth)>worldWidth)
				windowPos.x=worldWidth-windowWidth;
		}
	}
	if(inLeftZone || inRightZone){
		LOG(INFO)<<"screen moved. new position: "<< std::fixed<<
				std::setprecision(2)<<windowPos.x<<" "<<windowPos.y;

		createBoundaries();
		spawn();//create new characters and restores spawners outside

		redrawForClient(false);
	}
}
MyLevel::MyLevel(Game* j,std::string lvlFileName,Metadata* metadata,int id)
:world(b2Vec2(0,-10)),
 running(false),
 game(j),
 factory(&world,this),
 metadata(metadata),
 id(id),
 bossEncounter(false){
	LevelObject::resetIds();
	boundaries=nullptr;
	world.SetContinuousPhysics(true);
	world.SetContactListener(&contactListener);
	windowPos.x=0;
	windowPos.y=0;
	/*abro configuraciones*/
	Json::Value config_json;
	fileToJson(COFIG_FILE,config_json);

	Item::initializeDropTable(config_json);

	/*cargo nivel*/
	Json::Value level_json;
	fileToJson(lvlFileName,level_json);
	/*seteo variables mundo*/
	this->worldHeight=level_json["width"].asInt();
	this->worldWidth=level_json["length"].asInt();

	Json::Value world_json=config_json["world"];
	this->stepsPerSecond=world_json["steps/second"].asFloat();
	world.SetGravity(b2Vec2(0,world_json["gravity"].asFloat()));
	this->windowHeight=world_json["windowHeight"].asFloat();
	this->windowWidth=world_json["windowWidth"].asFloat();
	//window borders
	createBoundaries();
	//load all objects of the level
	Json::Value objetosNivel=level_json["foreground"];
	Json::ValueIterator it=objetosNivel.begin();
	for(; it!=objetosNivel.end(); it++){
		int id=(*it)["id"].asInt();
		b2Vec2 pos=jsonPosToWorldPos((*it)["x"].asInt(),
				(*it)["y"].asInt());
		ObjectInfo info(id,pos);
		int objectType=id/1000;
		if( objectType==1){
			addSpawner(id,pos);
		}else{
			createObject(&info);
		}
	}
	//load all objects of the level
	Json::Value objetosBossChamber=level_json["chamber"];
	Json::ValueIterator chamberIt=objetosBossChamber.begin();
	for(; chamberIt!=objetosBossChamber.end(); chamberIt++){
		int id=(*chamberIt)["id"].asInt();
		b2Vec2 pos=jsonPosToWorldPos(
				(*chamberIt)["x"].asInt()+worldWidth+BOSS_CHAMBER_OFFSET,
				(*chamberIt)["y"].asInt());
		ObjectInfo info(id,pos);
		int objectType=id/1000;
		if( objectType==1){
			addSpawner(id,pos);
		}else{
			createObject(&info);
		}
	}
	spawn();
}