Obracające się meteoryty, koniec gry przy natrafieniu na meteoryt. Poprawione sprajty statku, meteorytu i pocisku
37 lines
998 B
C++
37 lines
998 B
C++
#include <random>
|
|
#include <iostream>
|
|
#include "../headers/Plansza.h"
|
|
|
|
Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth) {
|
|
size.height = windowHeight;
|
|
size.width = windowWidth;
|
|
meteorTexture.loadFromFile("../assets/img/meteor.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);
|
|
}
|
|
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());
|
|
}
|
|
}
|
|
}
|