mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-05 19:04:26 +00:00
add basic music manager
This commit is contained in:
@@ -1,56 +1,93 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2021
|
||||
** Bomberman
|
||||
** File description:
|
||||
** MusicComponent
|
||||
*/
|
||||
//
|
||||
// Created by Tom Augier on 05/06/2021
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include "MusicComponent.hpp"
|
||||
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
MusicComponent::MusicComponent(WAL::Entity &entity, std::string &path)
|
||||
MusicComponent::MusicComponent(WAL::Entity &entity, \
|
||||
std::map<MusicComponent::musicIndex, std::string> &musicPath)
|
||||
: WAL::Component(entity),
|
||||
_musicPath(path)
|
||||
{}
|
||||
_musicIndex(IDLE)
|
||||
{
|
||||
for (int i = 0; i < DEATH + 1; i++) {
|
||||
if (musicPath.at(static_cast<musicIndex>(i)).empty()) {
|
||||
this->_isLoad[static_cast<musicIndex>(i)] = false;
|
||||
} else {
|
||||
this->_isLoad[static_cast<musicIndex>(i)] = true;
|
||||
this->_musicList[static_cast<musicIndex>(i)] = RAY::Audio::Music(musicPath.at(static_cast<musicIndex>(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MusicComponent::MusicComponent(WAL::Entity &entity)
|
||||
: Component(entity),
|
||||
_musicList(),
|
||||
_musicIndex()
|
||||
{}
|
||||
|
||||
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();
|
||||
{
|
||||
if (!this->_isLoad.at(this->_musicIndex))
|
||||
return;
|
||||
if (!this->_musicList[this->_musicIndex].isPlaying()) {
|
||||
std::cout << this->_musicIndex << std::endl;
|
||||
this->_musicList[this->_musicIndex].play();
|
||||
}
|
||||
}
|
||||
|
||||
void MusicComponent::unloadMusic(void)
|
||||
{
|
||||
this->_music.stop();
|
||||
if (!this->_isLoad.at(this->_musicIndex))
|
||||
return;
|
||||
if (!this->_musicList[this->_musicIndex].isPlaying())
|
||||
this->_musicList[this->_musicIndex].stop();
|
||||
}
|
||||
|
||||
void MusicComponent::pauseMusic(void)
|
||||
{
|
||||
this->_music.pause();
|
||||
if (!this->_isLoad.at(this->_musicIndex))
|
||||
return;
|
||||
this->_musicList[this->_musicIndex].pause();
|
||||
}
|
||||
|
||||
void MusicComponent::setVolume(float &volume)
|
||||
{
|
||||
this->_music.setVolume(volume);
|
||||
if (!this->_isLoad.at(this->_musicIndex))
|
||||
return;
|
||||
if (volume >= 0)
|
||||
this->_musicList[this->_musicIndex].setVolume(volume);
|
||||
}
|
||||
|
||||
void MusicComponent::setPitch(float &pitch)
|
||||
{
|
||||
this->_music.setPitch(pitch);
|
||||
if (!this->_isLoad.at(this->_musicIndex))
|
||||
return;
|
||||
this->_musicList[this->_musicIndex].setPitch(pitch);
|
||||
}
|
||||
|
||||
bool MusicComponent::isPlaying(void)
|
||||
{
|
||||
return (this->_music.isPlaying());
|
||||
if (!this->_isLoad.at(this->_musicIndex))
|
||||
return (false);
|
||||
return (this->_musicList[this->_musicIndex].isPlaying());
|
||||
}
|
||||
|
||||
void MusicComponent::setIndex(musicIndex index)
|
||||
{
|
||||
this->_musicIndex = index;
|
||||
}
|
||||
|
||||
MusicComponent::musicIndex MusicComponent::getIndex(void)
|
||||
{
|
||||
return (this->_musicIndex);
|
||||
}
|
||||
|
||||
} // namespace WAL
|
||||
|
||||
@@ -1,28 +1,34 @@
|
||||
//
|
||||
// Created by Zoe Roux on 5/17/21.
|
||||
// Created by Tom Augier on 05/06/2021
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Models/Vector3.hpp"
|
||||
#include "Component/Component.hpp"
|
||||
#include "Music.hpp"
|
||||
#include <map>
|
||||
#include "Audio/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:
|
||||
|
||||
enum musicIndex {
|
||||
IDLE,
|
||||
JUMP,
|
||||
BOMB,
|
||||
MOVE,
|
||||
HURT,
|
||||
THROW,
|
||||
DEATH,
|
||||
};
|
||||
|
||||
void setIndex(musicIndex index);
|
||||
|
||||
musicIndex getIndex();
|
||||
|
||||
//! @brief load music
|
||||
void loadMusic();
|
||||
|
||||
@@ -41,15 +47,28 @@ namespace BBM
|
||||
//! @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);
|
||||
MusicComponent(WAL::Entity &entity, std::map<musicIndex, 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
|
||||
std::map<musicIndex, RAY::Audio::Music> _musicList;
|
||||
|
||||
std::map<musicIndex, bool> _isLoad;
|
||||
//! musicIndex
|
||||
musicIndex _musicIndex;
|
||||
//! @brief Create a new MusicComponent linked to a specific entity
|
||||
explicit MusicComponent(WAL::Entity &entity);
|
||||
|
||||
|
||||
};
|
||||
} // namespace WAL
|
||||
|
||||
} // namespace BBM
|
||||
Reference in New Issue
Block a user