40 lines
1.0 KiB
C++
40 lines
1.0 KiB
C++
#include <random>
|
|
#include <iostream>
|
|
#include "../headers/Plansza.h"
|
|
|
|
Plansza::Plansza(int windowHeight, int windowWidth) {
|
|
size.height = windowHeight;
|
|
size.width = windowWidth;
|
|
meteorsCounter = 0;
|
|
meteorTexture.loadFromFile("../assets/img/meteor.png");
|
|
spawnClock.restart();
|
|
}
|
|
|
|
// TODO: Meteory na jednym poziomie ze statkiem
|
|
// TODO: Kolizje
|
|
void Plansza::spawn_meteor() {
|
|
if (spawnClock.getElapsedTime().asSeconds() > 1.0f) { // spawn co 1 sekunde
|
|
if (meteors.size() < 5) { // jeśli jest mniej niż 5 meteorów na planszy
|
|
meteors.emplace_back(random.getRandomNumber(), -100, meteorTexture);
|
|
}
|
|
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());
|
|
}
|
|
}
|
|
}
|