diff --git a/sources/Component/Music/MusicComponent.cpp b/sources/Component/Music/MusicComponent.cpp new file mode 100644 index 00000000..f31bfe16 --- /dev/null +++ b/sources/Component/Music/MusicComponent.cpp @@ -0,0 +1,56 @@ +/* +** EPITECH PROJECT, 2021 +** Bomberman +** File description: +** MusicComponent +*/ + +#include "MusicComponent.hpp" + + +namespace BBM +{ + MusicComponent::MusicComponent(WAL::Entity &entity, std::string &path) + : WAL::Component(entity), + _musicPath(path) + {} + + WAL::Component *MusicComponent::clone(WAL::Entity &entity) const + { + return new MusicComponent(entity); + } + + + void MusicComponent::loadMusic(void) + { + this->_music = RAY::Audio::Music(this->_musicPath); + this->_music.play(); + } + + void MusicComponent::unloadMusic(void) + { + this->_music.stop(); + } + + void MusicComponent::pauseMusic(void) + { + this->_music.pause(); + } + + void MusicComponent::setVolume(float &volume) + { + this->_music.setVolume(volume); + } + + void MusicComponent::setPitch(float &pitch) + { + this->_music.setPitch(pitch); + } + + bool MusicComponent::isPlaying(void) + { + return (this->_music.isPlaying()); + } + + +} // namespace WAL diff --git a/sources/Component/Music/MusicComponent.hpp b/sources/Component/Music/MusicComponent.hpp new file mode 100644 index 00000000..c15335ec --- /dev/null +++ b/sources/Component/Music/MusicComponent.hpp @@ -0,0 +1,55 @@ +// +// Created by Zoe Roux on 5/17/21. +// + +#pragma once + +#include "Models/Vector3.hpp" +#include "Component/Component.hpp" +#include "Music.hpp" + +namespace BBM +{ + //! @brief A basic Music component + class MusicComponent : public WAL::Component + { + private: + //! @brief music of this entity + RAY::Audio::Music _music; + //! @brief path to the music + std::string _musicPath; + //! @brief Create a new MusicComponent linked to a specific entity + explicit MusicComponent(WAL::Entity &entity); + + public: + + //! @brief load music + void loadMusic(); + + //! @brief unload music + void unloadMusic(); + + //! @brief put music on hold + void pauseMusic(); + + //! @brief set music volume + void setVolume(float &); + + //! @brief set pitch volume + void setPitch(float &); + + //! @brief is music playing + bool isPlaying(void); + + //! @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); + //! @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; + }; +} // namespace WAL \ No newline at end of file