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
Andrii Solianyk 72e2116dc7 Refactor of structs
Refactored Size and Position
Placed them in different .h files
2024-12-04 14:47:50 +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/meteors/meteor-1.png");
meteorTexture2.loadFromFile("../assets/img/meteors/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(50,499), -100, meteorTexture2);
} else {
meteors.emplace_back(RandomNumberGenerator::getRandomNumber(50,499), -100, meteorTexture1);
}
}
spawnClock.restart();
}
}
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());
}
}
}