Kolizja wiazki dodana
This commit is contained in:
@@ -19,6 +19,8 @@ public:
|
|||||||
Boss(int x, int y, const sf::Texture &bossTexture, const sf::Texture &bulletTexture, sf::Texture BombaTexture,
|
Boss(int x, int y, const sf::Texture &bossTexture, const sf::Texture &bulletTexture, sf::Texture BombaTexture,
|
||||||
sf::RenderWindow *window);
|
sf::RenderWindow *window);
|
||||||
|
|
||||||
|
void setPlanszaHeight(int height, int width);
|
||||||
|
|
||||||
void moveLeft() override;
|
void moveLeft() override;
|
||||||
void moveRight() override;
|
void moveRight() override;
|
||||||
void moveUp() override;
|
void moveUp() override;
|
||||||
@@ -35,9 +37,11 @@ public:
|
|||||||
bool isAlive() const;
|
bool isAlive() const;
|
||||||
std::vector<Bullet>& getBullets() { return bullets; }
|
std::vector<Bullet>& getBullets() { return bullets; }
|
||||||
std::vector<Bullet>& getBombs() { return bombs; }
|
std::vector<Bullet>& getBombs() { return bombs; }
|
||||||
|
bool isShooting() const { return laserBeam != nullptr; }
|
||||||
|
Beam* getBeam() const { return laserBeam; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float movementSpeed = 1.5f;
|
float movementSpeed = 5.5f;
|
||||||
BossDirection direction = BossDirection::Down;
|
BossDirection direction = BossDirection::Down;
|
||||||
|
|
||||||
sf::Clock shootClock;
|
sf::Clock shootClock;
|
||||||
@@ -56,6 +60,11 @@ private:
|
|||||||
std::vector<Bullet> bullets;
|
std::vector<Bullet> bullets;
|
||||||
std::vector<Bullet> bombs;
|
std::vector<Bullet> bombs;
|
||||||
|
|
||||||
|
int planszaHeight = 800;
|
||||||
|
int planszaWidth = 600;
|
||||||
|
|
||||||
|
bool isStationary = false;
|
||||||
|
|
||||||
void setRandomDirection();
|
void setRandomDirection();
|
||||||
void handleBounds();
|
void handleBounds();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ public:
|
|||||||
void spawn_bomber();
|
void spawn_bomber();
|
||||||
void spawn_kamikadze();
|
void spawn_kamikadze();
|
||||||
~Plansza() {
|
~Plansza() {
|
||||||
delete ship; // usuwanie wskaźnika ship
|
delete ship;
|
||||||
delete boss; // Usuwanie wskaźnika bossa
|
delete boss;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ships selectedShip;
|
static ships selectedShip;
|
||||||
@@ -115,6 +115,7 @@ private:
|
|||||||
sf::Clock bossSpawnClock; // Zegar do spawnowania bossa
|
sf::Clock bossSpawnClock; // Zegar do spawnowania bossa
|
||||||
bool bossSpawned = false; // Flaga informująca, czy boss został już zespawnowany
|
bool bossSpawned = false; // Flaga informująca, czy boss został już zespawnowany
|
||||||
bool gameOver = false;
|
bool gameOver = false;
|
||||||
|
unsigned int nextBossScoreThreshold = 1; // Próg punktowy dla spawnu bossa
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //PLANSZA_H
|
#endif //PLANSZA_H
|
||||||
|
|||||||
@@ -13,9 +13,15 @@ Boss::Boss(int x, int y, const sf::Texture& bossTexture, const sf::Texture& bull
|
|||||||
}
|
}
|
||||||
hp = 100;
|
hp = 100;
|
||||||
firerate = 2000;
|
firerate = 2000;
|
||||||
|
movementSpeed = 2.0f;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Boss::setPlanszaHeight(int height, int width) {
|
||||||
|
planszaHeight = height;
|
||||||
|
planszaWidth = width;
|
||||||
|
}
|
||||||
|
|
||||||
void Boss::shoot() {
|
void Boss::shoot() {
|
||||||
if (shootClock.getElapsedTime().asMilliseconds() >= firerate) {
|
if (shootClock.getElapsedTime().asMilliseconds() >= firerate) {
|
||||||
Bullet leftBullet(position.x - 20, position.y, bulletTexture);
|
Bullet leftBullet(position.x - 20, position.y, bulletTexture);
|
||||||
@@ -35,7 +41,7 @@ void Boss::shoot() {
|
|||||||
void Boss::dropBomb() {
|
void Boss::dropBomb() {
|
||||||
if (bombClock.getElapsedTime().asMilliseconds() >= 5000) {
|
if (bombClock.getElapsedTime().asMilliseconds() >= 5000) {
|
||||||
Bullet Bomb(position.x, position.y, BombaTexture);
|
Bullet Bomb(position.x, position.y, BombaTexture);
|
||||||
Bomb.setSpeed(0.1f);
|
Bomb.setSpeed(0.5f);
|
||||||
bullets.emplace_back(std::move(Bomb)); // Można zmienić na bombę
|
bullets.emplace_back(std::move(Bomb)); // Można zmienić na bombę
|
||||||
std::cout << "Bombka lezy" << std::endl;
|
std::cout << "Bombka lezy" << std::endl;
|
||||||
bombClock.restart();
|
bombClock.restart();
|
||||||
@@ -47,6 +53,7 @@ void Boss::shootLaser() {
|
|||||||
laserBeam = new Beam(position.x, position.y, beamTexture);
|
laserBeam = new Beam(position.x, position.y, beamTexture);
|
||||||
beamDurationClock.restart();
|
beamDurationClock.restart();
|
||||||
laserClock.restart();
|
laserClock.restart();
|
||||||
|
isStationary = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (laserBeam) {
|
if (laserBeam) {
|
||||||
@@ -56,12 +63,16 @@ void Boss::shootLaser() {
|
|||||||
if (beamDurationClock.getElapsedTime().asSeconds() >= beamDuration) {
|
if (beamDurationClock.getElapsedTime().asSeconds() >= beamDuration) {
|
||||||
delete laserBeam;
|
delete laserBeam;
|
||||||
laserBeam = nullptr;
|
laserBeam = nullptr;
|
||||||
|
isStationary = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Boss::move(float deltaX, float deltaY) {
|
void Boss::move(float deltaX, float deltaY) {
|
||||||
|
if (deltaX == 0 && deltaY == 0) {
|
||||||
|
std::cerr << "Boss stopped: deltaX and deltaY are both 0" << std::endl;
|
||||||
|
}
|
||||||
actorSprite.move(deltaX, deltaY);
|
actorSprite.move(deltaX, deltaY);
|
||||||
position.x += static_cast<int>(deltaX);
|
position.x += static_cast<int>(deltaX);
|
||||||
position.y += static_cast<int>(deltaY);
|
position.y += static_cast<int>(deltaY);
|
||||||
@@ -69,16 +80,21 @@ void Boss::move(float deltaX, float deltaY) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Boss::update() {
|
void Boss::update() {
|
||||||
if (directionClock.getElapsedTime().asSeconds() >= 3.0f) {
|
std::cout << "Current movementSpeed: " << movementSpeed << std::endl;
|
||||||
setRandomDirection();
|
std::cout << "Boss position: (" << position.x << ", " << position.y << "), Direction: " << static_cast<int>(direction) << std::endl;
|
||||||
directionClock.restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (direction) {
|
if (!isStationary) {
|
||||||
case BossDirection::Up: move(0, -movementSpeed); break;
|
if (directionClock.getElapsedTime().asSeconds() >= 3.0f) {
|
||||||
case BossDirection::Down: move(0, movementSpeed); break;
|
setRandomDirection();
|
||||||
case BossDirection::Left: move(-movementSpeed, 0); break;
|
directionClock.restart();
|
||||||
case BossDirection::Right: move(movementSpeed, 0); break;
|
}
|
||||||
|
|
||||||
|
switch (direction) {
|
||||||
|
case BossDirection::Up: moveUp(); break;
|
||||||
|
case BossDirection::Down: moveDown(); break;
|
||||||
|
case BossDirection::Left: moveLeft(); break;
|
||||||
|
case BossDirection::Right: moveRight(); break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shoot();
|
shoot();
|
||||||
@@ -125,9 +141,11 @@ void Boss::moveDown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Boss::takeDamage() {
|
void Boss::takeDamage() {
|
||||||
if (--hp <= 0) {
|
if (--hp <= 0) {
|
||||||
hp = 0;
|
hp = 0;
|
||||||
|
std::cout << "HP bossa" << hp << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,14 +154,38 @@ bool Boss::isAlive() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Boss::setRandomDirection() {
|
void Boss::setRandomDirection() {
|
||||||
int randomValue = RandomNumberGenerator::getRandomNumber(0, 3);
|
BossDirection previousDirection = direction;
|
||||||
direction = static_cast<BossDirection>(randomValue);
|
do {
|
||||||
|
int randomValue = RandomNumberGenerator::getRandomNumber(0, 3);
|
||||||
|
direction = static_cast<BossDirection>(randomValue);
|
||||||
|
} while (
|
||||||
|
(direction == BossDirection::Left && position.x <= 0) ||
|
||||||
|
(direction == BossDirection::Right && position.x >= planszaWidth) ||
|
||||||
|
(direction == BossDirection::Up && position.y <= 0) ||
|
||||||
|
(direction == BossDirection::Down && position.y >= planszaHeight)
|
||||||
|
);
|
||||||
|
if (previousDirection == direction) {
|
||||||
|
std::cerr << "Boss kept the same direction: " << static_cast<int>(direction) << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Boss::handleBounds() {
|
void Boss::handleBounds() {
|
||||||
if (position.x <= 0) direction = BossDirection::Right;
|
if (position.x < 0) {
|
||||||
if (position.x >= 300) direction = BossDirection::Left;
|
position.x = 0;
|
||||||
if (position.y <= 0) direction = BossDirection::Down;
|
direction = BossDirection::Right;
|
||||||
if (position.y >= 300) direction = BossDirection::Up;
|
} else if (position.x > planszaWidth - actorSprite.getGlobalBounds().width) {
|
||||||
|
position.x = planszaWidth - 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;
|
||||||
|
direction = BossDirection::Up;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ void Plansza::update() {
|
|||||||
spawn_hearts();
|
spawn_hearts();
|
||||||
spawn_power_up();
|
spawn_power_up();
|
||||||
// spawn_enemy();
|
// spawn_enemy();
|
||||||
// spawn_advanced_enemy();
|
spawn_advanced_enemy();
|
||||||
// spawn_wiazkowiec();
|
// spawn_wiazkowiec();
|
||||||
// spawn_bomber();
|
// spawn_bomber();
|
||||||
// spawn_kamikadze();
|
// spawn_kamikadze();
|
||||||
@@ -422,6 +422,12 @@ void Plansza::update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (boss->isShooting() && boss->getBeam() != nullptr) {
|
||||||
|
if (ship->getSprite().getGlobalBounds().intersects(boss->getBeam()->getSprite().getGlobalBounds())) {
|
||||||
|
ship->takeDamage(); // Gracz otrzymuje obrażenia
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -851,7 +857,7 @@ void Plansza::spawn_enemy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Plansza::spawn_advanced_enemy() {
|
void Plansza::spawn_advanced_enemy() {
|
||||||
if (AenemySpawnClock.getElapsedTime().asSeconds() >= 20) { // Spawn co 10 sekund
|
if (AenemySpawnClock.getElapsedTime().asSeconds() >= 8) { // Spawn co 10 sekund
|
||||||
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
|
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
|
||||||
AEnemies.emplace_back(spawnX, -50, advancedEnemyTexture, enemyBulletTexture);
|
AEnemies.emplace_back(spawnX, -50, advancedEnemyTexture, enemyBulletTexture);
|
||||||
std::cout << "Spawned Advanced Enemy at X: " << spawnX << std::endl;
|
std::cout << "Spawned Advanced Enemy at X: " << spawnX << std::endl;
|
||||||
@@ -893,10 +899,12 @@ void Plansza::spawn_wiazkowiec() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Plansza::spawn_boss() {
|
void Plansza::spawn_boss() {
|
||||||
if (!bossSpawned && bossSpawnClock.getElapsedTime().asSeconds() >= 3) { // Spawn po 60 sekundach
|
if (!bossSpawned && score >= nextBossScoreThreshold) { // Spawn po 60 sekundach
|
||||||
boss = new Boss(size.width / 2, -100, BossTexture, enemyBulletTexture, BombaTexture, window);
|
boss = new Boss(size.width / 2, -100, BossTexture, enemyBulletTexture, BombaTexture, window);
|
||||||
|
boss->setPlanszaHeight(size.width, size.height);
|
||||||
bossSpawned = true;
|
bossSpawned = true;
|
||||||
std::cout << "Boss spawned!" << std::endl;
|
nextBossScoreThreshold += 1000;
|
||||||
|
std::cout << "Boss spawned at score: " << score << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user