8 Commits

3 changed files with 57 additions and 14 deletions

BIN
assets/img/boss/Boss.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@@ -22,6 +22,7 @@ void Boss::setPlanszaHeight(int height, int width) {
planszaWidth = width;
}
// TODO: Po mergowaniu dodać obsługę pocisku, przy pomocy nowego konstruktora Bullet
void Boss::shoot() {
if (shootClock.getElapsedTime().asMilliseconds() >= firerate) {
Bullet leftBullet(position.x - 20, position.y, bulletTexture);
@@ -42,7 +43,7 @@ void Boss::dropBomb() {
if (bombClock.getElapsedTime().asMilliseconds() >= 5000) {
Bullet Bomb(position.x, position.y, BombaTexture);
Bomb.setSpeed(0.5f);
bullets.emplace_back(std::move(Bomb)); // Można zmienić na bombę
bombs.emplace_back(std::move(Bomb)); // Można zmienić na bombę
std::cout << "Bombka lezy" << std::endl;
bombClock.restart();
}
@@ -160,9 +161,9 @@ void Boss::setRandomDirection() {
direction = static_cast<BossDirection>(randomValue);
} while (
(direction == BossDirection::Left && position.x <= 0) ||
(direction == BossDirection::Right && position.x >= planszaWidth) ||
(direction == BossDirection::Right && position.x >= 600) ||
(direction == BossDirection::Up && position.y <= 0) ||
(direction == BossDirection::Down && position.y >= planszaHeight)
(direction == BossDirection::Down && position.y >= 800)
);
if (previousDirection == direction) {
std::cerr << "Boss kept the same direction: " << static_cast<int>(direction) << std::endl;
@@ -173,18 +174,14 @@ void Boss::setRandomDirection() {
void Boss::handleBounds() {
if (position.x < 0) {
position.x = 0;
direction = BossDirection::Right;
} else if (position.x > planszaWidth - actorSprite.getGlobalBounds().width) {
position.x = planszaWidth - actorSprite.getGlobalBounds().width;
} else if (position.x > 600 - actorSprite.getGlobalBounds().width) {
direction = BossDirection::Left;
}
if (position.y < 0) {
position.y = 0;
direction = BossDirection::Down;
} else if (position.y > planszaHeight - actorSprite.getGlobalBounds().height) {
position.y = planszaHeight - actorSprite.getGlobalBounds().height;
} else if (position.y > 800 - actorSprite.getGlobalBounds().height) {
direction = BossDirection::Up;
}
}

View File

@@ -118,7 +118,7 @@ void Plansza::update() {
spawn_hearts();
spawn_power_up();
// spawn_enemy();
spawn_advanced_enemy();
// spawn_advanced_enemy();
// spawn_wiazkowiec();
// spawn_bomber();
// spawn_kamikadze();
@@ -382,10 +382,20 @@ void Plansza::update() {
}
}
// Kolizja bossa z graczem
if (ship->getSprite().getGlobalBounds().intersects(boss->getSprite().getGlobalBounds())) {
ship->takeDamage();
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
if (boss->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
boss->takeDamage();
rocketIt = ship->getRockets().erase(rocketIt);
std::cout << "Rocket hit boss! Boss HP: " << boss->getHP() << std::endl;
} else {
++rocketIt;
}
}
// Kolizja bossa z graczem
// if (ship->getSprite().getGlobalBounds().intersects(boss->getSprite().getGlobalBounds())) {
// ship->takeDamage();
// }
} else if (bossSpawned && (!boss || !boss->isAlive())) {
std::cout << "Boss defeated!" << std::endl;
delete boss;
@@ -414,12 +424,48 @@ void Plansza::update() {
}
}
if (boss->isShooting() && boss->getBeam() != nullptr) {
if (ship->getSprite().getGlobalBounds().intersects(boss->getBeam()->getSprite().getGlobalBounds())) {
ship->takeDamage(); // Gracz otrzymuje obrażenia
}
}
// Sprawdzenie kolizji pocisków gracza z bombami Bossa
for (auto bombIt = boss->getBombs().begin(); bombIt != boss->getBombs().end();) {
bool bombHit = false;
for (auto bulletIt = ship->getBullets().begin(); bulletIt != ship->getBullets().end();) {
if (bombIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
ship->getBullets().erase(bulletIt);
bombIt = boss->getBombs().erase(bombIt);
bombHit = true;
break;
} else {
++bulletIt;
}
}
if (!bombHit) {
++bombIt;
}
}
// Sprawdzenie kolizji rakiet gracza z bombami Bossa
for (auto bombIt = boss->getBombs().begin(); bombIt != boss->getBombs().end();) {
bool bombHit = false;
for (auto rocketIt = ship->getRockets().begin(); rocketIt != ship->getRockets().end();) {
if (bombIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
ship->getRockets().erase(rocketIt);
bombIt = boss->getBombs().erase(bombIt);
bombHit = true;
break;
} else {
++rocketIt;
}
}
if (!bombHit) {
++bombIt;
}
}
}
@@ -858,7 +904,7 @@ void Plansza::spawn_advanced_enemy() {
}
void Plansza::spawn_bomber() {
if (BomberSpawnClock.getElapsedTime().asSeconds() >= 30) { // Spawn co 10 sekund
if (BomberSpawnClock.getElapsedTime().asSeconds() >= 5) { // Spawn co 10 sekund
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
Bomber bomber(spawnX, -50, BomberEnemyTexture, BombaTexture);
bomber.setPlanszaHeight(size.height, size.width); // Przekazanie wysokości i szerokości okna