Added heart and spawn of them
This commit is contained in:
@@ -24,7 +24,10 @@ ship(static_cast<int>(mainWindow->getSize().x) / 2, static_cast<int>(mainWindow-
|
||||
|
||||
meteorTexture1.loadFromFile("../assets/img/meteors/meteor-1.png");
|
||||
meteorTexture2.loadFromFile("../assets/img/meteors/meteor-2.png");
|
||||
spawnClock.restart();
|
||||
|
||||
heartTexture.loadFromFile("../assets/img/hearts/heart.png");
|
||||
|
||||
meteorSpawnClock.restart();
|
||||
}
|
||||
|
||||
|
||||
@@ -67,14 +70,20 @@ void Plansza::update() {
|
||||
|
||||
// generowanie nowego meteoru
|
||||
spawn_meteor();
|
||||
spawn_hearts();
|
||||
|
||||
|
||||
// utrzymanie meteorów i pocisków w ruchu
|
||||
for (auto& meteor : getMeteors()) {
|
||||
for (auto& meteor : meteors) {
|
||||
meteor.update();
|
||||
window->draw(meteor.getSprite());
|
||||
}
|
||||
|
||||
for (auto& heart : hearts) {
|
||||
heart.update();
|
||||
window->draw(heart.getSprite());
|
||||
}
|
||||
|
||||
for (auto& bullet : ship.getBullets()) {
|
||||
bullet.update();
|
||||
window->draw(bullet.getSprite());
|
||||
@@ -87,10 +96,12 @@ void Plansza::update() {
|
||||
|
||||
// Sprawdzenie czy meteory i pociski są poza granicami ekranu
|
||||
update_meteors();
|
||||
update_hearts();
|
||||
ship.updateBullets();
|
||||
|
||||
window->draw(ship.getSprite());
|
||||
|
||||
|
||||
// trochę dziwny sposób ale jednak działa
|
||||
for (auto& meteor : getMeteors()) {
|
||||
if(ship.getSprite().getGlobalBounds().intersects(meteor.getSprite().getGlobalBounds())) {
|
||||
@@ -162,7 +173,7 @@ void Plansza::update() {
|
||||
// Meteor-related niżej
|
||||
|
||||
void Plansza::spawn_meteor() {
|
||||
if (spawnClock.getElapsedTime().asSeconds() > rand() % 10 + 1) { // randomowy spawn meteorytów od 10 do 1 sekundy
|
||||
if (meteorSpawnClock.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);
|
||||
@@ -170,7 +181,16 @@ void Plansza::spawn_meteor() {
|
||||
meteors.emplace_back(RandomNumberGenerator::getRandomNumber(50,499), -100, meteorTexture1);
|
||||
}
|
||||
}
|
||||
spawnClock.restart();
|
||||
meteorSpawnClock.restart();
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::spawn_hearts() {
|
||||
if (heartSpawnClock.getElapsedTime().asSeconds() > rand() % 10 + 1) { // randomowy spawn meteorytów od 10 do 1 sekundy
|
||||
if (hearts.size() < 5) { // jeśli jest mniej niż 5 meteorów na planszy
|
||||
hearts.emplace_back(RandomNumberGenerator::getRandomNumber(50, 499), -100, heartTexture);
|
||||
}
|
||||
heartSpawnClock.restart();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,6 +203,15 @@ void Plansza::update_meteors() {
|
||||
}
|
||||
}
|
||||
|
||||
void Plansza::update_hearts() {
|
||||
// usuwanie serduszek które wyleciały poza ekran
|
||||
for (auto& heart : hearts) {
|
||||
if(heart.getStatus()) {
|
||||
hearts.erase(hearts.begin());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Size Plansza::getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user