void createLevel () { scrn.clearScreen(); bricks.clear(); enemies.clear(); bombs.clear(); for (int i = 0; i < 13; i++) { for (int j = 0; j < 15; j++) { switch ( lvls[NUM_LVL][i][j]) { case 2: { bricks.push_back(brick (calculateCoordinates(j - 1), calculateCoordinates(j), calculateCoordinates(i-1), calculateCoordinates(i), scrn)); } break; case 3: { enemies.push_back(enemy (calculateCoordinates(j - 1), calculateCoordinates(j), calculateCoordinates(i-1), calculateCoordinates(i), scrn)); } break; } } } lvlup = portal (10, 50, 410, 450, scrn); Main = hero (scrn); }
int main() { bool bCont = true; char strCont = 'y'; while (bCont) { objScreen.clearScreen(); objScreen.moveCursor(0, 0); cout.flush(); buildArray(); printArray(); if (aBoard[0][0][0].value == ' ') { objScreen.printChar('-', aBoard[0][0][0].x, aBoard[0][0][0].y, 32, 0, 0, 25000); } if (mazeMe(0, 0, 0)) { objScreen.printString("Puzzled Solved!", 1, 22, 25000); } else { objScreen.printString("Puzzle Unsolvable.", 1, 22, 25000); } objScreen.moveCursor(0, 23); cout.flush(); objScreen.printString("Do you want to play another game (y/n)? ", 1, 23, 25000); cin >> strCont; if (strCont == 'n') { bCont = false; } cin.ignore(1000, '\n'); } return 0; }
int main ( int argc, char** argv) { sf::RenderWindow window(sf::VideoMode(wW, wH), "MyDynablaster", sf::Style::Titlebar); sf::Clock clock; //==================================================================================================== Textures for objects sf::Texture texMainHero; texMainHero.loadFromFile("main_hero.png"); sf::Sprite sprMainHero; sprMainHero.setTexture(texMainHero); sf::Texture texBrick; texBrick.loadFromFile("brick.png"); sf::Sprite sprBrick; sprBrick.setTexture(texBrick); sf::Texture texEnemy; texEnemy.loadFromFile("enemy.png"); sf::Sprite sprEnemy; sprEnemy.setTexture(texEnemy); sf::Texture texBomb; texBomb.loadFromFile("bomb.png"); sf::Sprite sprBomb; sprBomb.setTexture(texBomb); sf::Texture texPortal; texPortal.loadFromFile("portal.png"); sf::Sprite sprPortal; sprPortal.setTexture(texPortal); sf::Texture texFire; texFire.loadFromFile("fire.png"); sf::Sprite sprFire; sprFire.setTexture(texFire); sf::Font font; if (!font.loadFromFile("font.ttf")) { return 3; } //-----------------------------------------------------------------------------------------------Boolean variables bool lvl_is_completed = false; bool in_menu = true; bool gamer_lose = false; // -----------------------------------------------------------------------------------------------Game while (window.isOpen()) { sf::Event event; while ( in_menu) { window.clear(sf::Color::White); sf::Text txt1, txt2; const int txt1_x = 100, txt1_y=100; txt1.setFont(font); txt1.setString("Start game"); txt1.setColor(sf::Color::Black); txt1.setPosition(txt1_x, txt1_y); txt1.setCharacterSize(72); window.draw(txt1); const int txt2_x = 100, txt2_y=180; txt2.setFont(font); txt2.setString("Exit"); txt2.setColor(sf::Color::Black); txt2.setPosition(txt2_x,txt2_y); txt2.setCharacterSize(72); window.draw(txt2); window.display(); while ( window.pollEvent(event)) { eventsInMenu( event, window, in_menu, txt1_x, txt1_y, txt2_x, txt2_y); } } while ( window.pollEvent(event) ) { if(scrn.getRun()) { eventsInGame(event, window); } else { if(gamer_lose) { eventsAfterLosing (event, window, in_menu); } else { eventsAfterWin (event, window, in_menu, 100, 150, 100, 250); } } } //--------------------------------------------------------------------------------------------------------------------Draw window.clear(sf::Color::White); if (scrn.getRun() == true) { sprPortal.setPosition(sf::Vector2f(lvlup.l, lvlup.b)); window.draw(sprPortal); if (! bricks.empty()) { for (list<brick>::iterator i = bricks.begin(); i != bricks.end(); ++i) { sprBrick.setPosition(sf::Vector2f(i->l, i->b)); window.draw(sprBrick); } } if (! enemies.empty()) { sf::Time elapsed1 = clock.getElapsedTime(); if (elapsed1.asSeconds() >= 0.5f) { for (list<enemy>::iterator i = enemies.begin(); i != enemies.end(); ++i) { i->motion(scrn, Main); } sf::Time elapsed1 = clock.restart(); } for (list<enemy>::iterator i = enemies.begin(); i != enemies.end(); ++i) { sprEnemy.setPosition(sf::Vector2f(i->l, i->b)); window.draw(sprEnemy); } } if ( !bombs.empty()) { for (list<bomb>::iterator i = bombs.begin(); i != bombs.end(); ++i) { sprBomb.setPosition(sf::Vector2f(i->l, i->b)); if ( (i->clock).getElapsedTime().asSeconds() >= 3.0) { i->damage(window, sprFire); if ( (i->clock).getElapsedTime().asSeconds() > 5.0) { lst_iter.push_back(i); } } window.draw(sprBomb); } } sprMainHero.setPosition (sf::Vector2f (Main.l, Main.b)); window.draw (sprMainHero); if ( enemies.empty() && Main.b == lvlup.b && Main.r ==lvlup.r) { std::cout<<NUM_LVL<<std::endl; if ( NUM_LVL < max_num_lvls -1) { levelUp(); } else { std::cout<<"I'm here"<< std::endl; scrn.setRun(false); } } } else { bricks.clear(); bombs.clear(); enemies.clear(); scrn.clearScreen(); scrn.setRun(false); sf::Text txt1, txt2, txt3, txt4; if ( NUM_LVL >= max_num_lvls - 1) { getText(txt1, font, "You Win!!", 100, 50, 72); window.draw(txt1); getText(txt2, font, "Back in menu", 100, 150, 72); window.draw(txt2); getText(txt3, font, "Exit", 100, 250, 72); window.draw(txt3); } else { gamer_lose = true; getText(txt1, font, "You lose", 100, 50, 72); window.draw(txt1); getText(txt2, font, "Try again?", 100, 150, 72); window.draw(txt2); getText(txt3, font, "Yes", 100, 250, 72); window.draw(txt3); getText(txt4, font, "No", 250, 250, 72); window.draw(txt4); } } window.display(); if ( bombs.size() != 0) { for (list<list<bomb>::iterator>::iterator i = lst_iter.begin(); i != lst_iter.end(); ++i) { bombs.remove( *(*i)); } lst_iter.clear(); } } //while (window.isOpen()) return 0; }