void start(RenderWindow& window) { Ball ball{windowWidth/2, windowHeight/2}; Paddle paddle{windowWidth/2, windowHeight - 50}; vector<Brick> bricks; for(int iX{0}; iX < countBlocksX; iX++) { for(int iY{0}; iY < countBlocksY; iY++) { bricks.emplace_back((iX + 1) * (blockWidth + 3) + 22, (iY + 2) * (blockHeight + 3)); } } /* * Game Loop * */ while(true) { window.clear(Color::Black); if(Keyboard::isKeyPressed(Keyboard::Key::Escape)) break; ball.update(); paddle.update(); testCollision(paddle, ball); for(auto& brick : bricks) { if(!brick.destroyed) { window.draw(brick.shape); } } hitBrick(bricks, ball); window.draw(paddle.shape); window.draw(ball.shape); window.display(); } }
void drawing(RenderWindow &window, engine *en) { window.clear(); ostringstream playerHealthString; playerHealthString << en->p->health; en->txt->healph.setString("" + playerHealthString.str()); en->map->lvl.Draw(window); window.draw(en->txt->healph); for (Entity* brick : en->map->listBrick) { window.draw(*brick->sprite); } for (Entity* bonus : en->map->listPointsBonus) { window.draw(*bonus->sprite); } checkForWinOrLosePlayer(en->id, window, en->im, en->txt, en->p); window.draw(*en->targetProtecting->sprite); for (Entity* entity : en->map->bullesPlayer) { window.draw(*entity->sprite); } for (Entity* entity : en->map->entities) { window.draw(*entity->sprite); } for (Entity* bulles : en->map->bullesEnemy) { window.draw(*bulles->sprite); } for (Entity* enemy : en->map->numberEnemies) { window.draw(*enemy->sprite); } if (en->id->g_appearanceEnemies) window.draw(en->im->spriteAppEnemies); window.display(); }
void draw_game(RenderWindow &window, Level &lvl, std::list<Entity*>::iterator &it, std::list<Entity*> &entities, PLAYER &Player, PlayerScores &plScores, int levelNumber) { init_font font; window.clear(Color(107, 140, 255)); lvl.Draw(window); for (it = entities.begin();it != entities.end();it++) (*it)->draw(window); Player.draw(window); plScores.draw(window, levelNumber); if (Player.isWin) { font.textFinish.setPosition(view.getCenter().x - 120, view.getCenter().y); window.draw(font.textFinish); font.textWin.setPosition(view.getCenter().x - 200, view.getCenter().y- 20); window.draw(font.textWin); } else if (!Player.life) { font.textFinish.setPosition(view.getCenter().x - 120, view.getCenter().y); window.draw(font.textFinish); font.textDead.setPosition(view.getCenter().x - 40, view.getCenter().y - 20); window.draw(font.textDead); } window.display(); }
void Game::menu() //menu function { std::cout << "state = MENU\n"; Button* menuTable[2]; //table of menu buttons menuTable[0] = new NewGameButton(Vector2f(300,40), Vector2f(0,0), Color::Green, "New Game" ); //button to the new game menuTable[1] = new ExitButton(Vector2f(300,40), Vector2f(0,100), Color::Red, "Exit" ); // button to exit while( state == MENU ) { Vector2f mouse(Mouse::getPosition( window )); //mouse handler Event event; while(window.pollEvent( event )) { if( event.type == Event::Closed ) state = END; else if( event.type == Event::MouseButtonReleased && event.mouseButton.button == Mouse::Left ) //mouse pressed { if ( menuTable[0]->contains( mouse )) state = GAME; else if ( menuTable[1]->contains( mouse )) menuTable[1]->onClick(); } } window.clear( Color::White ); for( int i=0; i<2; i++ ) window.draw( *menuTable[i] ); window.display(); } }
void run_animation(RenderWindow &window) { Clock clock; std::vector<initialization_blocks*> object; float x = RECTANGLES_SIZE.x / 2, y = 0; int number_block; for (int i = 0; i < NUMBER_BLOCKS; i++) { y += 10 + RECTANGLES_SIZE.y; object.push_back(new initialization_blocks(x, y, i)); } while (window.isOpen()) { Event event; while (window.pollEvent(event)) if (event.type == Event::Closed) window.close(); float time = clock.getElapsedTime().asMicroseconds(); clock.restart(); time = time / 800; window.clear(Color::White); number_block = 0; for (auto i : object) { i->update(time, number_block); window.draw(i->rectangle); number_block++; } window.display(); } }
void draw(Group & group, RenderWindow & window) { for(Block &thing: group.blocks) window.draw(*thing.block); window.display(); window.clear(Color::White); }
void update_graphics( RenderWindow& fen1, Building& Bataclan, vector<RectangleShape>& walls_ ){ //Rafraichissement du dessin fen1.clear(Color::Black); RectangleShape awareness(Vector2f((Pedest::ZONE_XMAX-Pedest::ZONE_XMIN)*Building::ZOOM , (Pedest::ZONE_YMAX-Pedest::ZONE_YMIN)*Building::ZOOM)); awareness.setPosition(Pedest::ZONE_XMIN*Building::ZOOM, Pedest::ZONE_YMIN*Building::ZOOM); awareness.setOutlineThickness(1); awareness.setFillColor(Color::Black); awareness.setOutlineColor(Color::Red); for (int i=0; i<Bataclan.width(); i++){ for (int j=0; j<Bataclan.length(); j++){ RectangleShape wall(Vector2f(Building::ZOOM,Building::ZOOM)); wall.setPosition(Building::ZOOM*i, Building::ZOOM*j); wall.setOutlineThickness(1); wall.setFillColor(Color::Black); wall.setOutlineColor(Color::Blue); fen1.draw(wall); } } fen1.draw(awareness); for (unsigned int j=0; j<walls_.size(); j++){ fen1.draw(walls_[j]); } for (int i=0; i<Building::NPEDEST; i++){ fen1.draw(Bataclan.people(i).img()); } fen1.display(); }
void display() { window.clear(Color::White); switch (gameState) { case INTRO: window.draw(title); window.draw(start); break; case PLAYING: window.draw(left); window.draw(right); grid.display(window); window.draw(player); window.draw(ball); window.draw(score); window.draw(lives); window.draw(top); window.draw(bottom); window.draw(fps); break; case GAME_WON: window.draw(won); break; case GAME_LOST: window.draw(lost); break; } window.display(); }
void Render(RenderWindow& window, Game* game) { SnakeParts* snake = game->snake; Map* map = game->map; Apple* apple = game->apple; window.clear(); //Map draw IntRect earth = IntRect(0, 0, SpriteSize, SpriteSize); IntRect wall = IntRect(SpriteSize, 0, SpriteSize, SpriteSize); for (int i = 0; i < MapHeight; i++) for (int j = 0; j < MapWidth; j++) { if (TileMap[i][j] == ' ') map->sprite.setTextureRect(earth); if (TileMap[i][j] == '1') map->sprite.setTextureRect(wall); map->sprite.setPosition((float)(j * SpriteSize), (float)(i * SpriteSize)); window.draw(map->sprite); } //Snake draw for (int i = 0; i < MaxLengthSnake; ++i) { if (snake[i].draw == true) { window.draw(snake[i].sprite); } } //Apple draw window.draw(apple->sprite); }
//Actual 2-player game Game::Game(RenderWindow &wind) : GameState(wind),status(0) { //sets end variable to false indicating game is not finished end=false; wind.clear(); //Clears window Chess.reset(wind); //Resets the chess game wind.display(); }
//Similar to 2-player game with just 1 difference i.e the function computer turn is called in case of 2nd players turn comvcom::comvcom(RenderWindow &wind) : GameState(wind) { end=false; wind.clear(); Chess.reset(wind); turn = 1; wind.display(); }
void Draw(RenderWindow & window, Car & car) { window.draw(car.SpriteFrontWheel); window.draw(car.SpriteBackWheel); window.draw(car.SpritePriora); window.draw(car.Road); window.display(); window.clear(Color::White); }
//a little bit ugly string fetchNameFromUser() { string resultString= "You have ended the game with score:" + std::to_string(score); Text alphabet [26]; Text resultText; setText(resultText, font, Color::White, 35, resultString, { 200,220 }); Text enterNameText; setText(enterNameText, font, Color::White, 30, "Please Enter Your Name", { 340,300 }); Text gameOverText; setText(gameOverText, font, Color::Red, 40, "GAME OVER", { 370,150 }); pair <unsigned char, unsigned char> myPair = { 0,0 }; char chosenLetter = 'A'; string userName = "******"; Text providedNameText; RectangleShape marker; while (window.waitEvent(myEvent)) { window.clear(Color::Black); setText(providedNameText, font, Color::White, 30, userName, { 460,360 }); drawTextes(gameOverText, enterNameText, providedNameText, scoreText,resultText); int j = 1; int k = 0; for (unsigned char i = 0; i<26; ++i) { if (0 == i % 13) { ++j; k=0; } ++k; char letter[2] = "A"; letter[0] = letter[0] + i; setText(alphabet[i], font, Color::White, 20 , letter , {350.0f+20*k,380.0f+20*j}); window.draw(alphabet[i]); } setMarker(marker, alphabet[chosenLetter - 65].getPosition()); window.draw(marker); static int i = 0; gameOverInput(myEvent, userName, chosenLetter, myPair, i); window.display(); if (3 == i) return userName; } }
void Difficulty::Moveright(RenderWindow &window) { if (SelectedNumberDif - 1 >= 0) { SelectedNumberDif--; window.clear(Color::Black); drawwindow(window); } }
void Draw(RenderWindow& window, RectangleStruct rect[QUANTITY]) { for (int i = 0; i < QUANTITY; i++) { window.draw(rect[i].square); } window.display(); window.clear(sf::Color::White); }
void Difficulty::Moveleft(RenderWindow &window) { if (SelectedNumberDif + 1 < 5) { SelectedNumberDif++; window.clear(Color::Black); drawwindow(window); } }
void loadingScreen(RenderWindow& window) { Text loadingMessage; loadingMessage.setFont(infoFont); loadingMessage.setColor(Color::Green); loadingMessage.setString("Loading..."); loadingMessage.setPosition(Vector2f(660, 750)); window.clear(Color::Black); window.draw(loadingMessage); window.display(); }
void Turt::window:: animate_window(RenderWindow& window, Graphics& graphics){ window.clear(sf::Color::Black); draw_drawables(window, graphics); window.display(); }
void Game::menu() { Text title("Mechanized Techno Explorer",font,80); title.setStyle(Text::Bold); title.setPosition(1280/2-title.getGlobalBounds().width/2,20); const int ile = 2; Text tekst[ile]; string str[] = {"Play","Exit"}; for(int i=0;i<ile;i++) { tekst[i].setFont(font); tekst[i].setCharacterSize(65); tekst[i].setString(str[i]); tekst[i].setPosition(1280/2-tekst[i].getGlobalBounds().width/2,250+i*120); } while(state == MENU) { Vector2f mouse(Mouse::getPosition()); Event event; while(window.pollEvent(event)) { //Wciœniêcie ESC lub przycisk X if(event.type == Event::Closed || event.type == Event::KeyPressed && event.key.code == Keyboard::Escape) state = END; //klikniêcie EXIT else if(tekst[1].getGlobalBounds().contains(mouse) && event.type == Event::MouseButtonReleased && event.key.code == Mouse::Left) { state = END; } } for(int i=0;i<ile;i++) if(tekst[i].getGlobalBounds().contains(mouse)) tekst[i].setColor(Color::Cyan); else tekst[i].setColor(Color::White); window.clear(); window.draw(title); for(int i=0;i<ile;i++) window.draw(tekst[i]); window.display(); } }
//this method stars game void InGame::startGame() { isPowerUpAlreadySpawned = false; isSnakeSlowedDown= false; Event event; //input handler for game, inputhandler controlls snake movement direction SnakeInputHandler *input = new SnakeInputHandler(); snake = new Snake(); gameSpeed = 100; previous = clock(); score = 0; apple = new Apple({Apple::getRandomNumber(0,800),Apple::getRandomNumber(0,600)}); setText(scoreText, font, std::to_string(score), Color::Red, 25, { 5,0 }); clock_t previousTime = clock(); clock_t lag = 0; //game loop while (gameStatus == GameStatus::IN_GAME) { window.pollEvent(event); window.clear(Color::Black); snake->updateDirection(); input->HandleInput(event,*snake); clock_t currentTime = clock(); clock_t elapsed = currentTime - previousTime; lag += elapsed; previousTime = currentTime; while (lag > gameSpeed) { //printf("lag:%d , gamespeed %d\n", lag, gameSpeed); update(*snake); lag -= gameSpeed; } Render(*snake); }; //after game is over, delete every dynamically allocated variables delete input; delete apple; delete snake; //check if powerUp has not been already deleted if (powerUp != nullptr) { delete powerUp; } }
int main(int, char const**) { // Create the main window RenderWindow window; window.create(VideoMode(800, 600), "Pong"); //Create and initialize the actual game screen GameScreen gamescreen = GameScreen(); gamescreen.initialize(); // Start the game loop while (window.isOpen()) { // Process events Event p1; while (window.pollEvent(p1)) { // Close window: exit if (p1.type == Event::Closed) { window.close(); } } // Clear screen window.clear(); /* Here I am trying to use that standard game loop with initialize, update, and draw. If I ever try to make a real game in C++ I know that I will need to know how to use these methods and create objects outside of this class. */ gamescreen.update(); //Draw each entity (sprite) for(Sprite ent : gamescreen.entities) { window.draw(ent); } // Update the window window.display(); } return EXIT_SUCCESS; }
void Score::Draw(RenderWindow& window, Time timeSinceLastDrawCall) { window.setFramerateLimit(70); window.clear(); window.draw(ScoreBackground); window.draw(CoinsCollectedLabel); window.draw(Coins); window.draw(Lives); window.draw(LivesleftLabel); window.draw(ScoreMade); window.draw(ScoreMadeLabel); window.display(); }
void UserInterface::CreateADialog(string Text , int fontsize, Font font, RenderWindow &win) { sf::Text text; text.setFont(font); text.setString(Text); text.setCharacterSize(fontsize); DialogSprite.setPosition(0 + 5, win.getSize().y - DialogSprite.getGlobalBounds().height); text.setPosition(DialogSprite.getGlobalBounds().left + 20, DialogSprite.getGlobalBounds().top + 30); win.draw(DialogSprite); win.draw(text); win.display(); win.clear(); }
void Game::menu() /// uruchamia i wyświetla menu { Text title("Pacman",font,200); /// nagłówek gry, czcionka i jej wielkość title.setColor(sf::Color(255, 211, 0, 255)); /// kolor nagłówka title.setPosition(1280/2-title.getGlobalBounds().width/2,20); /// pozycja nagłówka na ekranie const int liczba = 2; /// liczba napisów Text tekst[liczba]; string str[] = {"To Play Press P","To Exit Press Esc"}; /// tablica z napisami for(int i=0;i<liczba;i++) /// ustawienie parametrów dla dwóch napisów { tekst[i].setFont(font); /// ustawienie czcionki tekst[i].setCharacterSize(50); /// ustawienie wielkości czcionki tekst[i].setString(str[i]); tekst[i].setPosition(1280/2-tekst[i].getGlobalBounds().width/2,300+i*120); /// ustawienie napisów na ekranie } while(state == MENU) /// menu się wyświetla, dopóki user chce być w menu { Event event; while(window.pollEvent(event)) { ///Wciśnięcie ESC lub przycisk X if(event.type == Event::Closed || event.type == Event::KeyPressed && event.key.code == Keyboard::Escape) state = END; ///kliknięcie MENU else if(event.type == Event::KeyPressed && event.key.code == Keyboard::P) state = GAME; } for(int i=0;i<liczba;i++)///ustawienie koloru dla tekstu tekst[i].setColor(Color(6, 56, 171, 255)); window.clear(Color::White);/// ustawienie białego tła window.draw(title); /// wyświetlenie tytułu for(int i=0;i<liczba;i++) /// wyświetlenie tekstu window.draw(tekst[i]); window.display(); } }
void render() { window.clear(Color::Black); if (isGameStarted == false) { window.draw(initialText); } window.draw(ball.ballShape); window.draw(scoreText); for (int i = 0; i < 4; ++i) { window.draw(platform[i].platformShape); } window.display(); }
void Renderer::render(RenderWindow& window, const World& world) { // clear the window with black color window.clear(Color::Black); Renderer::renderShip(world.getShip(), window); for (auto& e : world.getEnemies()) { Renderer::renderEnemyShip(*e, window); } cout << world.getBullets().size() << endl; for (auto& b : world.getBullets()) { Renderer::renderBullet(*b, window); } // draw everything here... // window.draw(...); // end the current frame window.display(); }
void intro() { Sprite firecan; firecan.setTexture(MediaBucket.getTexture("firecan")); firecan.setOrigin(firecan.getLocalBounds().width/2, firecan.getLocalBounds().height/2); firecan.setPosition(400, 300); Time intro_time = seconds(4); Clock clock; double opacity = 255; RectangleShape filter; filter.setFillColor(Color(255,255,255,opacity)); filter.setSize(Vector2f(800,600)); filter.setOrigin(400,300); filter.setPosition(400,300); while(intro_time > seconds(0)) { while(app.pollEvent(event)) { if(event.type == Event::KeyPressed) { if(event.key.code == Keyboard::Escape) { intro_time = seconds(0); } } } elapsed_time = clock.restart(); intro_time -= elapsed_time; if(opacity >= 0) { opacity -= 255/2*elapsed_time.asSeconds(); if(opacity < 0) { opacity = 0; } } filter.setFillColor(Color(255,255,255,opacity)); app.clear(Color::White); app.draw(firecan); app.draw(filter); app.display(); } }
void StartProgram(RenderWindow & window, vector<Block> & blocks, int & stateIndex) { Clock frameClock; //time for screen-update float timeSinceLastFrame; while (window.isOpen()) { timeSinceLastFrame = frameClock.getElapsedTime().asMilliseconds(); ProcessEvents(window); if (timeSinceLastFrame >= TIME_PER_FRAME) //screen update every second { window.clear(Color::White); frameClock.restart(); Update(blocks, stateIndex); Draw(window, blocks); window.display(); } } }
void StartProgram(RenderWindow & window, Pendulum & pendulum) { Clock frameClock; int timeSinceLastFrame; while (window.isOpen()) { timeSinceLastFrame = frameClock.getElapsedTime().asMilliseconds(); ProcessEvents(window); if (timeSinceLastFrame >= TIME_PER_FRAME) { frameClock.restart(); ComputePhysics(pendulum); UpdatePendulum(pendulum); window.clear(Color::White); Draw(window, pendulum); window.display(); } } };
void render(RenderWindow &window, Sprite &mapSprite, Sprite *buttons, char(*myPlace)[sizeRectangleWeb], char(*enemyPlace)[sizeRectangleWeb]) { window.clear(); // ќтрисовка карты for (int i = 1; i < sizeRectangleWeb - 1; i++) for (int j = 1; j < sizeRectangleWeb - 1; j++) { if (myPlace[i][j] == '_') mapSprite.setTextureRect(IntRect(0, 0, 32, 32)); if (myPlace[i][j] == '0') mapSprite.setTextureRect(IntRect(32, 0, 32, 32)); if (myPlace[i][j] == '#') mapSprite.setTextureRect(IntRect(64, 0, 32, 32)); if (myPlace[i][j] == 'X') mapSprite.setTextureRect(IntRect(96, 0, 32, 32)); mapSprite.setPosition(j * 32, i * 32); window.draw(mapSprite); if (enemyPlace[i][j] == '_') mapSprite.setTextureRect(IntRect(128, 0, 32, 32)); if (enemyPlace[i][j] == '0') mapSprite.setTextureRect(IntRect(32, 0, 32, 32)); if (enemyPlace[i][j] == '#') mapSprite.setTextureRect(IntRect(128, 0, 32, 32)); if (enemyPlace[i][j] == 'X') mapSprite.setTextureRect(IntRect(96, 0, 32, 32)); mapSprite.setPosition(j * 32 + (sizeRectangleWeb - 1) * 32, i * 32); window.draw(mapSprite); } // ќтрисовка кнопок buttons[0].setTextureRect(IntRect(0, 0, 96, 32)); buttons[1].setTextureRect(IntRect(0, 32, 96, 32)); buttons[0].setPosition((sizeRectangleWeb - 2) * 32, (sizeRectangleWeb - 2) * 32 + 64); buttons[1].setPosition((sizeRectangleWeb - 2) * 32, (sizeRectangleWeb - 2) * 32 + 108); window.draw(buttons[0]); window.draw(buttons[1]); window.display(); }