diff --git a/headers/Plansza.h b/headers/Plansza.h index c8e0915..3aae063 100644 --- a/headers/Plansza.h +++ b/headers/Plansza.h @@ -20,8 +20,8 @@ public: private: std::vector meteors; Size size; - sf::Texture meteorTexture; - RandomNumberGenerator random; + sf::Texture meteorTexture1; + sf::Texture meteorTexture2; sf::Clock spawnClock; }; diff --git a/headers/RandomNumberGenerator.h b/headers/RandomNumberGenerator.h index a88dbaa..49b3acb 100644 --- a/headers/RandomNumberGenerator.h +++ b/headers/RandomNumberGenerator.h @@ -4,15 +4,11 @@ #include class RandomNumberGenerator { -private: - std::random_device rd; - std::mt19937 gen; - std::uniform_int_distribution<> dis; - public: - RandomNumberGenerator() : gen(rd()), dis(0, 499) {} - - int getRandomNumber() { + static int getRandomNumber(int min, int max) { + static std::random_device rd; + static std::mt19937 gen(rd()); + static std::uniform_int_distribution<> dis(min, max); return dis(gen); } }; diff --git a/main.cpp b/main.cpp index d4435b2..ecfc07b 100644 --- a/main.cpp +++ b/main.cpp @@ -23,6 +23,7 @@ int main() ship.setFirerate(200); while (window.isOpen()) { +// std::cout << "Liczba: " << RandomNumberGenerator::getRandomNumber(0,499) << std::endl; window.clear(); window.draw(backgroundSprite); // narysuj tło diff --git a/sources/Plansza.cpp b/sources/Plansza.cpp index 3024c89..6057327 100644 --- a/sources/Plansza.cpp +++ b/sources/Plansza.cpp @@ -5,14 +5,19 @@ Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth) { size.height = windowHeight; size.width = windowWidth; - meteorTexture.loadFromFile("../assets/img/meteor-1.png"); + meteorTexture1.loadFromFile("../assets/img/meteor-1.png"); + meteorTexture2.loadFromFile("../assets/img/meteor-2.png"); spawnClock.restart(); } void Plansza::spawn_meteor() { if (spawnClock.getElapsedTime().asSeconds() > rand() % 10 + 1) { // randomowy spawn meteorytów od 10 do 1 sekundy if (meteors.size() < 5) { // jeśli jest mniej niż 5 meteorów na planszy - meteors.emplace_back(random.getRandomNumber(), -100, meteorTexture); + if(rand() % 2 == 1) { + meteors.emplace_back(RandomNumberGenerator::getRandomNumber(0,499), -100, meteorTexture2); + } else { + meteors.emplace_back(RandomNumberGenerator::getRandomNumber(0,499), -100, meteorTexture1); + } } spawnClock.restart(); }