Złączono i wszystko działa, ale trzeba zrobić mocny refactor Planszy bo za dużo niewiadomo skąd biorących się pętli
This commit is contained in:
@@ -59,7 +59,7 @@ Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::Render
|
||||
spawnClock.restart();
|
||||
}
|
||||
|
||||
|
||||
// TODO: Refactor tej metody bo rozrosła się za bardzo już
|
||||
void Plansza::update() {
|
||||
// tło
|
||||
background.update();
|
||||
@@ -136,18 +136,18 @@ void Plansza::update() {
|
||||
update_hearts();
|
||||
ship->updateBullets();
|
||||
|
||||
ship.update();
|
||||
ship->update();
|
||||
window->draw(ship->getSprite());
|
||||
|
||||
for (auto &meteor: meteors) {
|
||||
if (ship->getSprite().getGlobalBounds().intersects(meteor.getSprite().getGlobalBounds())) {
|
||||
ship.onHit();
|
||||
ship->takeDamage();
|
||||
}
|
||||
}
|
||||
|
||||
for (auto heartIt = hearts.begin(); heartIt != hearts.end();) {
|
||||
if (ship.getSprite().getGlobalBounds().intersects(heartIt->getSprite().getGlobalBounds())) {
|
||||
ship.healUP();
|
||||
if (ship->getSprite().getGlobalBounds().intersects(heartIt->getSprite().getGlobalBounds())) {
|
||||
ship->healUP();
|
||||
heartIt = hearts.erase(heartIt);
|
||||
} else {
|
||||
++heartIt;
|
||||
@@ -156,9 +156,9 @@ void Plansza::update() {
|
||||
|
||||
for (auto meteorIt = getMeteors().begin(); meteorIt != getMeteors().end();) {
|
||||
bool meteorHit = false;
|
||||
for (auto rocketIt = ship.getBullets().begin(); rocketIt != ship.getBullets().end();) {
|
||||
for (auto rocketIt = ship->getBullets().begin(); rocketIt != ship->getBullets().end();) {
|
||||
if (meteorIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||
ship.getBullets().erase(rocketIt);
|
||||
ship->getBullets().erase(rocketIt);
|
||||
meteorIt = getMeteors().erase(meteorIt);
|
||||
meteorHit = true;
|
||||
break;
|
||||
@@ -173,9 +173,9 @@ void Plansza::update() {
|
||||
|
||||
for (auto meteorIt = getMeteors().begin(); meteorIt != getMeteors().end();) {
|
||||
bool meteorHit = false;
|
||||
for (auto rocketIt = ship.getRockets().begin(); rocketIt != ship.getRockets().end();) {
|
||||
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
|
||||
if (meteorIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||
ship.getRockets().erase(rocketIt);
|
||||
ship->getRockets().erase(rocketIt);
|
||||
meteorIt = getMeteors().erase(meteorIt);
|
||||
meteorHit = true;
|
||||
break;
|
||||
@@ -189,13 +189,7 @@ void Plansza::update() {
|
||||
}
|
||||
|
||||
|
||||
// Warunek przeganej
|
||||
if (gameOver) {
|
||||
ship->takeDamage();
|
||||
}
|
||||
}
|
||||
|
||||
if (!ship->isAlive()) {
|
||||
sf::RenderWindow errorWindow(sf::VideoMode(350, 200), "The end");
|
||||
sf::Font font;
|
||||
if (!font.loadFromFile("../assets/fonts/arial.ttf")) {
|
||||
@@ -662,7 +656,7 @@ void Plansza::update() {
|
||||
|
||||
|
||||
// Statystyka życia gracza (wyświetlanie)
|
||||
switch (ship.getHP()) {
|
||||
switch (ship->getHP()) {
|
||||
case 0:
|
||||
heartStats[0].setTexture(heartTextureGray);
|
||||
heartStats[1].setTexture(heartTextureGray);
|
||||
|
||||
Reference in New Issue
Block a user