Dodano podstawowy licznik
This commit is contained in:
@@ -21,6 +21,7 @@ public:
|
||||
void spawn_meteor();
|
||||
void update_meteors();
|
||||
void update();
|
||||
void update_score();
|
||||
private:
|
||||
Size size;
|
||||
Background background;
|
||||
@@ -29,8 +30,11 @@ private:
|
||||
sf::Texture meteorTexture1;
|
||||
sf::Texture meteorTexture2;
|
||||
sf::Clock spawnClock;
|
||||
sf::Clock scoreClock;
|
||||
std::vector<Meteor> meteors;
|
||||
sf::RenderWindow *window;
|
||||
sf::Font font;
|
||||
unsigned int score = 0;
|
||||
};
|
||||
|
||||
#endif //PLANSZA_H
|
||||
|
||||
@@ -12,6 +12,13 @@ ship(static_cast<int>(mainWindow->getSize().x) / 2, static_cast<int>(mainWindow-
|
||||
size.height = static_cast<int>(windowHeight);
|
||||
size.width = static_cast<int>(windowWidth);
|
||||
|
||||
score = 0;
|
||||
|
||||
if (!font.loadFromFile("../assets/fonts/arial.ttf")) {
|
||||
std::cerr << "Error loading font\n";
|
||||
exit(-500);
|
||||
}
|
||||
|
||||
ship.setMovingSpeed(8);
|
||||
ship.setFirerate(200);
|
||||
|
||||
@@ -157,6 +164,7 @@ void Plansza::update() {
|
||||
++meteorIt;
|
||||
}
|
||||
}
|
||||
update_score();
|
||||
}
|
||||
|
||||
// Meteor-related niżej
|
||||
@@ -191,5 +199,18 @@ std::vector<Meteor> &Plansza::getMeteors() {
|
||||
return meteors;
|
||||
}
|
||||
|
||||
// TODO: naliczanie punktów za zabicie wrogów
|
||||
void Plansza::update_score() {
|
||||
if (scoreClock.getElapsedTime().asMilliseconds() > 500) {
|
||||
score++;
|
||||
scoreClock.restart();
|
||||
}
|
||||
|
||||
sf::Text text(std::to_string(score), font, 24);
|
||||
text.setFillColor(sf::Color::White);
|
||||
text.setPosition(25, 25);
|
||||
window->draw(text);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user