void Engine::update(sf::RenderWindow& window){ getMousePosition(window); last_turn_board_state = board.update(clicked,turn,mouse); if(clicked && state != Winner) { if(last_turn_board_state == Board::NextTurn) { turn = players[(++current_player_number)%=2].get(); ///unfortunately changes when there were player turn failed DEBUG_MSG("NEXT TURN : " << turn->toStr() << std::endl); } clicked = false; if(last_turn_board_state == Board::Winner) { DEBUG_MSG("Winner is: " << turn->toStr() << std::endl); state = Winner; } } if(state == PlayingGame) window.draw(board); else if(state == Winner) { window.setView(window.getDefaultView()); std::string winning_msg = "Winner is: "; std::string tmp = "\n\nPress esc to return to menu."; winning_msg += turn->toStr(); winning_msg += tmp; sf::Text text; text.setFont(goodfoot); text.setString(winning_msg); text.setCharacterSize(50); text.setColor(sf::Color::White); text.setStyle(sf::Text::Bold); text.setPosition(window.getSize().x/2.0 - text.getLocalBounds().width/2.0, window.getSize().y/2.0 - text.getLocalBounds().height/2.0); window.draw(text); } }
void editLevelStateClass::draw(sf::RenderWindow& window) { window.setView(view); window.clear(sf::Color::Black); window.draw(backgroundSprite); if(drawAllFloor == true) { for(editFloorStruct& thisFloor : listOfFloor) { window.draw(thisFloor.floor); } } if(currentFloor != -1) { window.draw(listOfFloor[currentFloor].floor); for(std::pair<sf::RectangleShape, std::string>& thisWall : listOfFloor[currentFloor].listOfWall) { window.draw(thisWall.first); } } if(currentMode != NO_MODE) { window.draw(tempoRect.rect); } window.draw(sprite); if(chooseNameOfLevel == true) { window.setView(window.getDefaultView()); window.draw(nameOfLevelText); } }
int Logo::Run (sf::RenderWindow &App) { sf::Event Event; bool Running = true; sf::Texture Image; sf::Sprite Sprite; int alpha = 0; int alphab = 0; sf::Font Font; sf::Text autor; sf::Clock clock; sf::Texture Image2; sf::Sprite glhf; if (!Image.loadFromFile("Data/images/logo_gear.png")) { std::cerr<<"Error loading logo_gear.png"<<std::endl; return (-1); } Sprite.setTexture(Image); Sprite.setColor(sf::Color(255, 255, 255, alpha)); Sprite.setOrigin(Image.getSize().x/2, Image.getSize().y/2); Sprite.setPosition(400,200); if (!Image2.loadFromFile("Data/images/passion.png")) { std::cerr<<"Error loading passion.png"<<std::endl; return (-1); } glhf.setTexture(Image2); glhf.setColor(sf::Color(255, 255, 255, alphab)); glhf.setOrigin(Image2.getSize().x/2, Image2.getSize().y/2); glhf.setPosition(400,330); autor.setFont(resources::Font); autor.setCharacterSize(16); autor.setString("created by Lukasz Swiderski"); autor.setPosition(550,580); autor.setColor(sf::Color::Black); sf::View CameraPosition; CameraPosition=App.getDefaultView(); while (Running) { if(clock.getElapsedTime().asSeconds()>3) return 0; //Verifying events while (App.pollEvent(Event)) { // Window closed if (Event.type == sf::Event::Closed) { return (-1); } //Key pressed if (Event.type == sf::Event::KeyPressed) { switch (Event.key.code) { case sf::Keyboard::Escape: return(0); break; default : break; } } } //When getting at alpha_max, we stop modifying the sprite if (alpha<alpha_max) { alpha=alpha+5; if(alpha>alpha_max) alpha=alpha_max; clock.restart(); } if(alpha_max==alpha && alphab<alpha_max) { alphab=alphab+5; if(alphab>alpha_max) alphab=alpha_max; clock.restart(); } Sprite.setColor(sf::Color(255, 255, 255, alpha/alpha_div)); glhf.setColor(sf::Color(255, 255, 255, alphab/alpha_div)); //Drawing App.clear(sf::Color::White); App.draw(Sprite); App.draw(glhf); App.draw(autor); App.display(); } //Never reaching this point normally, but just in case, exit the application return (-1); }
void LevelEditor::handleEvents(sf::Event& event, sf::RenderWindow& window) { if(event.type == sf::Event::MouseButtonPressed || event.type == sf::Event::MouseButtonReleased) { //have the moust position that is relative to the view and also relative to the window itself //the one that is relative to the window is used to interact with the menus because the menus never move, while the one relative to the view //is used to interact with the world because the world can move according to the camera sf::Vector2f worldPosition = window.mapPixelToCoords(sf::Mouse::getPosition(window)); //in order to get the mouse position relative to the screen you need to apply the default window view so the position of the click is accurate sf::Vector2f screenPosition = window.mapPixelToCoords(sf::Mouse::getPosition(window), window.getDefaultView()); if(event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Left) { //if a menu button was pressed then don't let users create things if(!buttonPressEvents(screenPosition, window)) { leftClickEvents(worldPosition, window); } rectangleStart = worldPosition; } else if(event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Right) { rightClickEvents(worldPosition); } if(event.type == sf::Event::MouseButtonReleased && event.mouseButton.button == sf::Mouse::Left) { leftReleaseEvents(worldPosition, window); } } if(event.type == sf::Event::KeyPressed) { keyPressEvent(event); } if(event.type == sf::Event::Resized) { resizedEvent(event, window); } }
void particle_system::draw(sf::RenderWindow &window, sf::View view) { window.setView(view); window.draw(va); window.setView(window.getDefaultView()); }
int Credits::Run (sf::RenderWindow &App) { sf::Event Event; bool Running = true; txt.setFont(resources::Font); txt.setCharacterSize(20); txt.setColor(sf::Color::White); sf::View CameraPosition; CameraPosition=App.getDefaultView(); while (Running) { //Verifying events while (App.pollEvent(Event)) { // Window cLoadingd if (Event.type == sf::Event::Closed) { return (-1); } //Key pressed if (Event.type == sf::Event::KeyPressed) { switch (Event.key.code) { case sf::Keyboard::Escape: return (0); break; default : break; } } } //When getting at alpha_max, we stop modifying the sprite //Drawing App.setView(CameraPosition); txt.setString("Code & Design: Lukasz Swiderski"); txt.setPosition(180,180); App.draw(txt); txt.setString(" Music: Marek Rubczewski"); txt.setPosition(180,220); App.draw(txt); txt.setString("made by neufrin.com"); txt.setPosition(300,570); App.draw(txt); App.display(); App.clear(); } //Never reaching this point normally, but just in case, exit the application return (-1); }
int main() { sf::Clock clock; double s = 0; double viewZoom = 1.0f; srand(time(0)); for (u32 i = 0; i < PN; i++) { particule[i]._px = rand() % WINX; particule[i]._py = rand() % WINY; if (INITIAL_SPEED_ACTIVATE) { particule[i]._mx = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV; particule[i]._my = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV; } else { particule[i]._mx = 0; particule[i]._my = 0; } particule[i]._mass = PAR_MASS; particule[i]._color = PCOLOR; } planet.setPosition(sf::Vector2f(WINX/2, WINY/2)); planet.setOrigin(sf::Vector2f(10.0f, 10.0f)); planet.setFillColor(sf::Color::Blue); win.create(sf::VideoMode(WINX, WINY), "ORBITE"); win.setFramerateLimit(MAXFPS); clock.restart(); while (win.isOpen()) { s = clock.restart().asSeconds(); s *= SPEED; sf::View view = win.getDefaultView(); view.zoom(viewZoom); while (win.pollEvent(eve)) { if (eve.type == sf::Event::Closed) win.close(); if (eve.type == sf::Event::KeyPressed) { if (eve.key.code == sf::Keyboard::Add) viewZoom -= 0.25f; else if (eve.key.code == sf::Keyboard::Subtract) viewZoom += 0.25f; else if (eve.key.code == sf::Keyboard::Space) { trace.clear(); for (u32 i = 0; i < PN; i++) { particule[i]._px = rand() % WINX; particule[i]._py = rand() % WINY; if (INITIAL_SPEED_ACTIVATE) { particule[i]._mx = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV; particule[i]._my = ((rand() % INITIAL_SPEED) - INITIAL_SPEED / 2) / INITIAL_SPEED_DIV; } else { particule[i]._mx = 0; particule[i]._my = 0; } particule[i]._mass = PAR_MASS; particule[i]._color = PCOLOR; } } } } planet.setPosition((sf::Vector2f)sf::Mouse::getPosition(win)); for (u32 i = 0; i < PN; i++) { particule[i].updateToPosition(planet.getPosition(), PL_MASS, s); part[i].position = sf::Vector2f(particule[i]._px, particule[i]._py); part[i].color = particule[i]._color; if (ACTIVATE_ORBIT_TRACE) { sf::Vertex cpy = part[i]; trace.append(cpy); } } win.setView(view); win.clear(sf::Color::Black); win.draw(planet); win.draw(part); win.draw(trace); win.display(); } return (0); }
void ClientStateGameEnd::render(sf::RenderWindow& window) const { ClientStateGameStarted::render(window); window.setView(window.getDefaultView()); window.draw(TextView("Someone has win the game", 40, TypeAlign::Center)); }