even more steps sounds test

This commit is contained in:
MihailRis
2024-03-09 02:42:53 +03:00
parent 015b1c2ed7
commit 90f3373f46
11 changed files with 56 additions and 22 deletions
+32 -3
View File
@@ -1,11 +1,17 @@
#include "LevelFrontend.h"
#include "../world/Level.h"
#include "../assets/Assets.h"
#include "../graphics/Atlas.h"
#include "BlocksPreview.h"
#include "ContentGfxCache.h"
#include "../audio/audio.h"
#include "../world/Level.h"
#include "../voxels/Block.h"
#include "../assets/Assets.h"
#include "../graphics/Atlas.h"
#include "../logic/LevelController.h"
#include "../logic/PlayerController.h"
LevelFrontend::LevelFrontend(Level* level, Assets* assets)
: level(level),
assets(assets),
@@ -13,6 +19,29 @@ LevelFrontend::LevelFrontend(Level* level, Assets* assets)
blocksAtlas(BlocksPreview::build(contentCache.get(), assets, level->content)) {
}
void LevelFrontend::observe(LevelController* controller) {
controller->getPlayerController()->listenBlockInteraction(
[=](Player*, glm::ivec3 pos, const Block* def, BlockInteraction type) {
if (type != BlockInteraction::step) {
return;
}
// (test code)
// TODO: replace with BlockMaterial properties access
auto sound = assets->getSound("steps/"+def->material.substr(def->material.find(':')+1));
audio::play(
sound,
glm::vec3(),
true,
0.333f,
1.0f,
false,
audio::PRIORITY_LOW,
audio::get_channel_index("regular")
);
}
);
}
LevelFrontend::~LevelFrontend() {
}
+3
View File
@@ -8,6 +8,7 @@ class Level;
class Assets;
class BlocksPreview;
class ContentGfxCache;
class LevelController;
class LevelFrontend {
Level* level;
@@ -18,6 +19,8 @@ public:
LevelFrontend(Level* level, Assets* assets);
~LevelFrontend();
void observe(LevelController* controller);
Level* getLevel() const;
Assets* getAssets() const;
ContentGfxCache* getContentGfxCache() const;
+1 -18
View File
@@ -100,24 +100,7 @@ LevelScreen::LevelScreen(Engine* engine, Level* level) : Screen(engine) {
worldRenderer = std::make_unique<WorldRenderer>(engine, frontend.get(), controller->getPlayer());
hud = std::make_unique<Hud>(engine, frontend.get(), controller->getPlayer());
controller->getPlayerController()->listenBlockInteraction(
[=](Player*, glm::ivec3 pos, const Block* def, BlockInteraction type) {
if (type != BlockInteraction::step) {
return;
}
auto sound = assets->getSound("steps/grass");
audio::play(
sound,
glm::vec3(),
true,
1.0f,
1.0f,
false,
audio::PRIORITY_LOW,
audio::get_channel_index("regular")
);
}
);
frontend->observe(controller.get());
backlight = settings.graphics.backlight;