Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool Level::LoadFromFile( const std::string& filename )
- {
- std::fstream file( filename.c_str(), std::fstream::in );
- if ( !file )
- {
- return false;
- }
- std::string sizeStr;
- file >> sizeStr;
- auto tokens = util::Tokenize( sizeStr, "x" );
- if ( !file or tokens.size() != 2 )
- {
- return false;
- }
- size.x = util::FromString< sf::Int32 >( tokens[ 0 ] );
- size.y = util::FromString< sf::Int32 >( tokens[ 1 ] );
- file.get();
- std::getline( file, name );
- if ( !file )
- {
- return false;
- }
- for ( int iy = 0; iy < size.y; ++iy )
- {
- std::string line;
- std::getline( file, line );
- if ( !file or line.length() < size.x )
- {
- return false;
- }
- for ( int ix = 0; ix < size.x; ++ix )
- {
- AddBlock( line[ ix ], ix, iy );
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement