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:
|
public:
|
||||||
Beam(float x, float y, float width, float height, const sf::Color& color);
|
Beam(float x, float y, float width, float height, const sf::Color& color);
|
||||||
|
|
||||||
|
void draw(sf::RenderWindow &window);
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
void render(sf::RenderWindow& window);
|
void render(sf::RenderWindow& window);
|
||||||
|
|
||||||
@@ -20,6 +22,8 @@ public:
|
|||||||
private:
|
private:
|
||||||
sf::RectangleShape beamShape;
|
sf::RectangleShape beamShape;
|
||||||
bool visible;
|
bool visible;
|
||||||
|
sf::Texture beamTexture;
|
||||||
|
sf::Sprite beamSprite;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOTOSTATEK_BEAM_H
|
#endif // LOTOSTATEK_BEAM_H
|
||||||
@@ -31,8 +31,11 @@ public:
|
|||||||
bool isAlive() const;
|
bool isAlive() const;
|
||||||
void takeDamage();
|
void takeDamage();
|
||||||
void updateDirection();
|
void updateDirection();
|
||||||
|
void setPlanszaHeight(float height, float width);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
float planszaHeight = 800.f;
|
||||||
|
float planszaWidth = 600.f;
|
||||||
sf::Clock shootClock;
|
sf::Clock shootClock;
|
||||||
sf::Texture BombaTexture;
|
sf::Texture BombaTexture;
|
||||||
float movementSpeed = 2.0f;
|
float movementSpeed = 2.0f;
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public:
|
|||||||
void explode(const sf::Vector2f &playerPosition, bool &playerHit);
|
void explode(const sf::Vector2f &playerPosition, bool &playerHit);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool exploding = false; // Czy kamikadze obecnie eksploduje
|
bool exploding = false;
|
||||||
sf::Clock explosionClock;
|
sf::Clock explosionClock;
|
||||||
sf::Clock shootClock;
|
sf::Clock shootClock;
|
||||||
float movementSpeed = 2.0f;
|
float movementSpeed = 2.0f;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <SFML/System/Clock.hpp>
|
||||||
|
|
||||||
#include "Actor.h"
|
#include "Actor.h"
|
||||||
#include "Rocket.h"
|
#include "Rocket.h"
|
||||||
|
|
||||||
@@ -20,6 +22,7 @@ public:
|
|||||||
void moveDown() override;
|
void moveDown() override;
|
||||||
void takeDamage();
|
void takeDamage();
|
||||||
bool isAlive() const;
|
bool isAlive() const;
|
||||||
|
void update();
|
||||||
std::vector<Rocket>& getRockets();
|
std::vector<Rocket>& getRockets();
|
||||||
private:
|
private:
|
||||||
std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now();
|
std::chrono::steady_clock::time_point lastShotTime = std::chrono::steady_clock::now();
|
||||||
@@ -27,6 +30,9 @@ private:
|
|||||||
sf::Texture rocketTexture;
|
sf::Texture rocketTexture;
|
||||||
int health = 3; // Liczba punktów życia gracza
|
int health = 3; // Liczba punktów życia gracza
|
||||||
sf::Texture bulletTexture;
|
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();
|
void updateDirection();
|
||||||
bool isShooting() const;
|
bool isShooting() const;
|
||||||
const Beam& getBeam() const;
|
const Beam& getBeam() const;
|
||||||
|
void setPlanszaHeight(float height, float width);
|
||||||
|
void setMapBounds(float width, float height);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
float planszaHeight = 800.f;
|
||||||
|
float planszaWidth = 600.f;
|
||||||
sf::Clock shootClock;
|
sf::Clock shootClock;
|
||||||
sf::Texture WiazkaTexture;
|
sf::Texture WiazkaTexture;
|
||||||
float movementSpeed = 2.0f;
|
float movementSpeed = 2.0f;
|
||||||
bool alive = true;
|
bool alive = true;
|
||||||
DirectionW direction = DirectionW::Down;
|
DirectionW direction = DirectionW::Down;
|
||||||
Beam beam; // Wiązka
|
Beam beam; // Wiązka
|
||||||
bool shooting = false; // Czy obecnie strzela
|
bool shooting = false;
|
||||||
sf::Clock shootingClock; // Zegar kontrolujący czas strzału
|
sf::Clock shootingClock;
|
||||||
float beamDuration = 1.0f; // Czas trwania widoczności wiązki (w sekundach)
|
float beamDuration = 1.0f;
|
||||||
|
|
||||||
void spawnBeam(); // Tworzy wiązkę
|
void spawnBeam(); // Tworzy wiązkę
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,40 @@
|
|||||||
#include "../headers/Beam.h"
|
#include "../headers/Beam.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
Beam::Beam(float x, float y, float width, float height, const sf::Color& color)
|
Beam::Beam(float x, float y, float width, float height, const sf::Color& color)
|
||||||
: visible(false) {
|
: visible(false) {
|
||||||
beamShape.setPosition(x, y);
|
beamShape.setPosition(x, y);
|
||||||
beamShape.setSize({width, height});
|
beamShape.setSize({width, height});
|
||||||
beamShape.setFillColor(color);
|
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() {
|
void Beam::update() {
|
||||||
// Wiązka może mieć logikę do czasu, jeśli potrzebne
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Beam::render(sf::RenderWindow& window) {
|
void Beam::render(sf::RenderWindow& window) {
|
||||||
if (visible) {
|
window.draw(beamSprite);
|
||||||
window.draw(beamShape);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::FloatRect Beam::getBounds() const {
|
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;
|
BombaTexture = bulletTexture;
|
||||||
hp = 2; // 2 punkty życia
|
hp = 2; // 2 punkty życia
|
||||||
firerate = 10000; // Strzela co 10
|
firerate = 10000; // Strzela co 10
|
||||||
moving_speed = 1.0f; // Prędkość
|
moving_speed = 10.0f; // Prędkość
|
||||||
// BombaTexture.loadFromFile("../assets/img/bullets/bomba.png");
|
}
|
||||||
|
|
||||||
|
void Bomber::setPlanszaHeight(float height, float width) {
|
||||||
|
planszaHeight = height;
|
||||||
|
planszaWidth = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Losuje losowy kierunek dla Bombera
|
|
||||||
void Bomber::setRandomDirection() {
|
void Bomber::setRandomDirection() {
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
std::mt19937 gen(rd());
|
std::mt19937 gen(rd());
|
||||||
@@ -47,22 +50,39 @@ void Bomber::shoot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Bomber::updateDirection() {
|
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) {
|
if (position.y <= 0) {
|
||||||
direction = DirectionB::Down;
|
direction = DirectionB::Down;
|
||||||
} else if (position.y >= 800) {
|
} else if (position.y + spriteBounds.height >= planszaHeight) {
|
||||||
direction = DirectionB::Up;
|
direction = DirectionB::Up;
|
||||||
}
|
}
|
||||||
|
|
||||||
// logika dla kierunku lewo/prawo
|
// Kontrola lewej i prawej krawędzi (szerokości planszy)
|
||||||
if (position.x <= 0) {
|
if (position.x <= 0) {
|
||||||
direction = DirectionB::Right;
|
direction = DirectionB::Right;
|
||||||
} else if (position.x >= 1200) {
|
} else if (position.x + spriteBounds.width >= planszaWidth) {
|
||||||
direction = DirectionB::Left;
|
direction = DirectionB::Left;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bomber::move(float deltaX, float deltaY) {
|
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);
|
actorSprite.move(deltaX, deltaY);
|
||||||
position.x += static_cast<int>(deltaX);
|
position.x += static_cast<int>(deltaX);
|
||||||
position.y += static_cast<int>(deltaY);
|
position.y += static_cast<int>(deltaY);
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "../headers/Kamikadze.h"
|
#include "../headers/Kamikadze.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "../headers/Bullet.h"
|
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
|
#include "../headers/RandomNumberGenerator.h"
|
||||||
|
|
||||||
Kamikadze::Kamikadze(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) {
|
Kamikadze::Kamikadze(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) {
|
||||||
actorSprite.setTexture(texture);
|
actorSprite.setTexture(texture);
|
||||||
hp = 3; // 3 punkty życia
|
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(){}
|
void Kamikadze::shoot(){}
|
||||||
|
|
||||||
// Losuje losowy kierunek dla Bombera
|
|
||||||
void Kamikadze::setRandomDirection() {
|
void Kamikadze::setRandomDirection() {
|
||||||
std::random_device rd;
|
int randomDirection = RandomNumberGenerator::getRandomNumber(0,3);
|
||||||
std::mt19937 gen(rd());
|
|
||||||
std::uniform_int_distribution<int> dist(0, 3);
|
|
||||||
|
|
||||||
int randomDirection = dist(gen);
|
|
||||||
|
|
||||||
// Zapobieganie wyjscia poza ekran
|
// Zapobieganie wyjscia poza ekran
|
||||||
switch (randomDirection) {
|
switch (randomDirection) {
|
||||||
@@ -56,31 +51,28 @@ void Kamikadze::updateDirection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Kamikadze::followPlayer(const sf::Vector2f& playerPosition) {
|
void Kamikadze::followPlayer(const sf::Vector2f& playerPosition) {
|
||||||
// Oblicz różnicę w pozycjach
|
|
||||||
float diffX = playerPosition.x - position.x;
|
float diffX = playerPosition.x - position.x;
|
||||||
float diffY = playerPosition.y - position.y;
|
float diffY = playerPosition.y - position.y;
|
||||||
|
|
||||||
// Normalizacja wektora (skrócenie kierunku do jednostkowego)
|
|
||||||
float magnitude = std::sqrt(diffX * diffX + diffY * diffY);
|
float magnitude = std::sqrt(diffX * diffX + diffY * diffY);
|
||||||
if (magnitude != 0) {
|
if (magnitude != 0) {
|
||||||
diffX /= magnitude;
|
diffX /= magnitude;
|
||||||
diffY /= 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.x += diffX * movementSpeed;
|
||||||
position.y += diffY * movementSpeed;
|
position.y += diffY * movementSpeed;
|
||||||
} else {
|
} else { //zatrzymanie kamikadze
|
||||||
// Jeśli Kamikadze jest dokładnie na pozycji gracza, zatrzymaj jego ruch
|
|
||||||
movementSpeed = 0.0f;
|
movementSpeed = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Kamikadze::explode(const sf::Vector2f& playerPosition, bool& playerHit) {
|
void Kamikadze::explode(const sf::Vector2f& playerPosition, bool& playerHit) {
|
||||||
if (!exploding) {
|
if (!exploding) {
|
||||||
// Rozpocznij eksplozję
|
// Rozpocznij kamikadze
|
||||||
exploding = true;
|
exploding = true;
|
||||||
explosionClock.restart();
|
explosionClock.restart();
|
||||||
movementSpeed = 0.0f; // Zatrzymaj Kamikadze
|
movementSpeed = 0.0f;
|
||||||
|
|
||||||
std::cout << "Kamikadze exploding!" << std::endl;
|
std::cout << "Kamikadze exploding!" << std::endl;
|
||||||
std::cout << "Kamikadze position: (" << position.x << ", " << position.y << ")" << 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) {
|
void Kamikadze::update(const sf::Vector2f& playerPosition) {
|
||||||
if (alive && !exploding) {
|
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);
|
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;
|
std::cerr << "Failed to load enemy texture!" << std::endl;
|
||||||
exit(-1);
|
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")) {
|
if (!advancedEnemyTexture.loadFromFile("../assets/img/enemy/advanced_enemy.png")) {
|
||||||
std::cerr << "Failed to load advanced enemy texture!" << std::endl;
|
std::cerr << "Failed to load advanced enemy texture!" << std::endl;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
@@ -55,7 +51,7 @@ Plansza::Plansza(unsigned int windowHeight, unsigned int windowWidth, sf::Render
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
if (!WiazkowiecTexture.loadFromFile("../assets/img/enemy/wiazkowiec.png")) {
|
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);
|
exit(-1);
|
||||||
}
|
}
|
||||||
spawnClock.restart();
|
spawnClock.restart();
|
||||||
@@ -100,7 +96,8 @@ void Plansza::update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generowanie nowego meteoru
|
// generowanie nowego meteoru
|
||||||
//spawn_meteor();
|
ship.update();
|
||||||
|
spawn_meteor();
|
||||||
spawn_enemy();
|
spawn_enemy();
|
||||||
spawn_advanced_enemy();
|
spawn_advanced_enemy();
|
||||||
spawn_wiazkowiec();
|
spawn_wiazkowiec();
|
||||||
@@ -257,7 +254,7 @@ void Plansza::update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto it = BEnemies.begin(); it != BEnemies.end();) {
|
for (auto it = BEnemies.begin(); it != BEnemies.end();) {
|
||||||
it->update(); // Ruch b
|
it->update(); // Ruch bombera
|
||||||
it->shoot(); // Strzał przeciwnika
|
it->shoot(); // Strzał przeciwnika
|
||||||
|
|
||||||
window->draw(it->getSprite()); // Rysowanie na ekranie
|
window->draw(it->getSprite()); // Rysowanie na ekranie
|
||||||
@@ -275,7 +272,6 @@ void Plansza::update() {
|
|||||||
sf::Vector2f playerPosition = ship.getSprite().getPosition(); // Aktualna pozycja gracza
|
sf::Vector2f playerPosition = ship.getSprite().getPosition(); // Aktualna pozycja gracza
|
||||||
bool playerHit = false;
|
bool playerHit = false;
|
||||||
|
|
||||||
// Aktualizacja pozycji Kamikadze
|
|
||||||
it->update(playerPosition);
|
it->update(playerPosition);
|
||||||
|
|
||||||
// Wybuch, gdy Kamikadze dotknie gracza
|
// Wybuch, gdy Kamikadze dotknie gracza
|
||||||
@@ -292,7 +288,7 @@ void Plansza::update() {
|
|||||||
it->explode(playerPosition, playerHit); // Eksplozja trwa
|
it->explode(playerPosition, playerHit); // Eksplozja trwa
|
||||||
}
|
}
|
||||||
|
|
||||||
// Usunięcie martwego Kamikadze z listy
|
// Usunięcie martwego Kamikadze
|
||||||
if (it->isAlive()) {
|
if (it->isAlive()) {
|
||||||
window->draw(it->getSprite());
|
window->draw(it->getSprite());
|
||||||
++it;
|
++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
|
// Usuwanie pocisków, które są poza ekranem srednio to dziala
|
||||||
for (auto enemyIt = enemies.begin(); enemyIt != enemies.end(); ) {
|
for (auto enemyIt = enemies.begin(); enemyIt != enemies.end(); ) {
|
||||||
for (auto bulletIt = enemyIt->getBullets().begin(); bulletIt != enemyIt->getBullets().end();) {
|
for (auto bulletIt = enemyIt->getBullets().begin(); bulletIt != enemyIt->getBullets().end();) {
|
||||||
@@ -504,18 +513,26 @@ void Plansza::update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& wiazkowiec : WEnemies) {
|
for (auto wiazkowiecIt = WEnemies.begin(); wiazkowiecIt != WEnemies.end();) {
|
||||||
wiazkowiec.update();
|
bool hit = false;
|
||||||
|
for (auto bulletIt = ship.getBullets().begin(); bulletIt != ship.getBullets().end();) {
|
||||||
if (wiazkowiec.isShooting() && wiazkowiec.getBeam().isVisible()) {
|
if (wiazkowiecIt->getSprite().getGlobalBounds().intersects(bulletIt->getSprite().getGlobalBounds())) {
|
||||||
if (ship.getSprite().getGlobalBounds().intersects(wiazkowiec.getBeam().getBounds())) {
|
bulletIt = ship.getBullets().erase(bulletIt);
|
||||||
ship.takeDamage(); // Gracz otrzymuje obrażenia
|
wiazkowiecIt->takeDamage();
|
||||||
|
hit = true;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
++bulletIt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hit && !wiazkowiecIt->isAlive()) {
|
||||||
|
wiazkowiecIt = WEnemies.erase(wiazkowiecIt); // Usunięcie przeciwnika Wiazkowiec
|
||||||
|
} else {
|
||||||
|
++wiazkowiecIt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window->draw(wiazkowiec.getSprite());
|
|
||||||
wiazkowiec.render(*window);
|
|
||||||
}
|
|
||||||
|
|
||||||
//oblsuga dla rakiety
|
//oblsuga dla rakiety
|
||||||
for (auto enemyIt = enemies.begin(); enemyIt != enemies.end();) {
|
for (auto enemyIt = enemies.begin(); enemyIt != enemies.end();) {
|
||||||
@@ -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() {
|
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);
|
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;
|
std::cout << "Spawned Bomber Enemy at X: " << spawnX << std::endl;
|
||||||
BomberSpawnClock.restart();
|
BomberSpawnClock.restart();
|
||||||
}
|
}
|
||||||
@@ -659,9 +697,11 @@ void Plansza::spawn_kamikadze() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Plansza::spawn_wiazkowiec() {
|
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);
|
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;
|
std::cout << "Spawned Wiazkowiec Enemy at X: " << spawnX << std::endl;
|
||||||
WiazkowiecSpawnClock.restart();
|
WiazkowiecSpawnClock.restart();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,10 +34,32 @@ void Player::alternate_shoot() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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() {
|
void Player::takeDamage() {
|
||||||
|
if (!isImmortal) {
|
||||||
if (health > 0) {
|
if (health > 0) {
|
||||||
health--;
|
health--;
|
||||||
std::cout << "Player hit! Remaining health: " << health << "\n";
|
std::cout << "Player hit! Remaining health: " << health << "\n";
|
||||||
|
isImmortal = true; // Aktywuj chwilową nieśmiertelność
|
||||||
|
immortalityClock.restart();
|
||||||
|
|
||||||
|
|
||||||
if (health <= 0) {
|
if (health <= 0) {
|
||||||
@@ -47,6 +69,7 @@ void Player::takeDamage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Player::isAlive() const {
|
bool Player::isAlive() const {
|
||||||
return health > 0;
|
return health > 0;
|
||||||
|
|||||||
@@ -9,8 +9,12 @@ Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture& texture) : Actor(x, y, t
|
|||||||
actorSprite.setTexture(texture);
|
actorSprite.setTexture(texture);
|
||||||
hp = 2; // 2 punkty życia
|
hp = 2; // 2 punkty życia
|
||||||
firerate = 5000; // Strzela co 10
|
firerate = 5000; // Strzela co 10
|
||||||
moving_speed = 1.0f; // Prędkość
|
moving_speed = 5.0f; // Prędkość
|
||||||
// BombaTexture.loadFromFile("../assets/img/bullets/bomba.png");
|
}
|
||||||
|
|
||||||
|
void Wiazkowiec::setPlanszaHeight(float height, float width) {
|
||||||
|
planszaHeight = height;
|
||||||
|
planszaWidth = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wiazkowiec::spawnBeam() {
|
void Wiazkowiec::spawnBeam() {
|
||||||
@@ -23,16 +27,24 @@ void Wiazkowiec::spawnBeam() {
|
|||||||
case DirectionW::Up:
|
case DirectionW::Up:
|
||||||
beamHeight = position.y;
|
beamHeight = position.y;
|
||||||
beamY -= beamHeight;
|
beamY -= beamHeight;
|
||||||
|
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||||
break;
|
break;
|
||||||
case DirectionW::Down:
|
case DirectionW::Down:
|
||||||
beamHeight = 600 - position.y;
|
beamHeight = planszaHeight - position.y;
|
||||||
|
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||||
break;
|
break;
|
||||||
case DirectionW::Left:
|
case DirectionW::Left:
|
||||||
|
beamHeight = 50.f;
|
||||||
beamWidth = position.x;
|
beamWidth = position.x;
|
||||||
beamX -= beamWidth;
|
beamX -= beamWidth;
|
||||||
|
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
|
||||||
|
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||||
break;
|
break;
|
||||||
case DirectionW::Right:
|
case DirectionW::Right:
|
||||||
|
beamHeight = 50.f;
|
||||||
beamWidth = 800 - position.x;
|
beamWidth = 800 - position.x;
|
||||||
|
beamY = position.y + (actorSprite.getGlobalBounds().height / 2) - 25.f;
|
||||||
|
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +52,7 @@ void Wiazkowiec::spawnBeam() {
|
|||||||
beam.setVisible(true);
|
beam.setVisible(true);
|
||||||
|
|
||||||
shooting = true;
|
shooting = true;
|
||||||
shootingClock.restart(); // Reset zegara
|
shootingClock.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strzał wiązki
|
// Strzał wiązki
|
||||||
@@ -72,22 +84,41 @@ void Wiazkowiec::setRandomDirection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Wiazkowiec::updateDirection() {
|
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) {
|
if (position.y <= 0) {
|
||||||
direction = DirectionW::Down;
|
direction = DirectionW::Down;
|
||||||
} else if (position.y >= 800) {
|
} else if (position.y + spriteBounds.height >= planszaHeight) {
|
||||||
direction = DirectionW::Up;
|
direction = DirectionW::Up;
|
||||||
}
|
}
|
||||||
|
|
||||||
// logika dla kierunku lewo/prawo
|
// Kontrola lewej i prawej krawędzi
|
||||||
if (position.x <= 0) {
|
if (position.x <= 0) {
|
||||||
direction = DirectionW::Right;
|
direction = DirectionW::Right;
|
||||||
} else if (position.x >= 1200) {
|
} else if (position.x + spriteBounds.width >= planszaWidth) {
|
||||||
direction = DirectionW::Left;
|
direction = DirectionW::Left;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Wiazkowiec::move(float deltaX, float deltaY) {
|
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);
|
actorSprite.move(deltaX, deltaY);
|
||||||
position.x += static_cast<int>(deltaX);
|
position.x += static_cast<int>(deltaX);
|
||||||
position.y += static_cast<int>(deltaY);
|
position.y += static_cast<int>(deltaY);
|
||||||
|
|||||||
Reference in New Issue
Block a user