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";
}
}

37
sources/Background.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include "../headers/Background.h"
#include <iostream>
//logika robimy dwa spraity i sie przesuwaja po sobie i resetuja jak wyjda poza ekran
Background::Background(const std::string& texturePath, float speed)
: speed(speed)
{
if (!texture.loadFromFile(texturePath)) {
std::cerr << "Tlo sie nie zaladowalo!!! " << texturePath << "\n";
}
sprite1.setTexture(texture);
sprite2.setTexture(texture);
sprite1.setPosition(0, 0);
sprite2.setPosition(0, -texture.getSize().y);
}
void Background::update() {
// Przesuwanie tła
sprite1.move(0, speed);
sprite2.move(0, speed);
// Resetowanie pozycji tła
if (sprite1.getPosition().y >= sprite1.getTexture()->getSize().y) {
sprite1.setPosition(0, sprite2.getPosition().y - sprite2.getTexture()->getSize().y);
}
if (sprite2.getPosition().y >= sprite2.getTexture()->getSize().y) {
sprite2.setPosition(0, sprite1.getPosition().y - sprite1.getTexture()->getSize().y);
}
}
void Background::draw(sf::RenderWindow& window) {
window.draw(sprite1);
window.draw(sprite2);
}