Różne meteoryty
This commit is contained in:
@@ -20,8 +20,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::vector<Meteor> meteors;
|
std::vector<Meteor> meteors;
|
||||||
Size size;
|
Size size;
|
||||||
sf::Texture meteorTexture;
|
sf::Texture meteorTexture1;
|
||||||
RandomNumberGenerator random;
|
sf::Texture meteorTexture2;
|
||||||
sf::Clock spawnClock;
|
sf::Clock spawnClock;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,15 +4,11 @@
|
|||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
class RandomNumberGenerator {
|
class RandomNumberGenerator {
|
||||||
private:
|
|
||||||
std::random_device rd;
|
|
||||||
std::mt19937 gen;
|
|
||||||
std::uniform_int_distribution<> dis;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RandomNumberGenerator() : gen(rd()), dis(0, 499) {}
|
static int getRandomNumber(int min, int max) {
|
||||||
|
static std::random_device rd;
|
||||||
int getRandomNumber() {
|
static std::mt19937 gen(rd());
|
||||||
|
static std::uniform_int_distribution<> dis(min, max);
|
||||||
return dis(gen);
|
return dis(gen);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
1
main.cpp
1
main.cpp
@@ -23,6 +23,7 @@ int main()
|
|||||||
ship.setFirerate(200);
|
ship.setFirerate(200);
|
||||||
|
|
||||||
while (window.isOpen()) {
|
while (window.isOpen()) {
|
||||||
|
// std::cout << "Liczba: " << RandomNumberGenerator::getRandomNumber(0,499) << std::endl;
|
||||||
window.clear();
|
window.clear();
|
||||||
|
|
||||||
window.draw(backgroundSprite); // narysuj tło
|
window.draw(backgroundSprite); // narysuj tło
|
||||||
|
|||||||
@@ -5,14 +5,19 @@
|
|||||||
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth) {
|
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth) {
|
||||||
size.height = windowHeight;
|
size.height = windowHeight;
|
||||||
size.width = windowWidth;
|
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();
|
spawnClock.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plansza::spawn_meteor() {
|
void Plansza::spawn_meteor() {
|
||||||
if (spawnClock.getElapsedTime().asSeconds() > rand() % 10 + 1) { // randomowy spawn meteorytów od 10 do 1 sekundy
|
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
|
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();
|
spawnClock.restart();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user