This commit is contained in:
2024-12-20 19:39:18 +01:00
parent 76203a8b29
commit 0a5a26208a
2 changed files with 6 additions and 7 deletions

View File

@@ -29,7 +29,7 @@ public:
bool isAlive() const; bool isAlive() const;
void takeDamage(); void takeDamage();
void updateDirection(); void checkIfBeamShootOutOfBounds();
bool isShooting() const; bool isShooting() const;
const Beam* getBeam() const; const Beam* getBeam() const;
void setPlanszaHeight(float height, float width); void setPlanszaHeight(float height, float width);

View File

@@ -1,8 +1,8 @@
#include "../headers/Wiazkowiec.h" #include "../headers/Wiazkowiec.h"
#include "../headers/Plansza.h"
#include "../headers/RandomNumberGenerator.h"
#include <iostream> #include <iostream>
#include <random>
#include "../headers/Plansza.h"
Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture &texture) : Actor(x, y, texture), Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture &texture) : Actor(x, y, texture),
@@ -49,7 +49,6 @@ void Wiazkowiec::spawnBeam() {
break; break;
} }
// beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
beam->setVisible(true); beam->setVisible(true);
shooting = true; shooting = true;
@@ -67,7 +66,7 @@ void Wiazkowiec::shoot() {
void Wiazkowiec::setRandomDirection() { void Wiazkowiec::setRandomDirection() {
// Losowanie kierunku: 0 = Up, 1 = Down, 2 = Left, 3 = Right // Losowanie kierunku: 0 = Up, 1 = Down, 2 = Left, 3 = Right
switch (std::rand() % 4) { switch (RandomNumberGenerator::getRandomNumber(0, 3)) {
case 0: case 0:
direction = DirectionW::Up; direction = DirectionW::Up;
break; break;
@@ -85,7 +84,7 @@ void Wiazkowiec::setRandomDirection() {
} }
} }
void Wiazkowiec::updateDirection() { void Wiazkowiec::checkIfBeamShootOutOfBounds() {
auto spriteBounds = actorSprite.getGlobalBounds(); // Pobierz rozmiar i pozycję sprite'a auto spriteBounds = actorSprite.getGlobalBounds(); // Pobierz rozmiar i pozycję sprite'a
// Kontrola górnej i dolnej krawędzi // Kontrola górnej i dolnej krawędzi
@@ -140,7 +139,7 @@ void Wiazkowiec::update() {
setRandomDirection(); // Zmień kierunek po strzale setRandomDirection(); // Zmień kierunek po strzale
} }
} else { } else {
updateDirection(); checkIfBeamShootOutOfBounds();
switch (direction) { switch (direction) {
case DirectionW::Up: case DirectionW::Up: