From 6b45443c75b9bffa6cfcb48139965d89900d7837 Mon Sep 17 00:00:00 2001 From: Andrii Solianyk Date: Sun, 5 Jan 2025 18:20:19 +0100 Subject: [PATCH] Laser naprawiono --- headers/Beam.h | 2 ++ sources/AdvancedEnemy.cpp | 1 - sources/Beam.cpp | 5 ++++ sources/Bomber.cpp | 1 - sources/Enemy.cpp | 1 - sources/Kamikadze.cpp | 1 - sources/Plansza.cpp | 12 ++++----- sources/Wiazkowiec.cpp | 51 ++++++++++++++++++++------------------- 8 files changed, 39 insertions(+), 35 deletions(-) diff --git a/headers/Beam.h b/headers/Beam.h index 5dd5852..ce08a41 100644 --- a/headers/Beam.h +++ b/headers/Beam.h @@ -9,6 +9,8 @@ public: Beam(int x, int y, const sf::Texture &texture); sf::Sprite getSprite(); + + void setRotation(float angle); private: sf::Sprite beamSprite; }; diff --git a/sources/AdvancedEnemy.cpp b/sources/AdvancedEnemy.cpp index 516454b..746189a 100644 --- a/sources/AdvancedEnemy.cpp +++ b/sources/AdvancedEnemy.cpp @@ -3,7 +3,6 @@ #include "../headers/Plansza.h" AdvancedEnemy::AdvancedEnemy(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, texture) { - actorSprite.setTexture(texture); enemyBulletTexture = bulletTexture; hp = 2; // 2 punkty życia firerate = 2000; // Strzela co 2 diff --git a/sources/Beam.cpp b/sources/Beam.cpp index f14de49..3ccf6d7 100644 --- a/sources/Beam.cpp +++ b/sources/Beam.cpp @@ -3,6 +3,7 @@ #include Beam::Beam(int x, int y, const sf::Texture& texture) { + beamSprite.setOrigin(beamSprite.getLocalBounds().width/2, beamSprite.getLocalBounds().height/2); if (texture.getSize().x > 0 && texture.getSize().y > 0) { beamSprite.setPosition(x, y); } else { @@ -15,3 +16,7 @@ sf::Sprite Beam::getSprite() { return beamSprite; } +void Beam::setRotation(float angle) { + beamSprite.setRotation(angle); +} + diff --git a/sources/Bomber.cpp b/sources/Bomber.cpp index 9d29b9a..d56bd99 100644 --- a/sources/Bomber.cpp +++ b/sources/Bomber.cpp @@ -4,7 +4,6 @@ #include Bomber::Bomber(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, texture) { - actorSprite.setTexture(texture); BombaTexture = bulletTexture; hp = 2; // 2 punkty życia firerate = 10000; // Strzela co 10 diff --git a/sources/Enemy.cpp b/sources/Enemy.cpp index 484fba0..731281a 100644 --- a/sources/Enemy.cpp +++ b/sources/Enemy.cpp @@ -3,7 +3,6 @@ #include "../headers/Plansza.h" Enemy::Enemy(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) { - actorSprite.setTexture(texture); hp = 1; // Przeciwnik ma 1 punkt życia firerate = 2000; // Strzela co 2 moving_speed = 2.0f; // Prędkość diff --git a/sources/Kamikadze.cpp b/sources/Kamikadze.cpp index f78833a..f2fd0c2 100644 --- a/sources/Kamikadze.cpp +++ b/sources/Kamikadze.cpp @@ -7,7 +7,6 @@ Kamikadze::Kamikadze(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) { - actorSprite.setTexture(texture); hp = 3; // 3 punkty życia moving_speed = 2.0f; // Prędkość } diff --git a/sources/Plansza.cpp b/sources/Plansza.cpp index 1a3b7fd..0e9c294 100644 --- a/sources/Plansza.cpp +++ b/sources/Plansza.cpp @@ -111,13 +111,13 @@ void Plansza::update() { ship->update(); // migotanie statku update_score(); // naliczanie punktów // Sprawnowanie wszystkich rodzajów wrogów -// spawn_meteor(); -// spawn_hearts(); -// spawn_enemy(); -// spawn_advanced_enemy(); + // spawn_meteor(); + // spawn_hearts(); + // spawn_enemy(); + // spawn_advanced_enemy(); spawn_wiazkowiec(); -// spawn_bomber(); -// spawn_kamikadze(); + // spawn_bomber(); + // spawn_kamikadze(); // utrzymanie meteorów i pocisków w ruchu for (auto &meteor: meteors) { diff --git a/sources/Wiazkowiec.cpp b/sources/Wiazkowiec.cpp index 407cc1b..f73de42 100644 --- a/sources/Wiazkowiec.cpp +++ b/sources/Wiazkowiec.cpp @@ -9,7 +9,6 @@ Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture &texture, sf::RenderWindo beam(nullptr) { window_ptr = window; - actorSprite.setTexture(texture); try { beamTexture.loadFromFile("../assets/img/wiazka/laser.png"); @@ -34,19 +33,22 @@ void Wiazkowiec::spawnBeam() { switch (direction) { case DirectionW::Up: { - beam = new Beam(beamX, beamY - beamTexture.getSize().y, beamTexture); + beam = new Beam(beamX, beamY, beamTexture); + beam->setRotation(180); break; } case DirectionW::Down: { - beam = new Beam(beamX, beamY + actorSprite.getGlobalBounds().height, beamTexture); + beam = new Beam(beamX, beamY, beamTexture); break; } case DirectionW::Left: { - beam = new Beam(beamX - beamTexture.getSize().x, beamY, beamTexture); + beam = new Beam(beamX, beamY, beamTexture); + beam->setRotation(90); break; } case DirectionW::Right: { - beam = new Beam(beamX + actorSprite.getGlobalBounds().width, beamY, beamTexture); + beam = new Beam(beamX, beamY, beamTexture); + beam->setRotation(270); break; } default: @@ -61,27 +63,26 @@ void Wiazkowiec::spawnBeam() { void Wiazkowiec::shoot() { if (!shooting) { spawnBeam(); - std::cout << "Wiazkowiec shot a beam!" << std::endl; - switch (direction) { - case DirectionW::Up: { - std::cout << "Direction is up" << std::endl; - break; - } - case DirectionW::Down: { - std::cout << "Direction is down" << std::endl; - break; - } - case DirectionW::Left: { - std::cout << "Direction is left" << std::endl; - break; - } - case DirectionW::Right: { - std::cout << "Direction is right" << std::endl; - break; - } - default: - break; + } + switch (direction) { + case DirectionW::Up: { + std::cout << "Direction is up" << std::endl; + break; } + case DirectionW::Down: { + std::cout << "Direction is down" << std::endl; + break; + } + case DirectionW::Left: { + std::cout << "Direction is left" << std::endl; + break; + } + case DirectionW::Right: { + std::cout << "Direction is right" << std::endl; + break; + } + default: + break; } }