This commit is contained in:
2024-12-19 16:01:21 +01:00
parent 36984b859f
commit 76203a8b29
14 changed files with 58 additions and 68 deletions

View File

@@ -5,7 +5,8 @@
#include "../headers/Plansza.h"
Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture& texture) : Actor(x, y, texture), beam(new Beam(0, 0, 50.f, 50.f)) {
Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture &texture) : Actor(x, y, texture),
beam(new Beam(0, 0, 50.f, 50.f)) {
actorSprite.setTexture(texture);
hp = 2; // 2 punkty życia
firerate = 5000; // Strzela co 10
@@ -26,29 +27,29 @@ void Wiazkowiec::spawnBeam() {
switch (direction) {
case DirectionW::Up:
beamHeight = position.y;
beamY -= beamHeight;
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
break;
beamY -= beamHeight;
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
break;
case DirectionW::Down:
beamHeight = planszaHeight - position.y;
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
break;
break;
case DirectionW::Left:
beamHeight = 50.f;
beamWidth = position.x;
beamX -= beamWidth;
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
break;
beamWidth = position.x;
beamX -= beamWidth;
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
break;
case DirectionW::Right:
beamHeight = 50.f;
beamWidth = 800 - position.x;
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
break;
beamWidth = 800 - position.x;
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
break;
}
// beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
// beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
beam->setVisible(true);
shooting = true;
@@ -65,21 +66,22 @@ void Wiazkowiec::shoot() {
void Wiazkowiec::setRandomDirection() {
// Losowanie kierunku: 0 = Up, 1 = Down, 2 = Left, 3 = Right
int directionIndex = std::rand() % 4;
switch (directionIndex) {
switch (std::rand() % 4) {
case 0:
direction = DirectionW::Up;
break;
break;
case 1:
direction = DirectionW::Down;
break;
break;
case 2:
direction = DirectionW::Left;
break;
break;
case 3:
direction = DirectionW::Right;
break;
break;
default:
break;
}
}
@@ -143,19 +145,20 @@ void Wiazkowiec::update() {
switch (direction) {
case DirectionW::Up:
moveUp();
break;
break;
case DirectionW::Down:
moveDown();
break;
break;
case DirectionW::Left:
moveLeft();
break;
break;
case DirectionW::Right:
moveRight();
break;
break;
}
if (shootClock.getElapsedTime().asSeconds() >= 3.0f) { // Co 3 sekundy
if (shootClock.getElapsedTime().asSeconds() >= 3.0f) {
// Co 3 sekundy
shoot();
shootClock.restart();
}
@@ -163,7 +166,7 @@ void Wiazkowiec::update() {
}
// Ustawianie widoczności wiązki podczas renderowania
void Wiazkowiec::render(sf::RenderWindow& window) {
void Wiazkowiec::render(sf::RenderWindow &window) {
if (beam->isVisible()) {
beam->render(window);
}
@@ -184,6 +187,6 @@ bool Wiazkowiec::isShooting() const {
return shooting;
}
const Beam* Wiazkowiec::getBeam() const {
const Beam *Wiazkowiec::getBeam() const {
return beam;
}
}