Im having a bit of a problem with loading a tilemap froma .txt file. Everything from drawing to collision works when i use an array, but whenever i try to read it from a file, the compiler gives some:
main.obj : error LNK2001: unresolved external symbol __imp___CrtDbgReportW
fatal error LNK1120: 1 unresolved externals
Anyway, can anyone refer me to a tutorial or give some help? This is how the text file looks like.
00000
00020
01220
00000
00000
Code: Select all
This is what it loks like in the array version:
void draw_map()
{
for( int x = 0; x < 40; x++ )
{
for( int y = 0; y < 30; y++ )
{
//if we read a number, draw respective tile
if( map1[y][x] == 0 )
{
draw_tile( x * 32 - camera.x, y * 32 - camera.y, tiles, screen, map[0][0].id );
}
if( map1[y][x] == 1 )
{
draw_tile( x * 32 - camera.x, y * 32 - camera.y, tiles, screen, map[1][1].id );
}
if( map1[y][x] == 2 )
{
draw_tile( x * 32 - camera.x, y * 32 - camera.y, tiles, screen, map[2][2].id );
}
}
}
}
This is what Ive got in the reading file version
void LoadLevel( const char* filename )
{
std::ifstream file("Levels/level0.txt");
char temp;
for( int x = 0; x < 40; x++ )
{
for( int y = 0; y < 30; y++ )
{
file >> temp;
if( temp == '0' )
{
draw_tile( x * 32 - camera.x, y * 32 - camera.y, tiles, screen, map[0][0].id );
}
if( temp == '1' )
{
draw_tile( x * 32 - camera.x, y * 32 - camera.y, tiles, screen, map[1][1].id );
}
if( temp == '2' )
{
draw_tile( x * 32 - camera.x, y * 32 - camera.y, tiles, screen, map[2][2].id );
}
}
}
file.close();
}