mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-27 16:22:09 +00:00
add map for SoundSystem and fix error in MusicComponent
This commit is contained in:
@@ -7,20 +7,16 @@
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
MusicComponent::MusicComponent(WAL::Entity &entity, std::string &musicPath)
|
||||
MusicComponent::MusicComponent(WAL::Entity &entity, const std::string &musicPath)
|
||||
: WAL::Component(entity),
|
||||
_musicPath(musicPath),
|
||||
_music(RAY::Audio::Music(musicPath))
|
||||
{
|
||||
}
|
||||
|
||||
MusicComponent::MusicComponent(WAL::Entity &entity)
|
||||
: Component(entity),
|
||||
_music()
|
||||
{}
|
||||
|
||||
WAL::Component *MusicComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new MusicComponent(entity);
|
||||
return new MusicComponent(entity, this->_musicPath);
|
||||
}
|
||||
|
||||
void MusicComponent::loadMusic(void)
|
||||
|
||||
@@ -35,20 +35,19 @@ namespace BBM
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
//! @brief Create a new MusicComponent at a certain Music
|
||||
MusicComponent(WAL::Entity &entity, std::string &musicPath);
|
||||
explicit MusicComponent(WAL::Entity &entity, const std::string &musicPath);
|
||||
//! @brief A Music component is copy constructable
|
||||
MusicComponent(const MusicComponent &) = default;
|
||||
//! @brief A default destructor
|
||||
~MusicComponent() override = default;
|
||||
//! @brief A Music component is not assignable
|
||||
MusicComponent &operator=(const MusicComponent &) = delete;
|
||||
|
||||
private:
|
||||
//! @brief music of this entity
|
||||
RAY::Audio::Music _music;
|
||||
//! @brief Create a new MusicComponent linked to a specific entity
|
||||
explicit MusicComponent(WAL::Entity &entity);
|
||||
|
||||
|
||||
//! @brief patht to the music assets
|
||||
const std::string _musicPath;
|
||||
};
|
||||
|
||||
} // namespace BBM
|
||||
@@ -19,7 +19,7 @@ std::map<SoundComponent::soundIndex, std::string> &soundPath)
|
||||
this->_isLoad[static_cast<soundIndex>(i)] = false;
|
||||
} else {
|
||||
this->_isLoad[static_cast<soundIndex>(i)] = true;
|
||||
this->_soundList[static_cast<soundIndex>(i)] = std::unique_ptr<RAY::Audio::Sound>(new RAY::Audio::Sound(soundPath.at(static_cast<soundIndex>(i))));
|
||||
this->_soundList[static_cast<soundIndex>(i)] = std::make_unique<RAY::Audio::Sound>(soundPath.at(static_cast<soundIndex>(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ std::map<SoundComponent::soundIndex, std::string> &soundPath)
|
||||
return new SoundComponent(entity);
|
||||
}
|
||||
|
||||
void SoundComponent::playSound(void)
|
||||
void SoundComponent::playSound()
|
||||
{
|
||||
if (!this->_isLoad.at(this->_soundIndex))
|
||||
return;
|
||||
@@ -43,7 +43,7 @@ std::map<SoundComponent::soundIndex, std::string> &soundPath)
|
||||
this->_soundList[this->_soundIndex].get()->play();
|
||||
}
|
||||
|
||||
void SoundComponent::stopSound(void)
|
||||
void SoundComponent::stopSound()
|
||||
{
|
||||
if (!this->_isLoad.at(this->_soundIndex))
|
||||
return;
|
||||
@@ -51,7 +51,7 @@ std::map<SoundComponent::soundIndex, std::string> &soundPath)
|
||||
this->_soundList[this->_soundIndex].get()->stop();
|
||||
}
|
||||
|
||||
void SoundComponent::pauseSound(void)
|
||||
void SoundComponent::pauseSound()
|
||||
{
|
||||
if (!this->_isLoad.at(this->_soundIndex))
|
||||
return;
|
||||
@@ -73,7 +73,7 @@ std::map<SoundComponent::soundIndex, std::string> &soundPath)
|
||||
this->_soundList[this->_soundIndex].get()->setPitch(pitch);
|
||||
}
|
||||
|
||||
bool SoundComponent::isPlaying(void)
|
||||
bool SoundComponent::isPlaying()
|
||||
{
|
||||
if (!this->_isLoad.at(this->_soundIndex))
|
||||
return (false);
|
||||
@@ -85,7 +85,7 @@ std::map<SoundComponent::soundIndex, std::string> &soundPath)
|
||||
this->_soundIndex = index;
|
||||
}
|
||||
|
||||
SoundComponent::soundIndex SoundComponent::getIndex(void)
|
||||
SoundComponent::soundIndex SoundComponent::getIndex()
|
||||
{
|
||||
return (this->_soundIndex);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace BBM
|
||||
void setPitch(float &);
|
||||
|
||||
//! @brief is Sound playing
|
||||
bool isPlaying(void);
|
||||
bool isPlaying();
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
@@ -3,33 +3,30 @@
|
||||
//
|
||||
|
||||
#include "PlayerSoundManagerSystem.hpp"
|
||||
#include <map>
|
||||
|
||||
namespace BBM {
|
||||
|
||||
|
||||
SoundManagerSystem::SoundManagerSystem()
|
||||
: WAL::System({
|
||||
typeid(SoundComponent),
|
||||
typeid(HealthComponent)
|
||||
})
|
||||
SoundManagerSystem::SoundManagerSystem(WAL::Wal &wal)
|
||||
: System(wal)
|
||||
{}
|
||||
|
||||
void SoundManagerSystem::onFixedUpdate(WAL::Entity &entity)
|
||||
{
|
||||
if (!entity.hasComponent<ControllableComponent>())
|
||||
return;
|
||||
const auto &controllable = entity.getComponent<ControllableComponent>();
|
||||
auto &sound = entity.getComponent<SoundComponent>();
|
||||
auto &health = entity.getComponent<HealthComponent>();
|
||||
void SoundManagerSystem::onFixedUpdate(WAL::ViewEntity<SoundComponent, ControllableComponent, HealthComponent> &entity)
|
||||
{
|
||||
const auto &controllable = entity.get<ControllableComponent>();
|
||||
auto &sound = entity.get<SoundComponent>();
|
||||
auto &health = entity.get<HealthComponent>();
|
||||
|
||||
sound.setIndex(SoundComponent::BOMB);
|
||||
if (controllable.bomb)
|
||||
sound.playSound();
|
||||
sound.setIndex(SoundComponent::JUMP);
|
||||
if (controllable.jump)
|
||||
sound.playSound();
|
||||
sound.setIndex(SoundComponent::MOVE);
|
||||
if (controllable.move.x != 0 || controllable.move.y != 0)
|
||||
sound.playSound();
|
||||
}
|
||||
std::map<bool, SoundComponent::soundIndex> soundIndex = {
|
||||
{controllable.bomb, SoundComponent::BOMB},
|
||||
{controllable.jump, SoundComponent::JUMP},
|
||||
{controllable.move.x != 0 || controllable.move.y != 0, SoundComponent::MOVE}
|
||||
};
|
||||
for (auto &a : soundIndex) {
|
||||
if (a.first) {
|
||||
sound.setIndex(a.second);
|
||||
sound.playSound();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,14 +13,14 @@
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
class SoundManagerSystem : public WAL::System
|
||||
class SoundManagerSystem : public WAL::System<SoundComponent, ControllableComponent, HealthComponent>
|
||||
{
|
||||
public:
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::Entity &entity) override;
|
||||
void onFixedUpdate(WAL::ViewEntity<SoundComponent, ControllableComponent, HealthComponent> &entity) override;
|
||||
|
||||
//! @brief ctor
|
||||
SoundManagerSystem();
|
||||
SoundManagerSystem(WAL::Wal &wal);
|
||||
//! @brief Default copy ctor
|
||||
SoundManagerSystem(const SoundManagerSystem &) = default;
|
||||
//! @brief Default dtor
|
||||
|
||||
Reference in New Issue
Block a user