Dodano w miare sensowne poruszanie sie tla i muzyke, do zrobienia lepsze tlo

This commit is contained in:
2024-11-20 19:32:35 +01:00
parent a69dc434a9
commit e38bb6e5d0
68 changed files with 6390 additions and 9 deletions

44
sources/AudioManager.cpp Normal file
View File

@@ -0,0 +1,44 @@
#include "../headers/AudioManager.h"
#include <iostream>
//Dodalem dla zabawy audio tez jako potencjalny dodatek, jbc mozna wywalic
bool AudioManager::loadBackgroundMusic(const std::string& filePath) {
if (!backgroundMusic.openFromFile(filePath)) {
std::cerr << "Muzyka tla sie nie zaladowala!!! " << filePath << "\n";
return false;
}
return true;
}
void AudioManager::playBackgroundMusic(float volume, bool loop) {
backgroundMusic.setVolume(volume);
backgroundMusic.setLoop(loop);
backgroundMusic.play();
}
void AudioManager::stopBackgroundMusic() {
backgroundMusic.stop();
}
bool AudioManager::loadSoundEffect(const std::string& name, const std::string& filePath) {
sf::SoundBuffer buffer;
if (!buffer.loadFromFile(filePath)) {
std::cerr << "Plik z efektem sie nie zaladowal " << filePath << "\n";
return false;
}
// std::cout << "Zaladowano " << name << " z " << filePath << "\n";
soundBuffers[name] = buffer;
sounds[name].setBuffer(soundBuffers[name]);
return true;
}
void AudioManager::playSoundEffect(const std::string& name, float volume) {
if (sounds.find(name) != sounds.end()) {
sounds[name].setVolume(volume);
sounds[name].play();
} else {
std::cerr << "Pliku z efektem " << name << " nie znaleziono!\n";
}
}