Naprawiono laser, przerobiono na wskaźniki. Do refactoringu i poprawy sprite'a
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
class Beam {
|
||||
public:
|
||||
Beam(float x, float y, float width, float height, const sf::Color& color);
|
||||
Beam(float x, float y, float width, float height);
|
||||
|
||||
void draw(sf::RenderWindow &window);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
void takeDamage();
|
||||
void updateDirection();
|
||||
bool isShooting() const;
|
||||
const Beam& getBeam() const;
|
||||
const Beam* getBeam() const;
|
||||
void setPlanszaHeight(float height, float width);
|
||||
void setMapBounds(float width, float height);
|
||||
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
float movementSpeed = 2.0f;
|
||||
bool alive = true;
|
||||
DirectionW direction = DirectionW::Down;
|
||||
Beam beam; // Wiązka
|
||||
Beam *beam; // Wiązka
|
||||
bool shooting = false;
|
||||
sf::Clock shootingClock;
|
||||
float beamDuration = 1.0f;
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#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)
|
||||
: visible(false) {
|
||||
beamShape.setPosition(x, y);
|
||||
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;
|
||||
|
||||
@@ -111,13 +111,13 @@ void Plansza::update() {
|
||||
ship->update(); // migotanie statku
|
||||
update_score(); // naliczanie punktów
|
||||
// Sprawnowanie wszystkich rodzajów wrogów
|
||||
spawn_meteor();
|
||||
spawn_hearts();
|
||||
spawn_enemy();
|
||||
spawn_advanced_enemy();
|
||||
// spawn_meteor();
|
||||
// spawn_hearts();
|
||||
// spawn_enemy();
|
||||
// spawn_advanced_enemy();
|
||||
spawn_wiazkowiec();
|
||||
spawn_bomber();
|
||||
spawn_kamikadze();
|
||||
// spawn_bomber();
|
||||
// spawn_kamikadze();
|
||||
|
||||
// utrzymanie meteorów i pocisków w ruchu
|
||||
for (auto &meteor: meteors) {
|
||||
@@ -445,8 +445,8 @@ void Plansza::update() {
|
||||
for (auto &wiazkowiec: WEnemies) {
|
||||
wiazkowiec.update();
|
||||
|
||||
if (wiazkowiec.isShooting() && wiazkowiec.getBeam().isVisible()) {
|
||||
if (ship->getSprite().getGlobalBounds().intersects(wiazkowiec.getBeam().getBounds())) {
|
||||
if (wiazkowiec.isShooting() && wiazkowiec.getBeam()->isVisible()) {
|
||||
if (ship->getSprite().getGlobalBounds().intersects(wiazkowiec.getBeam()->getBounds())) {
|
||||
ship->takeDamage(); // Gracz otrzymuje obrażenia
|
||||
}
|
||||
}
|
||||
@@ -775,7 +775,7 @@ void Plansza::spawn_kamikadze() {
|
||||
}
|
||||
|
||||
void Plansza::spawn_wiazkowiec() {
|
||||
if (WiazkowiecSpawnClock.getElapsedTime().asSeconds() >= 50) { // Spawn co 10 sekund
|
||||
if (WiazkowiecSpawnClock.getElapsedTime().asSeconds() >= 5) { // Spawn co 10 sekund
|
||||
int spawnX = RandomNumberGenerator::getRandomNumber(50, size.width - 50);
|
||||
Wiazkowiec wiazkowiec(spawnX, -50, WiazkowiecTexture);
|
||||
wiazkowiec.setPlanszaHeight(size.height, size.width); // Przekazanie wysokości i szerokosci okna
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "../headers/Plansza.h"
|
||||
|
||||
|
||||
Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture& texture) : Actor(x, y, texture), beam(0, 0, 50.f, 50.f, sf::Color::Red) {
|
||||
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
|
||||
@@ -27,29 +27,29 @@ void Wiazkowiec::spawnBeam() {
|
||||
case DirectionW::Up:
|
||||
beamHeight = position.y;
|
||||
beamY -= beamHeight;
|
||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
|
||||
break;
|
||||
case DirectionW::Down:
|
||||
beamHeight = planszaHeight - position.y;
|
||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
|
||||
break;
|
||||
case DirectionW::Left:
|
||||
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);
|
||||
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 = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
beam = new Beam(beamX, beamY, beamWidth, beamHeight);
|
||||
break;
|
||||
}
|
||||
|
||||
beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
beam.setVisible(true);
|
||||
// beam = Beam(beamX, beamY, beamWidth, beamHeight, sf::Color::Red);
|
||||
beam->setVisible(true);
|
||||
|
||||
shooting = true;
|
||||
shootingClock.restart();
|
||||
@@ -133,7 +133,7 @@ void Wiazkowiec::update() {
|
||||
if (shooting) {
|
||||
// Kontrola zakończenia strzału
|
||||
if (shootingClock.getElapsedTime().asSeconds() >= beamDuration) {
|
||||
beam.setVisible(false);
|
||||
beam->setVisible(false);
|
||||
shooting = false;
|
||||
setRandomDirection(); // Zmień kierunek po strzale
|
||||
}
|
||||
@@ -164,8 +164,8 @@ void Wiazkowiec::update() {
|
||||
|
||||
// Ustawianie widoczności wiązki podczas renderowania
|
||||
void Wiazkowiec::render(sf::RenderWindow& window) {
|
||||
if (beam.isVisible()) {
|
||||
beam.render(window);
|
||||
if (beam->isVisible()) {
|
||||
beam->render(window);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +184,6 @@ bool Wiazkowiec::isShooting() const {
|
||||
return shooting;
|
||||
}
|
||||
|
||||
const Beam& Wiazkowiec::getBeam() const {
|
||||
const Beam* Wiazkowiec::getBeam() const {
|
||||
return beam;
|
||||
}
|
||||
Reference in New Issue
Block a user