diff --git a/headers/Plansza.h b/headers/Plansza.h index 0971823..ed5ce85 100644 --- a/headers/Plansza.h +++ b/headers/Plansza.h @@ -21,6 +21,7 @@ public: void spawn_meteor(); void update_meteors(); void update(); + void update_score(); private: Size size; Background background; @@ -29,8 +30,11 @@ private: sf::Texture meteorTexture1; sf::Texture meteorTexture2; sf::Clock spawnClock; + sf::Clock scoreClock; std::vector meteors; sf::RenderWindow *window; + sf::Font font; + unsigned int score = 0; }; #endif //PLANSZA_H diff --git a/sources/Plansza.cpp b/sources/Plansza.cpp index 5183a91..995ba12 100644 --- a/sources/Plansza.cpp +++ b/sources/Plansza.cpp @@ -12,6 +12,13 @@ ship(static_cast(mainWindow->getSize().x) / 2, static_cast(mainWindow- size.height = static_cast(windowHeight); size.width = static_cast(windowWidth); + score = 0; + + if (!font.loadFromFile("../assets/fonts/arial.ttf")) { + std::cerr << "Error loading font\n"; + exit(-500); + } + ship.setMovingSpeed(8); ship.setFirerate(200); @@ -157,6 +164,7 @@ void Plansza::update() { ++meteorIt; } } + update_score(); } // Meteor-related niżej @@ -191,5 +199,18 @@ std::vector &Plansza::getMeteors() { return meteors; } +// TODO: naliczanie punktów za zabicie wrogów +void Plansza::update_score() { + if (scoreClock.getElapsedTime().asMilliseconds() > 500) { + score++; + scoreClock.restart(); + } + + sf::Text text(std::to_string(score), font, 24); + text.setFillColor(sf::Color::White); + text.setPosition(25, 25); + window->draw(text); +} +