mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-28 08:33:36 +00:00
Sound for jump + fix sound component function name
This commit is contained in:
Binary file not shown.
@@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include "SoundComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
@@ -10,18 +11,18 @@ namespace BBM
|
||||
SoundComponent::SoundComponent(WAL::Entity &entity, \
|
||||
std::map<SoundComponent::soundIndex, std::string> &soundPath)
|
||||
: WAL::Component(entity),
|
||||
_soundIndex(IDLE)
|
||||
_soundIndex(IDLE),
|
||||
_soundPath(soundPath)
|
||||
{
|
||||
for (int i = 0; i < DEATH + 1; i++) {
|
||||
for (int i = 0; i <= DEATH; i++)
|
||||
this->_isLoad[static_cast<soundIndex>(i)] = false;
|
||||
/*for (int i = 0; i <= DEATH; i++) {
|
||||
if (soundPath.at(static_cast<soundIndex>(i)).empty()) {
|
||||
this->_isLoad[static_cast<soundIndex>(i)] = false;
|
||||
} else {
|
||||
this->_isLoad[static_cast<soundIndex>(i)] = true;
|
||||
this->_soundList[static_cast<soundIndex>(i)] = RAY::Audio::Sound(soundPath.at(static_cast<soundIndex>(i)));
|
||||
}
|
||||
}
|
||||
/*for (int i = 0; i < DEATH + 1; i++) {
|
||||
std::cout << i << this->_isLoad.at(static_cast<soundIndex>(i)) << soundPath.at(static_cast<soundIndex>(i)) << std::endl;
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -36,22 +37,19 @@ std::map<SoundComponent::soundIndex, std::string> &soundPath)
|
||||
return new SoundComponent(entity);
|
||||
}
|
||||
|
||||
void SoundComponent::loadSound(void)
|
||||
void SoundComponent::playSound(void)
|
||||
{
|
||||
std::cout << this->_soundIndex << std::endl;
|
||||
if (!this->_isLoad.at(this->_soundIndex))
|
||||
return;
|
||||
if (!this->_soundList[this->_soundIndex].isPlaying()) {
|
||||
std::cout << this->_soundIndex << std::endl;
|
||||
this->_soundList[this->_soundIndex] = RAY::Audio::Sound(this->_soundPath.at(this->_soundIndex));
|
||||
if (!this->_soundList[this->_soundIndex].isPlaying())
|
||||
this->_soundList[this->_soundIndex].play();
|
||||
}
|
||||
}
|
||||
|
||||
void SoundComponent::unloadSound(void)
|
||||
void SoundComponent::stopSound(void)
|
||||
{
|
||||
if (!this->_isLoad.at(this->_soundIndex))
|
||||
return;
|
||||
if (!this->_soundList[this->_soundIndex].isPlaying())
|
||||
if (this->_soundList[this->_soundIndex].isPlaying())
|
||||
this->_soundList[this->_soundIndex].stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,10 +30,10 @@ namespace BBM
|
||||
soundIndex getIndex();
|
||||
|
||||
//! @brief load Sound
|
||||
void loadSound();
|
||||
void playSound();
|
||||
|
||||
//! @brief unload Sound
|
||||
void unloadSound();
|
||||
void stopSound();
|
||||
|
||||
//! @brief put Sound on hold
|
||||
void pauseSound();
|
||||
@@ -47,11 +47,10 @@ namespace BBM
|
||||
//! @brief is Sound playing
|
||||
bool isPlaying(void);
|
||||
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
//! @brief Create a new SoundComponent at a certain Sound
|
||||
SoundComponent(WAL::Entity &entity, std::map<soundIndex, std::string> &SoundPath);
|
||||
SoundComponent(WAL::Entity &entity, std::map<soundIndex, std::string> &);
|
||||
//! @brief A Sound component is copy constructable
|
||||
SoundComponent(const SoundComponent &) = default;
|
||||
//! @brief A default destructor
|
||||
@@ -63,8 +62,13 @@ namespace BBM
|
||||
std::map<soundIndex, RAY::Audio::Sound> _soundList;
|
||||
|
||||
std::map<soundIndex, bool> _isLoad;
|
||||
|
||||
std::map<soundIndex, std::string> _soundPath;
|
||||
|
||||
//! SoundIndex
|
||||
soundIndex _soundIndex;
|
||||
|
||||
|
||||
//! @brief Create a new SoundComponent linked to a specific entity
|
||||
explicit SoundComponent(WAL::Entity &entity);
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "Map/Map.hpp"
|
||||
#include "Component/Music/MusicComponent.hpp"
|
||||
#include "Component/Sound/SoundComponent.hpp"
|
||||
#include "System/Sound/PlayerSoundManagerSystem.hpp"
|
||||
|
||||
namespace RAY2D = RAY::Drawables::Drawables2D;
|
||||
namespace RAY3D = RAY::Drawables::Drawables3D;
|
||||
@@ -53,12 +54,13 @@ namespace BBM
|
||||
.addSystem<GamepadSystem>()
|
||||
.addSystem<ControllableSystem>()
|
||||
.addSystem<CollisionSystem>(wal)
|
||||
.addSystem<MovableSystem>();
|
||||
.addSystem<MovableSystem>()
|
||||
.addSystem<SoundManagerSystem>();
|
||||
}
|
||||
|
||||
void enableRaylib(WAL::Wal &wal)
|
||||
{
|
||||
RAY::TraceLog::setLevel(LOG_WARNING);
|
||||
//RAY::TraceLog::setLevel(LOG_WARNING);
|
||||
RAY::Window &window = RAY::Window::getInstance(600, 400, "Bomberman", FLAG_WINDOW_RESIZABLE);
|
||||
wal.addSystem<RenderSystem>(wal, window);
|
||||
}
|
||||
@@ -70,7 +72,7 @@ namespace BBM
|
||||
{SoundComponent::IDLE, ""},
|
||||
{SoundComponent::JUMP, ""},
|
||||
{SoundComponent::BOMB, ""},
|
||||
{SoundComponent::MOVE, "assets/sounds/weird.wav"},
|
||||
{SoundComponent::MOVE, "assets/sounds/jump.wav"},
|
||||
{SoundComponent::HURT, ""},
|
||||
{SoundComponent::THROW, ""},
|
||||
{SoundComponent::DEATH, ""}
|
||||
@@ -79,10 +81,12 @@ namespace BBM
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<HealthComponent>(1)
|
||||
.addComponent<KeyboardComponent>()
|
||||
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 1)
|
||||
.addComponent<CollisionComponent>(2)
|
||||
.addComponent<MovableComponent>()
|
||||
//.addComponent<MusicComponent>("assets/musics/music_win.ogg");
|
||||
.addComponent<SoundComponent>(soundPath);
|
||||
scene->addEntity("cube")
|
||||
.addComponent<PositionComponent>(-5, 0, -5)
|
||||
|
||||
@@ -6,6 +6,14 @@
|
||||
|
||||
namespace BBM {
|
||||
|
||||
|
||||
SoundManagerSystem::SoundManagerSystem()
|
||||
: WAL::System({
|
||||
typeid(SoundComponent),
|
||||
typeid(HealthComponent)
|
||||
})
|
||||
{}
|
||||
|
||||
void SoundManagerSystem::onFixedUpdate(WAL::Entity &entity)
|
||||
{
|
||||
if (!entity.hasComponent<ControllableComponent>())
|
||||
@@ -15,12 +23,13 @@ namespace BBM {
|
||||
auto &health = entity.getComponent<HealthComponent>();
|
||||
|
||||
sound.setIndex(SoundComponent::BOMB);
|
||||
controllable.bomb ? sound.loadSound() : sound.unloadSound();
|
||||
if (controllable.bomb)
|
||||
sound.playSound();
|
||||
sound.setIndex(SoundComponent::JUMP);
|
||||
controllable.jump ? sound.loadSound() : sound.unloadSound();
|
||||
if (controllable.jump)
|
||||
sound.playSound();
|
||||
sound.setIndex(SoundComponent::MOVE);
|
||||
(controllable.move.x != 0 || controllable.move.y != 0) ? sound.loadSound() : sound.unloadSound();
|
||||
sound.setIndex(SoundComponent::DEATH);
|
||||
health.getHealthPoint() == 0 ? sound.loadSound() : sound.unloadSound();
|
||||
if (controllable.move.x != 0 || controllable.move.y != 0)
|
||||
sound.playSound();
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ namespace BBM
|
||||
void onFixedUpdate(WAL::Entity &entity) override;
|
||||
|
||||
//! @brief ctor
|
||||
SoundManagerSystem(WAL::Wal &wal, RAY::Window &window);
|
||||
SoundManagerSystem();
|
||||
//! @brief Default copy ctor
|
||||
SoundManagerSystem(const SoundManagerSystem &) = default;
|
||||
//! @brief Default dtor
|
||||
|
||||
Reference in New Issue
Block a user