emmmm, strzal niby jest w bullecie, ale chujowo to dziala
This commit is contained in:
@@ -1,14 +1,23 @@
|
|||||||
|
|
||||||
#ifndef LOTOSTATEK_BULLET_H
|
#ifndef LOTOSTATEK_BULLET_H
|
||||||
#define LOTOSTATEK_BULLET_H
|
#define LOTOSTATEK_BULLET_H
|
||||||
|
|
||||||
#include "Projectile.h"
|
#include "Projectile.h"
|
||||||
#include "SFML/Graphics/Texture.hpp"
|
#include "SFML/Graphics/Texture.hpp"
|
||||||
|
#include "SFML/Audio/Sound.hpp"
|
||||||
|
#include "SFML/Audio/SoundBuffer.hpp"
|
||||||
|
|
||||||
class Bullet : public Projectile {
|
class Bullet : public Projectile {
|
||||||
public:
|
public:
|
||||||
Bullet(float x, float y, sf::Texture &texture) : Projectile(x,y, texture) {};
|
Bullet(float x, float y, sf::Texture &texture);
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
||||||
|
// Dodanie metody do odtwarzania dźwięku
|
||||||
|
void playShootSound();
|
||||||
|
|
||||||
|
private:
|
||||||
|
sf::Sound shootSound;
|
||||||
|
sf::SoundBuffer shootBuffer; // Dodanie bufora dźwięku
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif //LOTOSTATEK_BULLET_H
|
#endif //LOTOSTATEK_BULLET_H
|
||||||
|
|||||||
@@ -1,9 +1,22 @@
|
|||||||
#include "../headers/Bullet.h"
|
#include "../headers/Bullet.h"
|
||||||
|
|
||||||
|
Bullet::Bullet(float x, float y, sf::Texture &texture) : Projectile(x, y, texture) {
|
||||||
|
// Ładowanie dźwięku wystrzału
|
||||||
|
if (!shootBuffer.loadFromFile("../assets/sounds/shoot.ogg")) {
|
||||||
|
// Obsługa błędu
|
||||||
|
}
|
||||||
|
shootSound.setBuffer(shootBuffer);
|
||||||
|
playShootSound(); // Odtwarzanie dźwięku wystrzału przy utworzeniu pocisku
|
||||||
|
}
|
||||||
|
|
||||||
void Bullet::update() {
|
void Bullet::update() {
|
||||||
sprite.move(0.0f, speed);
|
sprite.move(0.0f, speed);
|
||||||
position.y += int(speed);
|
position.y += int(speed);
|
||||||
if(position.y < -100) {
|
if (position.y < -100) {
|
||||||
outOfBounds = true;
|
outOfBounds = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Bullet::playShootSound() {
|
||||||
|
shootSound.play();
|
||||||
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ void Plansza::update() {
|
|||||||
// TODO: Przenieść obiekt dźwięku wewnątrz klasy Bullet
|
// TODO: Przenieść obiekt dźwięku wewnątrz klasy Bullet
|
||||||
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
|
if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
|
||||||
ship.shoot();
|
ship.shoot();
|
||||||
audioManager.playSoundEffect("shoot", 70.f); // Odtworzenie dźwięku wystrzału
|
// audioManager.playSoundEffect("shoot", 70.f); // Odtworzenie dźwięku wystrzału
|
||||||
}
|
}
|
||||||
if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
|
if (sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
|
||||||
ship.alternate_shoot();
|
ship.alternate_shoot();
|
||||||
|
|||||||
Reference in New Issue
Block a user