fix sound on click

This commit is contained in:
arthur.jamet
2021-06-17 09:47:36 +02:00
parent 5a948bca46
commit a8f5cb85a5
10 changed files with 17 additions and 10 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ namespace BBM
{SoundComponent::JUMP, "assets/sounds/click.ogg"}
};
addMenuControl(*scene);
addMenuControl(*scene, sounds);
scene->addEntity("background")
.addComponent<PositionComponent>()
.addComponent<Drawable2DComponent, RAY::Texture>("assets/plain_menu_background.png");
+1 -1
View File
@@ -22,7 +22,7 @@ namespace BBM
{SoundComponent::JUMP, "assets/sounds/click.ogg"}
};
addMenuControl(*scene);
addMenuControl(*scene, sounds);
scene->addEntity("Control entity")
.addComponent<MusicComponent>("assets/musics/music_player_select.ogg")
.addComponent<SoundComponent>(sounds);
+1 -1
View File
@@ -33,7 +33,7 @@ namespace BBM
};
auto scene = std::make_shared<WAL::Scene>();
addMenuControl(*scene);
addMenuControl(*scene, sounds);
scene->addEntity("Control entity")
.addComponent<MusicComponent>("assets/musics/music_player_select.ogg")
.addComponent<SoundComponent>(sounds);
+1 -1
View File
@@ -23,7 +23,7 @@ namespace BBM
};
auto scene = std::make_shared<WAL::Scene>();
addMenuControl(*scene);
addMenuControl(*scene, sounds);
scene->addEntity("Control entity")
.addComponent<MusicComponent>("assets/musics/music_title.ogg")
.addComponent<SoundComponent>(sounds);
+1 -1
View File
@@ -23,7 +23,7 @@ namespace BBM
};
auto scene = std::make_shared<WAL::Scene>();
addMenuControl(*scene);
addMenuControl(*scene, sounds);
scene->addEntity("Control entity")
.addComponent<MusicComponent>("assets/musics/music_player_select.ogg")
.addComponent<SoundComponent>(sounds);
+4 -1
View File
@@ -110,17 +110,20 @@ namespace BBM
.addSystem<RenderSystem>(window);
}
void Runner::addMenuControl(WAL::Scene &scene)
void Runner::addMenuControl(WAL::Scene &scene, const std::map<SoundComponent::SoundIndex, std::string> &sounds)
{
scene.addEntity("Keyboard default control")
.addComponent<ControllableComponent>()
.addComponent<SoundComponent>(sounds)
.addComponent<KeyboardComponent>();
scene.addEntity("Keyboard second control")
.addComponent<ControllableComponent>()
.addComponent<SoundComponent>(sounds)
.addComponent<KeyboardComponent>(ControllableComponent::Layout::KEYBOARD_1);
for (int i = 0; i < 4; i++) {
scene.addEntity("Gamepad controller")
.addComponent<ControllableComponent>()
.addComponent<SoundComponent>(sounds)
.addComponent<GamepadComponent>(i);
}
}
+3 -1
View File
@@ -5,6 +5,8 @@
#pragma once
#include "Models/GameState.hpp"
#include "Wal.hpp"
#include <map>
#include "Component/Sound/SoundComponent.hpp"
namespace BBM
{
@@ -30,7 +32,7 @@ namespace BBM
//! @brief init all raylib-related data & context
static void enableRaylib(WAL::Wal &wal);
static void addMenuControl(WAL::Scene &scene);
static void addMenuControl(WAL::Scene &scene, const std::map<SoundComponent::SoundIndex, std::string> &sounds = {});
//! @brief load all data related to title screen
static std::shared_ptr<WAL::Scene> loadTitleScreenScene();
+1 -1
View File
@@ -45,7 +45,7 @@ namespace BBM
playersIconPath.push_back(path.replace(path.find("textures"), std::string("textures").size(), "icons"));
}
addMenuControl(*scene);
addMenuControl(*scene, sounds);
scene->addEntity("Audio ressources")
.addComponent<MusicComponent>("assets/musics/music_result.ogg")
.addComponent<SoundComponent>(sounds);
+3 -1
View File
@@ -24,7 +24,7 @@ namespace BBM
{SoundComponent::JUMP, "assets/sounds/click.ogg"}
};
addMenuControl(*scene);
addMenuControl(*scene, sounds);
scene->addEntity("Control entity")
.addComponent<MusicComponent>("assets/musics/music_title.ogg")
.addComponent<SoundComponent>(sounds);
@@ -110,6 +110,7 @@ namespace BBM
.addComponent<PositionComponent>(1920 / 1.5, 1080 - 360, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_plus.png")
.addComponent<SoundComponent>(sounds)
.addComponent<ControllableComponent>()
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &)
{
auto &component = entity.getComponent<SoundComponent>();
@@ -133,6 +134,7 @@ namespace BBM
.addComponent<PositionComponent>(1920 / 3, 1080 - 360, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_minus.png")
.addComponent<SoundComponent>(sounds)
.addComponent<ControllableComponent>()
.addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &)
{
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
+1 -1
View File
@@ -22,7 +22,7 @@ namespace BBM
{SoundComponent::JUMP, "assets/sounds/click.ogg"}
};
auto scene = std::make_shared<WAL::Scene>();
addMenuControl(*scene);
addMenuControl(*scene, sounds);
scene->addEntity("control")
.addComponent<SoundComponent>(sounds)
.addComponent<MusicComponent>("assets/musics/music_title.ogg");