Compare commits
4 Commits
1c0e5d0293
...
5Przeciwni
| Author | SHA1 | Date | |
|---|---|---|---|
| 87399213b3 | |||
| f1dc19e795 | |||
| 168ba2e477 | |||
| 38fd71b8e6 |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
@@ -8,6 +8,8 @@ class Beam {
|
||||
public:
|
||||
Beam(float x, float y, float width, float height, const sf::Color& color);
|
||||
|
||||
void draw(sf::RenderWindow &window);
|
||||
|
||||
void update();
|
||||
void render(sf::RenderWindow& window);
|
||||
|
||||
@@ -20,6 +22,8 @@ public:
|
||||
private:
|
||||
sf::RectangleShape beamShape;
|
||||
bool visible;
|
||||
sf::Texture beamTexture;
|
||||
sf::Sprite beamSprite;
|
||||
};
|
||||
|
||||
#endif // LOTOSTATEK_BEAM_H
|
||||
@@ -31,8 +31,11 @@ public:
|
||||
bool isAlive() const;
|
||||
void takeDamage();
|
||||
void updateDirection();
|
||||
void setPlanszaHeight(float height, float width);
|
||||
|
||||
private:
|
||||
float planszaHeight = 800.f;
|
||||
float planszaWidth = 600.f;
|
||||
sf::Clock shootClock;
|
||||
sf::Texture BombaTexture;
|
||||
float movementSpeed = 2.0f;
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
void explode(const sf::Vector2f &playerPosition, bool &playerHit);
|
||||
|
||||
private:
|
||||
bool exploding = false; // Czy kamikadze obecnie eksploduje
|
||||
bool exploding = false;
|
||||
sf::Clock explosionClock;
|
||||
sf::Clock shootClock;
|
||||
float movementSpeed = 2.0f;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
|
||||
#include <chrono>
|
||||
#include <SFML/System/Clock.hpp>
|
||||
|
||||
#include "Actor.h"
|
||||
#include "Rocket.h"
|
||||
|
||||
@@ -20,6 +22,7 @@ public:
|
||||
void moveDown() override;
|
||||
void takeDamage();
|
||||
bool isAlive() const;
|
||||
void update();
|
||||
std::vector<Rocket>& getRockets();
|
||||
private:
|
||||
std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now();
|
||||
@@ -27,6 +30,9 @@ private:
|
||||
sf::Texture rocketTexture;
|
||||
int health = 3; // Liczba punktów życia gracza
|
||||
sf::Texture bulletTexture;
|
||||
bool isImmortal = false; // flaga na immortal
|
||||
sf::Clock immortalityClock; // Zegar kontrolujący czas nieśmiertelności
|
||||
float immortalityDuration = 1.5f; // Czas trwania nieśmiertelności w sec
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -32,19 +32,22 @@ public:
|
||||
void updateDirection();
|
||||
bool isShooting() const;
|
||||
const Beam& getBeam() const;
|
||||
void setPlanszaHeight(float height, float width);
|
||||
void setMapBounds(float width, float height);
|
||||
|
||||
|
||||
private:
|
||||
float planszaHeight = 800.f;
|
||||
float planszaWidth = 600.f;
|
||||
sf::Clock shootClock;
|
||||
sf::Texture WiazkaTexture;
|
||||
float movementSpeed = 2.0f;
|
||||
bool alive = true;
|
||||
DirectionW direction = DirectionW::Down;
|
||||
Beam beam; // Wiązka
|
||||
bool shooting = false; // Czy obecnie strzela
|
||||
sf::Clock shootingClock; // Zegar kontrolujący czas strzału
|
||||
float beamDuration = 1.0f; // Czas trwania widoczności wiązki (w sekundach)
|
||||
|
||||
bool shooting = false;
|
||||
sf::Clock shootingClock;
|
||||
float beamDuration = 1.0f;
|
||||
void spawnBeam(); // Tworzy wiązkę
|
||||
};
|
||||
|
||||
|
||||
@@ -1,20 +1,40 @@
|
||||
#include "../headers/Beam.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Beam::Beam(float x, float y, float width, float height, const sf::Color& color)
|
||||
: visible(false) {
|
||||
beamShape.setPosition(x, y);
|
||||
beamShape.setSize({width, height});
|
||||
beamShape.setFillColor(color);
|
||||
|
||||
if (!beamTexture.loadFromFile("../assets/img/wiazka/wiazka.png")) {
|
||||
std::cerr << "Błąd! Nie można załadować tekstury wiazka.png" << std::endl;
|
||||
}
|
||||
beamSprite.setTexture(beamTexture);
|
||||
|
||||
if (beamTexture.getSize().x > 0 && beamTexture.getSize().y > 0) {
|
||||
float scaleX = width / beamTexture.getSize().x;
|
||||
float scaleY = height / beamTexture.getSize().y;
|
||||
beamSprite.setScale(scaleX, scaleY);
|
||||
beamSprite.setPosition(x, y);
|
||||
} else {
|
||||
std::cerr << "Błąd: Tekstura wiązki nie została poprawnie załadowana." << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Beam::draw(sf::RenderWindow& window) {
|
||||
|
||||
window.draw(beamSprite);
|
||||
|
||||
}
|
||||
|
||||
void Beam::update() {
|
||||
// Wiązka może mieć logikę do czasu, jeśli potrzebne
|
||||
}
|
||||
|
||||
void Beam::render(sf::RenderWindow& window) {
|
||||
if (visible) {
|
||||
window.draw(beamShape);
|
||||
}
|
||||
window.draw(beamSprite);
|
||||
}
|
||||
|
||||
sf::FloatRect Beam::getBounds() const {
|
||||
|
||||
@@ -7,11 +7,14 @@ Bomber::Bomber(int x, int y, const sf::Texture& texture, const sf::Texture& bull
|
||||
BombaTexture = bulletTexture;
|
||||
hp = 2; // 2 punkty życia
|
||||
firerate = 10000; // Strzela co 10
|
||||
moving_speed = 1.0f; // Prędkość
|
||||
// BombaTexture.loadFromFile("../assets/img/bullets/bomba.png");
|
||||
moving_speed = 10.0f; // Prędkość
|
||||
}
|
||||
|
||||
void Bomber::setPlanszaHeight(float height, float width) {
|
||||
planszaHeight = height;
|
||||
planszaWidth = width;
|
||||
}
|
||||
|
||||
// Losuje losowy kierunek dla Bombera
|
||||
void Bomber::setRandomDirection() {
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
@@ -47,22 +50,39 @@ void Bomber::shoot() {
|
||||
}
|
||||
|
||||
void Bomber::updateDirection() {
|
||||
// Zmieniamy kierunek przeciwnika, gdy dotrze do krawędzi
|
||||
auto spriteBounds = actorSprite.getGlobalBounds(); // Pobierz rozmiar i pozycję sprite'a
|
||||
|
||||
// Kontrola górnej i dolnej krawędzi (wysokości planszy)
|
||||
if (position.y <= 0) {
|
||||
direction = DirectionB::Down;
|
||||
} else if (position.y >= 800) {
|
||||
} else if (position.y + spriteBounds.height >= planszaHeight) {
|
||||
direction = DirectionB::Up;
|
||||
}
|
||||
|
||||
// logika dla kierunku lewo/prawo
|
||||
// Kontrola lewej i prawej krawędzi (szerokości planszy)
|
||||
if (position.x <= 0) {
|
||||
direction = DirectionB::Right;
|
||||
} else if (position.x >= 1200) {
|
||||
} else if (position.x + spriteBounds.width >= planszaWidth) {
|
||||
direction = DirectionB::Left;
|
||||
}
|
||||
}
|
||||
|
||||
void Bomber::move(float deltaX, float deltaY) {
|
||||
auto spriteBounds = actorSprite.getGlobalBounds(); // Rozmiar i pozycja sprite'a
|
||||
|
||||
// Zapobiegaj wyjściu poza poziome granice
|
||||
if (position.x + deltaX < 0) {
|
||||
deltaX = -position.x;
|
||||
} else if (position.x + spriteBounds.width + deltaX > planszaWidth) {
|
||||
deltaX = planszaWidth - (position.x + spriteBounds.width);
|
||||
}
|
||||
|
||||
// Zapobiegaj wyjściu poza pionowe granice
|
||||
if (position.y + deltaY < 0) {
|
||||
deltaY = -position.y;
|
||||
} else if (position.y + spriteBounds.height + deltaY > planszaHeight) {
|
||||
deltaY = planszaHeight - (position.y + spriteBounds.height);
|
||||
}
|
||||
actorSprite.move(deltaX, deltaY);
|
||||
position.x += static_cast<int>(deltaX);
|
||||
position.y += static_cast<int>(deltaY);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "../headers/Kamikadze.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "../headers/Bullet.h"
|
||||
#include <random>
|
||||
|
||||
#include "../headers/RandomNumberGenerator.h"
|
||||
|
||||
Kamikadze::Kamikadze(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) {
|
||||
actorSprite.setTexture(texture);
|
||||
hp = 3; // 3 punkty życia
|
||||
@@ -13,13 +13,8 @@ Kamikadze::Kamikadze(int x, int y, const sf::Texture& texture) : Actor(x, y, tex
|
||||
|
||||
void Kamikadze::shoot(){}
|
||||
|
||||
// Losuje losowy kierunek dla Bombera
|
||||
void Kamikadze::setRandomDirection() {
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<int> dist(0, 3);
|
||||
|
||||
int randomDirection = dist(gen);
|
||||
int randomDirection = RandomNumberGenerator::getRandomNumber(0,3);
|
||||
|
||||
// Zapobieganie wyjscia poza ekran
|
||||
switch (randomDirection) {
|
||||
@@ -56,31 +51,28 @@ void Kamikadze::updateDirection() {
|
||||
}
|
||||
|
||||
void Kamikadze::followPlayer(const sf::Vector2f& playerPosition) {
|
||||
// Oblicz różnicę w pozycjach
|
||||
float diffX = playerPosition.x - position.x;
|
||||
float diffY = playerPosition.y - position.y;
|
||||
|
||||
// Normalizacja wektora (skrócenie kierunku do jednostkowego)
|
||||
float magnitude = std::sqrt(diffX * diffX + diffY * diffY);
|
||||
if (magnitude != 0) {
|
||||
diffX /= magnitude;
|
||||
diffY /= magnitude;
|
||||
|
||||
// Aktualizacja pozycji Kamikadze w kierunku gracza z uwzględnieniem prędkości
|
||||
// Aktualizacja pozycji Kamikadze w kierunku gracza
|
||||
position.x += diffX * movementSpeed;
|
||||
position.y += diffY * movementSpeed;
|
||||
} else {
|
||||
// Jeśli Kamikadze jest dokładnie na pozycji gracza, zatrzymaj jego ruch
|
||||
} else { //zatrzymanie kamikadze
|
||||
movementSpeed = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void Kamikadze::explode(const sf::Vector2f& playerPosition, bool& playerHit) {
|
||||
if (!exploding) {
|
||||
// Rozpocznij eksplozję
|
||||
// Rozpocznij kamikadze
|
||||
exploding = true;
|
||||
explosionClock.restart();
|
||||
movementSpeed = 0.0f; // Zatrzymaj Kamikadze
|
||||
movementSpeed = 0.0f;
|
||||
|
||||
std::cout << "Kamikadze exploding!" << std::endl;
|
||||
std::cout << "Kamikadze position: (" << position.x << ", " << position.y << ")" << std::endl;
|
||||
@@ -121,9 +113,9 @@ void Kamikadze::moveDown() { move(0.0f, moving_speed); }
|
||||
|
||||
void Kamikadze::update(const sf::Vector2f& playerPosition) {
|
||||
if (alive && !exploding) {
|
||||
// Podążaj za graczem, dopóki Kamikadze jest żywy i nie eksploduje
|
||||
// Podążanie za graczem, dopóki Kamikadze jest żywy
|
||||
followPlayer(playerPosition);
|
||||
actorSprite.setPosition(position.x, position.y); // Aktualizuj sprite
|
||||
actorSprite.setPosition(position.x, position.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,10 +34,6 @@ Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::Render
|
||||
std::cerr << "Failed to load enemy texture!" << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
if (!WiazkaTexture.loadFromFile("../assets/img/bullets/wiazka.png")) {
|
||||
std::cerr << "Failed to load wiazka texture!" << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
if (!advancedEnemyTexture.loadFromFile("../assets/img/enemy/advanced_enemy.png")) {
|
||||
std::cerr << "Failed to load advanced enemy texture!" << std::endl;
|
||||
exit(-1);
|
||||
@@ -55,7 +51,7 @@ Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::Render
|
||||
exit(-1);
|
||||
}
|
||||
if (!WiazkowiecTexture.loadFromFile("../assets/img/enemy/wiazkowiec.png")) {
|
||||
std::cerr << "Failed to load BombaTexture!" << std::endl;
|
||||
std::cerr << "Failed to load Wiazkowiec texture!" << std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
spawnClock.restart();
|
||||
@@ -100,7 +96,8 @@ void Plansza::update() {
|
||||
}
|
||||
|
||||
// generowanie nowego meteoru
|
||||
//spawn_meteor();
|
||||
ship.update();
|
||||
spawn_meteor();
|
||||
spawn_enemy();
|
||||
spawn_advanced_enemy();
|
||||
spawn_wiazkowiec();
|
||||
@@ -257,7 +254,7 @@ void Plansza::update() {
|
||||
}
|
||||
}
|
||||
for (auto it = BEnemies.begin(); it != BEnemies.end();) {
|
||||
it->update(); // Ruch b
|
||||
it->update(); // Ruch bombera
|
||||
it->shoot(); // Strzał przeciwnika
|
||||
|
||||
window->draw(it->getSprite()); // Rysowanie na ekranie
|
||||
@@ -275,7 +272,6 @@ void Plansza::update() {
|
||||
sf::Vector2f playerPosition = ship.getSprite().getPosition(); // Aktualna pozycja gracza
|
||||
bool playerHit = false;
|
||||
|
||||
// Aktualizacja pozycji Kamikadze
|
||||
it->update(playerPosition);
|
||||
|
||||
// Wybuch, gdy Kamikadze dotknie gracza
|
||||
@@ -292,7 +288,7 @@ void Plansza::update() {
|
||||
it->explode(playerPosition, playerHit); // Eksplozja trwa
|
||||
}
|
||||
|
||||
// Usunięcie martwego Kamikadze z listy
|
||||
// Usunięcie martwego Kamikadze
|
||||
if (it->isAlive()) {
|
||||
window->draw(it->getSprite());
|
||||
++it;
|
||||
@@ -414,6 +410,19 @@ void Plansza::update() {
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& wiazkowiec : WEnemies) {
|
||||
wiazkowiec.update();
|
||||
|
||||
if (wiazkowiec.isShooting() && wiazkowiec.getBeam().isVisible()) {
|
||||
if (ship.getSprite().getGlobalBounds().intersects(wiazkowiec.getBeam().getBounds())) {
|
||||
ship.takeDamage(); // Gracz otrzymuje obrażenia
|
||||
}
|
||||
}
|
||||
|
||||
window->draw(wiazkowiec.getSprite());
|
||||
wiazkowiec.render(*window);
|
||||
}
|
||||
|
||||
// Usuwanie pocisków, które są poza ekranem srednio to dziala
|
||||
for (auto enemyIt = enemies.begin(); enemyIt != enemies.end(); ) {
|
||||
for (auto bulletIt = enemyIt->getBullets().begin(); bulletIt != enemyIt->getBullets().end();) {
|
||||
@@ -504,19 +513,27 @@ void Plansza::update() {
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& wiazkowiec : WEnemies) {
|
||||
wiazkowiec.update();
|
||||
|
||||
if (wiazkowiec.isShooting() && wiazkowiec.getBeam().isVisible()) {
|
||||
if (ship.getSprite().getGlobalBounds().intersects(wiazkowiec.getBeam().getBounds())) {
|
||||
ship.takeDamage(); // Gracz otrzymuje obrażenia
|
||||
for (auto wiazkowiecIt = WEnemies.begin(); wiazkowiecIt != WEnemies.end();) {
|
||||
bool hit = false;
|
||||
for (auto bulletIt = ship.getBullets().begin(); bulletIt != ship.getBullets().end();) {
|
||||
if (wiazkowiecIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
||||
bulletIt = ship.getBullets().erase(bulletIt);
|
||||
wiazkowiecIt->takeDamage();
|
||||
hit = true;
|
||||
break;
|
||||
} else {
|
||||
++bulletIt;
|
||||
}
|
||||
}
|
||||
|
||||
window->draw(wiazkowiec.getSprite());
|
||||
wiazkowiec.render(*window);
|
||||
if (hit && !wiazkowiecIt->isAlive()) {
|
||||
wiazkowiecIt = WEnemies.erase(wiazkowiecIt); // Usunięcie przeciwnika Wiazkowiec
|
||||
} else {
|
||||
++wiazkowiecIt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//oblsuga dla rakiety
|
||||
for (auto enemyIt = enemies.begin(); enemyIt != enemies.end();) {
|
||||
bool hit = false;
|
||||
@@ -594,6 +611,25 @@ void Plansza::update() {
|
||||
}
|
||||
}
|
||||
|
||||
for (auto wiazkowiecIt = WEnemies.begin(); wiazkowiecIt != WEnemies.end();) {
|
||||
bool hit = false;
|
||||
for (auto rocketIt = ship.getRockets().begin(); rocketIt != ship.getRockets().end();) {
|
||||
if (wiazkowiecIt->getSprite().getGlobalBounds().intersects(rocketIt->getSprite().getGlobalBounds())) {
|
||||
rocketIt = ship.getRockets().erase(rocketIt);
|
||||
wiazkowiecIt->takeDamage();
|
||||
hit = true;
|
||||
break;
|
||||
} else {
|
||||
++rocketIt;
|
||||
}
|
||||
}
|
||||
if (hit && !wiazkowiecIt->isAlive()) {
|
||||
wiazkowiecIt = WEnemies.erase(wiazkowiecIt);
|
||||
} else {
|
||||
++wiazkowiecIt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -641,9 +677,11 @@ void Plansza::spawn_advanced_enemy() {
|
||||
}
|
||||
|
||||
void Plansza::spawn_bomber() {
|
||||
if (BomberSpawnClock.getElapsedTime().asSeconds() >= 120) { // Spawn co 10 sekund
|
||||
if (BomberSpawnClock.getElapsedTime().asSeconds() >= 10) { // Spawn co 10 sekund
|
||||
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
|
||||
BEnemies.emplace_back(spawnX, -50, BomberEnemyTexture, BombaTexture);
|
||||
Bomber bomber(spawnX, -50, BomberEnemyTexture, BombaTexture);
|
||||
bomber.setPlanszaHeight(size.height, size.width); // Przekazanie wysokości i szerokości okna
|
||||
BEnemies.push_back(bomber);
|
||||
std::cout << "Spawned Bomber Enemy at X: " << spawnX << std::endl;
|
||||
BomberSpawnClock.restart();
|
||||
}
|
||||
@@ -659,9 +697,11 @@ void Plansza::spawn_kamikadze() {
|
||||
}
|
||||
|
||||
void Plansza::spawn_wiazkowiec() {
|
||||
if (WiazkowiecSpawnClock.getElapsedTime().asSeconds() >= 10) { // Spawn co 10 sekund
|
||||
if (WiazkowiecSpawnClock.getElapsedTime().asSeconds() >= 110) { // Spawn co 10 sekund
|
||||
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
|
||||
WEnemies.emplace_back(spawnX, -50, WiazkowiecTexture);
|
||||
Wiazkowiec wiazkowiec(spawnX, -50, WiazkowiecTexture);
|
||||
wiazkowiec.setPlanszaHeight(size.height, size.width); // Przekazanie wysokości i szerokosci okna
|
||||
WEnemies.push_back(wiazkowiec);
|
||||
std::cout << "Spawned Wiazkowiec Enemy at X: " << spawnX << std::endl;
|
||||
WiazkowiecSpawnClock.restart();
|
||||
}
|
||||
|
||||
@@ -34,17 +34,40 @@ void Player::alternate_shoot() {
|
||||
}
|
||||
}
|
||||
|
||||
void Player::takeDamage() {
|
||||
if (health > 0) {
|
||||
health--;
|
||||
std::cout << "Player hit! Remaining health: " << health << "\n";
|
||||
|
||||
|
||||
if (health <= 0) {
|
||||
std::cout << "Player has been destroyed!\n";
|
||||
std::cout << "You lost the game!\n";
|
||||
|
||||
void Player::update() {
|
||||
// Wyłącz nieśmiertelność po określonym czasie
|
||||
if (isImmortal && immortalityClock.getElapsedTime().asSeconds() >= immortalityDuration) {
|
||||
isImmortal = false;
|
||||
std::cout << "Immortality ended.\n";
|
||||
}
|
||||
|
||||
// Efekt migania podczas nieśmiertelności
|
||||
if (isImmortal) {
|
||||
if (static_cast<int>(immortalityClock.getElapsedTime().asMilliseconds() / 200) % 2 == 0) {
|
||||
actorSprite.setColor(sf::Color(255, 255, 255, 128)); // Półprzezroczysty
|
||||
} else {
|
||||
actorSprite.setColor(sf::Color(255, 255, 255, 255)); // Normalny
|
||||
}
|
||||
} else {
|
||||
actorSprite.setColor(sf::Color(255, 255, 255, 255)); // Normalny
|
||||
}
|
||||
}
|
||||
|
||||
void Player::takeDamage() {
|
||||
if (!isImmortal) {
|
||||
if (health > 0) {
|
||||
health--;
|
||||
std::cout << "Player hit! Remaining health: " << health << "\n";
|
||||
isImmortal = true; // Aktywuj chwilową nieśmiertelność
|
||||
immortalityClock.restart();
|
||||
|
||||
|
||||
if (health <= 0) {
|
||||
std::cout << "Player has been destroyed!\n";
|
||||
std::cout << "You lost the game!\n";
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,12 @@ Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture& texture) : Actor(x, y, t
|
||||
actorSprite.setTexture(texture);
|
||||
hp = 2; // 2 punkty życia
|
||||
firerate = 5000; // Strzela co 10
|
||||
moving_speed = 1.0f; // Prędkość
|
||||
// BombaTexture.loadFromFile("../assets/img/bullets/bomba.png");
|
||||
moving_speed = 5.0f; // Prędkość
|
||||
}
|
||||
|
||||
void Wiazkowiec::setPlanszaHeight(float height, float width) {
|
||||
planszaHeight = height;
|
||||
planszaWidth = width;
|
||||
}
|
||||
|
||||
void Wiazkowiec::spawnBeam() {
|
||||
@@ -23,16 +27,24 @@ void Wiazkowiec::spawnBeam() {
|
||||
case DirectionW::Up:
|
||||
beamHeight = position.y;
|
||||
beamY -= beamHeight;
|
||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
break;
|
||||
case DirectionW::Down:
|
||||
beamHeight = 600 - position.y;
|
||||
beamHeight = planszaHeight - position.y;
|
||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
break;
|
||||
case DirectionW::Left:
|
||||
beamWidth = position.x;
|
||||
beamHeight = 50.f;
|
||||
beamWidth = position.x;
|
||||
beamX -= beamWidth;
|
||||
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
|
||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
break;
|
||||
case DirectionW::Right:
|
||||
beamWidth = 800 - position.x;
|
||||
beamHeight = 50.f;
|
||||
beamWidth = 800 - position.x;
|
||||
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
|
||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -40,7 +52,7 @@ void Wiazkowiec::spawnBeam() {
|
||||
beam.setVisible(true);
|
||||
|
||||
shooting = true;
|
||||
shootingClock.restart(); // Reset zegara
|
||||
shootingClock.restart();
|
||||
}
|
||||
|
||||
// Strzał wiązki
|
||||
@@ -72,22 +84,41 @@ void Wiazkowiec::setRandomDirection() {
|
||||
}
|
||||
|
||||
void Wiazkowiec::updateDirection() {
|
||||
// Zmieniamy kierunek przeciwnika, gdy dotrze do krawędzi
|
||||
auto spriteBounds = actorSprite.getGlobalBounds(); // Pobierz rozmiar i pozycję sprite'a
|
||||
|
||||
// Kontrola górnej i dolnej krawędzi
|
||||
if (position.y <= 0) {
|
||||
direction = DirectionW::Down;
|
||||
} else if (position.y >= 800) {
|
||||
} else if (position.y + spriteBounds.height >= planszaHeight) {
|
||||
direction = DirectionW::Up;
|
||||
}
|
||||
|
||||
// logika dla kierunku lewo/prawo
|
||||
// Kontrola lewej i prawej krawędzi
|
||||
if (position.x <= 0) {
|
||||
direction = DirectionW::Right;
|
||||
} else if (position.x >= 1200) {
|
||||
} else if (position.x + spriteBounds.width >= planszaWidth) {
|
||||
direction = DirectionW::Left;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Wiazkowiec::move(float deltaX, float deltaY) {
|
||||
auto spriteBounds = actorSprite.getGlobalBounds(); // Rozmiar i pozycja sprite'a
|
||||
|
||||
// Zapobiegaj wyjściu poza poziome granice
|
||||
if (position.x + deltaX < 0) {
|
||||
deltaX = -position.x;
|
||||
} else if (position.x + spriteBounds.width + deltaX > planszaWidth) {
|
||||
deltaX = planszaWidth - (position.x + spriteBounds.width);
|
||||
}
|
||||
|
||||
// Zapobiegaj wyjściu poza pionowe granice
|
||||
if (position.y + deltaY < 0) {
|
||||
deltaY = -position.y;
|
||||
} else if (position.y + spriteBounds.height + deltaY > planszaHeight) {
|
||||
deltaY = planszaHeight - (position.y + spriteBounds.height);
|
||||
}
|
||||
|
||||
actorSprite.move(deltaX, deltaY);
|
||||
position.x += static_cast<int>(deltaX);
|
||||
position.y += static_cast<int>(deltaY);
|
||||
|
||||
Reference in New Issue
Block a user