Exemplo n.º 1
0
bool CArea::onLoad(const std::string & file, int sizeX, int sizeY) {
		mMapSize.x = sizeX; mMapSize.y = sizeY;
    mapList.clear();

    FILE* fileHandle = fopen(file.c_str(), "r");

    if(fileHandle == NULL) {
        return false;
    }

    char tilesetFile[255] = "";

    fscanf(fileHandle, "%s\n", tilesetFile);

		//Load texture for the area
		mTilesetTexture.setID(RESOURCE_DIR + std::string("/") + tilesetFile);

    fscanf(fileHandle, "%d\n", &areaSize);

    for(int X = 0;X < areaSize;X++) {
        for(int Y = 0;Y < areaSize;Y++) {
            std::string mapPath = "";
						mapPath.append(RESOURCE_DIR"/");
						char mapfile[255];
            fscanf(fileHandle, "%s ", mapfile);
						mapPath.append(mapfile);
            CMap tempMap;
            if(tempMap.onLoad(mapPath,mMapSize.x,mMapSize.y) == false) {
                fclose(fileHandle);
								ELOG() << "Could not load map (" << mapPath << ")"  << std::endl;
                return false;
            }

						tempMap.setTexture(mTilesetTexture);

            mapList.push_back(tempMap);
        }
        fscanf(fileHandle, "\n");
    }

    fclose(fileHandle);

    return true;
}