Cos usprawnione i nasrane
This commit is contained in:
@@ -1,21 +1,48 @@
|
||||
#include "../headers/Bomber.h"
|
||||
#include "../headers/Bullet.h"
|
||||
#include <random>
|
||||
|
||||
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 = 2000; // Strzela co 2
|
||||
moving_speed = 2.0f; // Prędkość
|
||||
BombaTexture.loadFromFile("../assets/img/bullets/bomba.png");
|
||||
firerate = 10000; // Strzela co 10
|
||||
moving_speed = 1.0f; // Prędkość
|
||||
// BombaTexture.loadFromFile("../assets/img/bullets/bomba.png");
|
||||
}
|
||||
|
||||
// Losuje losowy kierunek dla Bombera
|
||||
void Bomber::setRandomDirection() {
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<int> dist(0, 3);
|
||||
|
||||
int randomDirection = dist(gen);
|
||||
|
||||
// Zapobieganie wyjscia poza ekran
|
||||
switch (randomDirection) {
|
||||
case 0:
|
||||
if (position.y > 0) direction = DirectionB::Up;
|
||||
break;
|
||||
case 1:
|
||||
if (position.y < 800) direction = DirectionB::Down;
|
||||
break;
|
||||
case 2:
|
||||
if (position.x > 0) direction = DirectionB::Left;
|
||||
break;
|
||||
case 3:
|
||||
if (position.x < 1200) direction = DirectionB::Right;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Bomber::shoot() {
|
||||
if (shootClock.getElapsedTime().asMilliseconds() >= firerate) {
|
||||
Bullet Bbullet(position.x, position.y + actorSprite.getGlobalBounds().height / 2, BombaTexture);
|
||||
Bbullet.setSpeed(0.5f); // Prędkość w dół
|
||||
Bbullet.setSpeed(0.1f); // Prędkość w dół
|
||||
bullets.emplace_back(std::move(Bbullet));
|
||||
shootClock.restart();
|
||||
setRandomDirection();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user