Stair::Case InterCurveWord::Find_CX_Staircases(const std::string& curveWord) { std::string pattern = "CFX"; Stair::Case CX_stairs; size_t F_string=0; for (size_t _index=0; _index < curveWord.length();) { bool foundPattern = curveWord.substr(_index, pattern.length()) == pattern; // Didn't find the pattern if (!foundPattern) { // Store Fs that precede the pattern as length F_string. if (curveWord[_index] == 'F') F_string++; // If curveWord_i is not 'F', restart F_string at 0. else F_string = 0; _index ++; } // Found the pattern else { // Move index past the pattern _index += pattern.length(); // Store a stair of length F_string CX_stairs.push_back( Stair(_index-1,F_string) ); // Restart F_string from 0. F_string = 0; } } return CX_stairs; }
Stair::Case InterCurveWord::Find_XC_Staircases(const std::string& curveWord) { const std::string pattern = "XC"; Stair::Case XC_stairs; const char inc = 'F'; for (size_t _index=0; _index < curveWord.length();) { bool foundPattern = curveWord.substr(_index, pattern.length()) == pattern; if (!foundPattern) { _index ++; } else { size_t _offset = _index; _index += pattern.length(); size_type _prev = _index; // Store Fs that succede the pattern. while (curveWord[_index] == inc && _index < curveWord.length()) _index ++; XC_stairs.push_back( Stair(_offset, _index - _prev) ); } } return XC_stairs; }
void loadLevel(int level, bool ascending) { std::wstring filename; int numWalls = 0; wall *walls = NULL; switch (level) { // transition case -1: { player.setScore(player.getScore() + 50); filename = Gosu::resourcePrefix() + L"media/ui/transitionScreen.bmp"; despawnItems(); despawnEnemies(); items.push_back(Item(kittensAnim, KITTENS, 135, 105)); break; } // start screen case 0: { onStartScreen = true; filename = Gosu::resourcePrefix() + L"media/ui/startScreen.bmp"; despawnItems(); despawnEnemies(); // Set entrances and exits down = Stair(15, 45, false); up = Stair(105, 195, true); // Set player location if (ascending) { player.warp(down.x(), down.y()); } else { player.warp(up.x(), up.y()); } break; } case 1: { // Get map graphic filename = Gosu::resourcePrefix() + L"media/maps/map1.bmp"; // Get map walls numWalls = 25; wall someWalls[] = { wall(0, 0, 240, 0), wall(0, 0, 0, 210), wall(0, 210, 240, 210), wall(240, 210, 240, 0), wall(0, 180, 30, 180), wall(30, 30, 30, 120), wall(30, 150, 30, 180), wall(30, 30, 90, 30), wall(90, 30, 90, 60), wall(90, 60, 60, 60), wall(30, 120, 60, 120), wall(60, 120, 60, 150), wall(30, 90, 120, 90), wall(120, 90, 120, 0), wall(90, 210, 90, 180), wall(60, 180, 210, 180), wall(210, 180, 210, 30), wall(210, 60, 180, 60), wall(210, 120, 180, 120), wall(210, 150, 90, 150), wall(90, 150, 90, 120), wall(90, 120, 150, 120), wall(150, 120, 150, 30), wall(150, 30, 180, 30), wall(150, 90, 180, 90) }; walls = (wall *)realloc(walls, numWalls * sizeof(wall)); memcpy(walls, someWalls, (numWalls * sizeof(wall))); // Set entrances and exits down = Stair(15, 45, false); up = Stair(105, 195, true); // Set player location if (ascending) { player.warp(down.x(), down.y()); } else { player.warp(up.x(), up.y()); } // Set items despawnItems(); items.push_back(Item(ammoAnim, AMMO, 195, 75)); items.push_back(Item(healthAnim, HEALTH, 195, 165)); // Spawn enemies spawnEnemies(); break; } case 2: { // Get map graphic filename = Gosu::resourcePrefix() + L"media/maps/map2.bmp"; // Get map walls numWalls = 29; wall someWalls[] = { wall(0, 0, 240, 0), wall(0, 0, 0, 210), wall(0, 210, 240, 210), wall(240, 210, 240, 0), wall(0, 60, 30, 60), wall(30, 60, 30, 30), wall(30, 30, 90, 30), wall(90, 30, 90, 90), wall(0, 120, 90, 120), wall(30, 120, 30, 90), wall(30, 90, 60, 90), wall(60, 90, 60, 60), wall(30, 210, 30, 150), wall(30, 150, 120, 150), wall(120, 150, 120, 90), wall(120, 90, 150, 90), wall(150, 60, 150, 180), wall(120, 60, 180, 60), wall(120, 30, 120, 60), wall(180, 30, 180, 60), wall(180, 30, 210, 30), wall(210, 60, 240, 60), wall(210, 150, 240, 150), wall(180, 90, 180, 210), wall(180, 90, 210, 90), wall(210, 90, 210, 120), wall(60, 180, 120, 180), wall(90, 180, 90, 210), wall(150, 0, 150, 30) }; walls = (wall *)realloc(walls, numWalls * sizeof(wall)); memcpy(walls, someWalls, (numWalls * sizeof(wall))); // Set entrances and exits down = Stair(75, 195, false); up = Stair(15, 105, true); // Set player location if (ascending) { player.warp(down.x(), down.y()); } else { player.warp(up.x(), up.y()); } // Set items despawnItems(); items.push_back(Item(ammoAnim, AMMO, 225, 195)); items.push_back(Item(healthAnim, HEALTH, 15, 195)); // Spawn enemies spawnEnemies(); break; } case 3: { // Get map graphic filename = Gosu::resourcePrefix() + L"media/maps/map3.bmp"; // Get map walls numWalls = 25; wall someWalls[] = { wall(0, 0, 240, 0), wall(0, 0, 0, 210), wall(0, 210, 240, 210), wall(240, 210, 240, 0), wall(0, 60, 30, 60), wall(30, 60, 30, 90), wall(30, 90, 60, 90), wall(60, 60, 60, 180), wall(30, 30, 90, 30), wall(90, 30, 90, 150), wall(30, 180, 180, 180), wall(180, 180, 180, 90), wall(210, 90, 210, 180), wall(210, 180, 240, 180), wall(210, 60, 210, 30), wall(210, 30, 120, 30), wall(120, 30, 120, 0), wall(90, 60, 180, 60), wall(150, 60, 150, 90), wall(120, 90, 180, 90), wall(90, 120, 150, 120), wall(150, 120, 150, 150), wall(150, 150, 120, 150), wall(0, 120, 30, 120), wall(30, 120, 30, 150) }; walls = (wall *)realloc(walls, numWalls * sizeof(wall)); memcpy(walls, someWalls, (numWalls * sizeof(wall))); // Set entrances and exits down = Stair(15, 135, false); up = Stair(-15, -15, true); // Set player location if (ascending) { player.warp(down.x(), down.y()); } else { player.warp(up.x(), up.y()); } // Set items despawnItems(); items.push_back(Item(ammoAnim, AMMO, 135, 15)); items.push_back(Item(healthAnim, HEALTH, 45, 75)); items.push_back(Item(kittensAnim, KITTENS, 135, 75)); // Spawn enemies spawnEnemies(); break; } default: break; } if (level == 1 && ascending) player.startSong1(); else if (level != 0) Gosu::Sample(Gosu::resourcePrefix() + L"media/sounds/levelChange.wav").play(); backgroundImage.reset(new Gosu::Image(graphics(), filename, true)); environment = Environment(numWalls, walls); }