Laser naprawiono

This commit is contained in:
2025-01-05 18:20:19 +01:00
parent c4c83382c3
commit 6b45443c75
8 changed files with 39 additions and 35 deletions

View File

@@ -9,6 +9,8 @@ public:
Beam(int x, int y, const sf::Texture &texture); Beam(int x, int y, const sf::Texture &texture);
sf::Sprite getSprite(); sf::Sprite getSprite();
void setRotation(float angle);
private: private:
sf::Sprite beamSprite; sf::Sprite beamSprite;
}; };

View File

@@ -3,7 +3,6 @@
#include "../headers/Plansza.h" #include "../headers/Plansza.h"
AdvancedEnemy::AdvancedEnemy(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, texture) { AdvancedEnemy::AdvancedEnemy(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, texture) {
actorSprite.setTexture(texture);
enemyBulletTexture = bulletTexture; enemyBulletTexture = bulletTexture;
hp = 2; // 2 punkty życia hp = 2; // 2 punkty życia
firerate = 2000; // Strzela co 2 firerate = 2000; // Strzela co 2

View File

@@ -3,6 +3,7 @@
#include <iostream> #include <iostream>
Beam::Beam(int x, int y, const sf::Texture& texture) { Beam::Beam(int x, int y, const sf::Texture& texture) {
beamSprite.setOrigin(beamSprite.getLocalBounds().width/2, beamSprite.getLocalBounds().height/2);
if (texture.getSize().x > 0 && texture.getSize().y > 0) { if (texture.getSize().x > 0 && texture.getSize().y > 0) {
beamSprite.setPosition(x, y); beamSprite.setPosition(x, y);
} else { } else {
@@ -15,3 +16,7 @@ sf::Sprite Beam::getSprite() {
return beamSprite; return beamSprite;
} }
void Beam::setRotation(float angle) {
beamSprite.setRotation(angle);
}

View File

@@ -4,7 +4,6 @@
#include <random> #include <random>
Bomber::Bomber(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, texture) { Bomber::Bomber(int x, int y, const sf::Texture& texture, const sf::Texture& bulletTexture) : Actor(x, y, texture) {
actorSprite.setTexture(texture);
BombaTexture = bulletTexture; BombaTexture = bulletTexture;
hp = 2; // 2 punkty życia hp = 2; // 2 punkty życia
firerate = 10000; // Strzela co 10 firerate = 10000; // Strzela co 10

View File

@@ -3,7 +3,6 @@
#include "../headers/Plansza.h" #include "../headers/Plansza.h"
Enemy::Enemy(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) { Enemy::Enemy(int x, int y, const sf::Texture& texture) : Actor(x, y, texture) {
actorSprite.setTexture(texture);
hp = 1; // Przeciwnik ma 1 punkt życia hp = 1; // Przeciwnik ma 1 punkt życia
firerate = 2000; // Strzela co 2 firerate = 2000; // Strzela co 2
moving_speed = 2.0f; // Prędkość moving_speed = 2.0f; // Prędkość

View File

@@ -7,7 +7,6 @@
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);
hp = 3; // 3 punkty życia hp = 3; // 3 punkty życia
moving_speed = 2.0f; // Prędkość moving_speed = 2.0f; // Prędkość
} }

View File

@@ -111,13 +111,13 @@ void Plansza::update() {
ship->update(); // migotanie statku ship->update(); // migotanie statku
update_score(); // naliczanie punktów update_score(); // naliczanie punktów
// Sprawnowanie wszystkich rodzajów wrogów // Sprawnowanie wszystkich rodzajów wrogów
// spawn_meteor(); // spawn_meteor();
// spawn_hearts(); // spawn_hearts();
// spawn_enemy(); // spawn_enemy();
// spawn_advanced_enemy(); // spawn_advanced_enemy();
spawn_wiazkowiec(); spawn_wiazkowiec();
// spawn_bomber(); // spawn_bomber();
// spawn_kamikadze(); // spawn_kamikadze();
// utrzymanie meteorów i pocisków w ruchu // utrzymanie meteorów i pocisków w ruchu
for (auto &meteor: meteors) { for (auto &meteor: meteors) {

View File

@@ -9,7 +9,6 @@ Wiazkowiec::Wiazkowiec(int x, int y, const sf::Texture &texture, sf::RenderWindo
beam(nullptr) beam(nullptr)
{ {
window_ptr = window; window_ptr = window;
actorSprite.setTexture(texture);
try { try {
beamTexture.loadFromFile("../assets/img/wiazka/laser.png"); beamTexture.loadFromFile("../assets/img/wiazka/laser.png");
@@ -34,19 +33,22 @@ void Wiazkowiec::spawnBeam() {
switch (direction) { switch (direction) {
case DirectionW::Up: { case DirectionW::Up: {
beam = new Beam(beamX, beamY - beamTexture.getSize().y, beamTexture); beam = new Beam(beamX, beamY, beamTexture);
beam->setRotation(180);
break; break;
} }
case DirectionW::Down: { case DirectionW::Down: {
beam = new Beam(beamX, beamY + actorSprite.getGlobalBounds().height, beamTexture); beam = new Beam(beamX, beamY, beamTexture);
break; break;
} }
case DirectionW::Left: { case DirectionW::Left: {
beam = new Beam(beamX - beamTexture.getSize().x, beamY, beamTexture); beam = new Beam(beamX, beamY, beamTexture);
beam->setRotation(90);
break; break;
} }
case DirectionW::Right: { case DirectionW::Right: {
beam = new Beam(beamX + actorSprite.getGlobalBounds().width, beamY, beamTexture); beam = new Beam(beamX, beamY, beamTexture);
beam->setRotation(270);
break; break;
} }
default: default:
@@ -61,27 +63,26 @@ void Wiazkowiec::spawnBeam() {
void Wiazkowiec::shoot() { void Wiazkowiec::shoot() {
if (!shooting) { if (!shooting) {
spawnBeam(); spawnBeam();
std::cout << "Wiazkowiec shot a beam!" << std::endl; }
switch (direction) { switch (direction) {
case DirectionW::Up: { case DirectionW::Up: {
std::cout << "Direction is up" << std::endl; std::cout << "Direction is up" << std::endl;
break; break;
}
case DirectionW::Down: {
std::cout << "Direction is down" << std::endl;
break;
}
case DirectionW::Left: {
std::cout << "Direction is left" << std::endl;
break;
}
case DirectionW::Right: {
std::cout << "Direction is right" << std::endl;
break;
}
default:
break;
} }
case DirectionW::Down: {
std::cout << "Direction is down" << std::endl;
break;
}
case DirectionW::Left: {
std::cout << "Direction is left" << std::endl;
break;
}
case DirectionW::Right: {
std::cout << "Direction is right" << std::endl;
break;
}
default:
break;
} }
} }