mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
feat(gameplay): add walking sound for players and adjust underwater bubble interval
- Move walk/run sound interval constants from anonymous namespace to ClientPlayer header - Add moving_time field to PlayerInfo to track continuous movement - Implement play_walk_sound callback triggered by WALK and RUN gaits - Increase underwater bubble timer from 1.0s to 1.5s
This commit is contained in:
@@ -17,6 +17,8 @@ namespace Cubed {
|
|||||||
class ClientWorld;
|
class ClientWorld;
|
||||||
class ClientPlayer {
|
class ClientPlayer {
|
||||||
public:
|
public:
|
||||||
|
static constexpr float WALK_SOUND_INTERVAL = 0.45f;
|
||||||
|
static constexpr float RUN_SOUND_INTERVAL = 0.3f;
|
||||||
using ChunkPosSet = absl::flat_hash_set<ChunkPos, ChunkPos::Hash>;
|
using ChunkPosSet = absl::flat_hash_set<ChunkPos, ChunkPos::Hash>;
|
||||||
ClientPlayer(ClientWorld& world);
|
ClientPlayer(ClientWorld& world);
|
||||||
~ClientPlayer();
|
~ClientPlayer();
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ struct PlayerInfo {
|
|||||||
Gait gait;
|
Gait gait;
|
||||||
float angle = 0.0f;
|
float angle = 0.0f;
|
||||||
float walk_time = 0.0f;
|
float walk_time = 0.0f;
|
||||||
|
float moving_time = 0.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlayerRenderData {
|
struct PlayerRenderData {
|
||||||
|
|||||||
@@ -5,10 +5,7 @@
|
|||||||
#include "Cubed/debug_collector.hpp"
|
#include "Cubed/debug_collector.hpp"
|
||||||
#include "Cubed/gameplay/client_world.hpp"
|
#include "Cubed/gameplay/client_world.hpp"
|
||||||
|
|
||||||
namespace {
|
namespace {} // namespace
|
||||||
constexpr float WALK_SOUND_INTERVAL = 0.45f;
|
|
||||||
constexpr float RUN_SOUND_INTERVAL = 0.3f;
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
namespace Cubed {
|
namespace Cubed {
|
||||||
ClientPlayer::ClientPlayer(ClientWorld& world) : m_world(world) {}
|
ClientPlayer::ClientPlayer(ClientWorld& world) : m_world(world) {}
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ void ClientWorld::init(std::string_view player_name,
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
m_timers.try_emplace("under water bubble", 1.0f, [this]() {
|
m_timers.try_emplace("under water bubble", 1.5f, [this]() {
|
||||||
if (m_player.is_underwater()) {
|
if (m_player.is_underwater()) {
|
||||||
auto ans = m_random.random_int(1, 2);
|
auto ans = m_random.random_int(1, 2);
|
||||||
std::string sound =
|
std::string sound =
|
||||||
@@ -794,6 +794,36 @@ void ClientWorld::update(float delta_time) {
|
|||||||
player.angle = glm::mix(player.angle, 0.0f, t);
|
player.angle = glm::mix(player.angle, 0.0f, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// walking sound
|
||||||
|
if (player.gait == Gait::STOP) {
|
||||||
|
player.moving_time = 0.0f;
|
||||||
|
} else {
|
||||||
|
player.moving_time += delta_time;
|
||||||
|
}
|
||||||
|
auto play_walk_sound = [&]() {
|
||||||
|
glm::ivec3 block = glm::floor(player.render_pos);
|
||||||
|
block.y -= 1;
|
||||||
|
BlockType id = get_block_tpye(block);
|
||||||
|
if (id == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::string name = BlockManager::name_form_id(id);
|
||||||
|
std::string sound = "block/" + name + "/walk.ogg";
|
||||||
|
m_audio.play_3d(sound, player.render_pos);
|
||||||
|
};
|
||||||
|
if (player.gait == Gait::WALK) {
|
||||||
|
if (player.moving_time >= ClientPlayer::WALK_SOUND_INTERVAL) {
|
||||||
|
player.moving_time = 0.0f;
|
||||||
|
play_walk_sound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (player.gait == Gait::RUN) {
|
||||||
|
if (player.moving_time >= ClientPlayer::RUN_SOUND_INTERVAL) {
|
||||||
|
player.moving_time = 0.0f;
|
||||||
|
play_walk_sound();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_render_player_data.emplace_back(
|
m_render_player_data.emplace_back(
|
||||||
player.name, player.uuid, player.render_pos, player.render_yaw,
|
player.name, player.uuid, player.render_pos, player.render_yaw,
|
||||||
player.render_pitch, player.gait, player.angle);
|
player.render_pitch, player.gait, player.angle);
|
||||||
|
|||||||
Reference in New Issue
Block a user