//TODO: use char* void ReadFileToString(std::string path, std::string* text) { std::string line = ""; std::ifstream storyFile(path); if(storyFile.is_open()) { while(getline(storyFile, line)) { *text += line; } storyFile.close(); } }
//intitalize window and window options, calls main loop void Game::Start(void) { if(gameState != Uninitialized) return; //set window icon icon.loadFromFile("images/Player.png"); //make the window mainWindow.create(sf::VideoMode(1024,768,32),"Ace SPACE Pilot"); //playing field is 576 by 768 mainWindow.setView(View); mainWindow.setIcon(40,40,icon.getPixelsPtr()); mainWindow.setKeyRepeatEnabled(false); mainWindow.setFramerateLimit(60); mainWindow.setMouseCursorVisible(false); rightBound.setSize(sf::Vector2f(400,768)); rightBound.setFillColor(sf::Color::Black); rightBound.setPosition(576,0); leftBound.setSize(sf::Vector2f(400,768)); leftBound.setFillColor(sf::Color::Black); leftBound.setPosition(-400,0); bottomBound.setSize(sf::Vector2f(576,400)); bottomBound.setFillColor(sf::Color::Black); bottomBound.setPosition(0,768); spawnArea.setSize(sf::Vector2f(676,400)); spawnArea.setPosition(-50,-400); spawnArea.setFillColor(sf::Color::Black); wholeArea.setSize(sf::Vector2f(1024,768)); wholeArea.setFillColor(sf::Color::Black); mainWindow.setVerticalSyncEnabled(true); gameState = Uninitialized; //load our main fonts uni05.loadFromFile("fonts/uni05_53.ttf"); datagoth.loadFromFile("fonts/datagoth.otf"); //load projectile textures textures[0].loadFromFile("images/proj.png"); textures[1].loadFromFile("images/EnemyProj.png"); textures[2].loadFromFile("images/EnemyProjSmall.png"); //load sounds sf::SoundBuffer projSound; projSound.loadFromFile("sounds/se_plst00.wav"); sounds[0].setBuffer(projSound); sounds[0].setVolume(20); sf::SoundBuffer okSound; okSound.loadFromFile("sounds/se_ok00.wav"); sounds[1].setBuffer(okSound); sounds[1].setVolume(50); sf::SoundBuffer pauseSound; pauseSound.loadFromFile("sounds/se_select00.wav"); sounds[2].setBuffer(pauseSound); sf::SoundBuffer hitSound; hitSound.loadFromFile("sounds/se_damage00.wav"); sounds[3].setBuffer(hitSound); sounds[3].setVolume(20); sf::SoundBuffer endSound; endSound.loadFromFile("sounds/se_playerdead.wav"); sounds[4].setBuffer(endSound); sf::SoundBuffer killSound; killSound.loadFromFile("sounds/destroy.ogg"); sounds[5].setBuffer(killSound); //loads in story std::ifstream storyFile("storytime.txt"); std::string storyString((std::istreambuf_iterator<char>(storyFile)), std::istreambuf_iterator<char>()); story = wordWrap(storyString,48); if(mainWindow.setActive(true)) { while(gameState != Exiting) { GameLoop(); } } mainWindow.setActive(false); if(mainWindow.isOpen()) mainWindow.close(); }