Zaimplementowano pauze

This commit is contained in:
2025-01-09 12:11:56 +01:00
parent 5ad7cc9d1e
commit 62808a9fbf
3 changed files with 120 additions and 89 deletions

View File

@@ -19,6 +19,7 @@ int main() {
icon.loadFromFile("../assets/img/icon/ikonka.png");
mainWindow.setIcon(128, 128, icon.getPixelsPtr());
bool isPaused = false;
Plansza plansza(mainWindow.getSize().y, mainWindow.getSize().x, &mainWindow, selectedShip);
@@ -32,9 +33,27 @@ int main() {
mainWindow.close();
}
plansza.update();
mainWindow.display();
// Obsługa pauzy
if (event.key.code == sf::Keyboard::P) {
isPaused = !isPaused;
sf::RectangleShape bg(sf::Vector2f(mainWindow.getSize().x, mainWindow.getSize().y));
bg.setFillColor(sf::Color(0,0,0,100));
sf::Text text("PAUZA", plansza.font, 50);
text.setOrigin(text.getLocalBounds().getSize().x/2, text.getLocalBounds().getSize().y/2);
text.setFillColor(sf::Color::White);
text.setPosition(mainWindow.getSize().x/2, mainWindow.getSize().y/2);
plansza.update();
mainWindow.draw(bg);
mainWindow.draw(text);
mainWindow.display();
}
if (!isPaused) { // jesli nie spauzowane to graj
plansza.update();
mainWindow.display();
}
}
return 0;
@@ -121,6 +140,9 @@ void menu() {
menuWindow.close();
exit(-2);
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Enter)) {
menuWindow.close();
}
if (event.type == sf::Event::MouseButtonPressed) {
if (event.mouseButton.button == sf::Mouse::Left) {