This repository has been archived on 2025-06-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
LotoStatek/sources/Plansza.cpp
2024-11-22 09:38:13 +01:00

42 lines
1.2 KiB
C++

#include <random>
#include <iostream>
#include "../headers/Plansza.h"
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth) {
size.height = windowHeight;
size.width = windowWidth;
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
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();
}
}
Plansza::Size Plansza::getSize() {
return size;
}
std::vector<Meteor> &Plansza::getMeteors() {
return meteors;
}
void Plansza::update_meteors() {
// usuwanie meteorów które wyleciały poza ekran
for (auto& meteor : meteors) {
if(meteor.getStatus()) {
meteors.erase(meteors.begin());
}
}
}