void TemplateGame::init() { // Load texture m_simpleTex = LoadImagePNG( gameDataFile("", "simpletex.png" ).c_str() ); // Load font m_fontImg = LoadImagePNG( gameDataFile("", "nesfont.png" ).c_str() ); m_nesFont = makeFont_nesfont_8( m_fontImg.textureId ); m_cube = make_cube(); // setColorConstant( m_cube, vec4f( 1.0, 1.0, 1.0 ) ); m_basicShader = loadShader( "template.Plastic" ); m_rotate = 0.0; glEnable( GL_DEPTH_TEST ); }
void GameState::nextLevel() { m_pickTiles.erase( m_pickTiles.begin(), m_pickTiles.end() ); m_carRoute.erase( m_carRoute.begin(), m_carRoute.end() ); char buff[64]; m_level++; sprintf( buff, "level_%02d.txt", m_level ); loadLevel( gameDataFile( "", buff ).c_str() ); }
GameState::GameState() : m_level(0), m_boardSizeX( 15 ), m_boardSizeY( 15 ) { // init car pos m_carPos.x = (float)m_boardSizeX / 2.0; m_carPos.y = (float)m_boardSizeY / 2.0; m_carDir = vec2f( 0.5, 0.5 ); m_newTileTimeout = NEW_TILE_TIMEOUT; m_maxTiles = INITIAL_MAX_TILES; // read the wordlist loadWordList( gameDataFile("", "2of12inf.txt").c_str() ); }
// load the tileset void MapRoom::initTiles() { #ifdef __APPLE__ std::string voxtileDir = getResourceDir(); #else std::string voxtileDir = getResourceDir() + "/voxtiles"; #endif #ifndef WIN32 DIR *dp; struct dirent *dirp; if((dp = opendir( voxtileDir.c_str() )) == NULL) { printf("Can't open tiles dir %s\n", voxtileDir.c_str() ); exit(1); } #else WIN32_FIND_DATAA ffd; TCHAR szDir[MAX_PATH]; HANDLE hFind = INVALID_HANDLE_VALUE; hFind = FindFirstFileA( voxtileDir + "/*").c_str(), &ffd ); #endif #ifndef WIN32 while ((dirp = readdir(dp)) != NULL) { char *tilename = dirp->d_name; #else do { char *tilename = ffd.cFileName; #endif char buff[1024]; sprintf( buff, "%s/%s", voxtileDir.c_str(), tilename ); std::string tileId = tilename; std::string tileExt; size_t extPos = tileId.rfind( '.' ); if (extPos != std::string::npos) { tileExt = tileId.substr( extPos ); tileId = tileId.substr( 0, extPos ); if (tileExt != ".csv") continue; printf("Load tile %s for tile id %s\n", buff, tileId.c_str() ); VoxChunk *tile = VoxChunk::loadCSVFile( buff ); tile->m_chunkName = tileId; // HACK the floor height if ( (tileId.find( "overland" ) != std::string::npos) || (tileId.find( "cave" ) != std::string::npos) ) { tile->m_floorHeight = 1.0; } if (tileId.find( "stairs" ) != std::string::npos) { tile->m_floorHeight = 0.5; } m_tileset[ tileId ] = tile; } #ifndef WIN32 } closedir(dp); #else } while (FindNextFileA( hFind, &ffd) != 0 ); FindClose( hFind ); #endif // Now load enemies m_octorok = VoxChunk::loadCSVFile( gameDataFile( "", "octaroc.csv").c_str() ); if (!m_octorok) { printf("FAIL to load octaroc\n" ); } }