示例#1
0
// load the area file containing all our map definitions
bool CArea::OnLoad(char* File) {
    MapList.clear();

    FILE* FileHandle = fopen(File, "r");

    if(FileHandle == NULL) {

        return false;
    }

    char TilesetFile[255];

    fscanf(FileHandle, "%s\n", TilesetFile);

    if((Surf_Tileset = CSurface::OnLoad(TilesetFile)) == false) {
        fclose(FileHandle);
        std::cout << "file handle false: " << TilesetFile;
        return false;
    }

    fscanf(FileHandle, "%d\n", &AreaSize);

    for(int X = 0;X < AreaSize;X++) {
        for(int Y = 0;Y < AreaSize;Y++) {
            char MapFile[255];

            fscanf(FileHandle, "%s ", MapFile);

            CMap tempMap;
            tempMap.Map_X = X * MAP_WIDTH * TILE_SIZE;
            tempMap.Map_Y = Y * MAP_HEIGHT * TILE_SIZE;
            if(tempMap.OnLoad(MapFile) == false) {
                fclose(FileHandle);

                return false;
            }

            tempMap.Surf_Tileset = Surf_Tileset;

            MapList.push_back(tempMap);
        }
        fscanf(FileHandle, "\n");
    }

    fclose(FileHandle);

    return true;
}
示例#2
0
文件: CArea.cpp 项目: Fenixp/SDL_Maps
//=============================================================================
bool CArea::OnLoad(char* File) {
    MapList.clear();

    FILE* FileHandle = fopen(File, "r");

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

    char TilesetFile[255];

    fscanf(FileHandle, "%s\n", TilesetFile);

    if((Surf_Tileset = CSurface::OnLoad(TilesetFile)) == false) {
        fclose(FileHandle);

        return false;
    }

    fscanf(FileHandle, "%d\n", &AreaSize);

    for(int X = 0;X < AreaSize;X++) {
        for(int Y = 0;Y < AreaSize;Y++) {
            char MapFile[255];

            fscanf(FileHandle, "%s ", MapFile);

            CMap tempMap;
            if(tempMap.OnLoad(MapFile) == false) {
                fclose(FileHandle);

                return false;
            }

            tempMap.Surf_Tileset = Surf_Tileset;

            MapList.push_back(tempMap);
        }
        fscanf(FileHandle, "\n");
    }

    fclose(FileHandle);

    return true;
}
示例#3
0
//=============================================================================
bool CArea::OnLoad(char* File)
{

    OnCleanup();

    FILE* FileHandle = fopen(File, "r");

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

    char PassablesFile[255];
    char ImpassablesFile[255];

    fscanf(FileHandle, "%255s\n", PassablesFile);
    fscanf(FileHandle, "%255s\n", ImpassablesFile);

    if((Surf_Tileset_Passables = CSurface::OnLoad(PassablesFile)) == false)
    {
        fclose(FileHandle);
        return false;
    }
    if((Surf_Tileset_Impassables = CSurface::OnLoad(ImpassablesFile)) == false)
    {
        fclose(FileHandle);
        return false;
    }

    fscanf(FileHandle, "%d:%d\n", &areaWidth, &areaHeight);

    // I added the MapWidth and MapHeight here for the sake of adding enemies in CMap::OnLoad()

    int ID = 0;
    int MapWidth  = MAP_WIDTH * TILE_SIZE;
    int MapHeight = MAP_HEIGHT * TILE_SIZE;

    for(int Y = 0; Y < areaHeight; Y++)
    {
        for(int X = 0; X < areaWidth; X++)
        {
            char MapFile[255];

            fscanf(FileHandle, "%s255 ", MapFile);

            int nX = ((ID % areaWidth) * MapWidth);
            int nY = ((ID / areaWidth) * MapHeight);

            CMap tempMap;
            if(tempMap.OnLoad(MapFile, nX, nY) == false)
            {
                fclose(FileHandle);

                return false;
            }

            tempMap.Surf_Tileset_Passables = Surf_Tileset_Passables;
            tempMap.Surf_Tileset_Impassables = Surf_Tileset_Impassables;

            MapList.push_back(tempMap);
            ID++;
        }
        fscanf(FileHandle, "\n");

    }

    fclose(FileHandle);

    return true;
}