mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
feat(gameplay): add ocean wave ambient sounds with random selection
Add four ocean wave FLAC sound files and play one randomly when player is within 10 blocks of sea level and in an ocean biome. Include a Random member initialized from ChunkGenerator seed for consistent randomization.
This commit is contained in:
BIN
assets/sound/ambient/ocean/wave001.flac
Normal file
BIN
assets/sound/ambient/ocean/wave001.flac
Normal file
Binary file not shown.
BIN
assets/sound/ambient/ocean/wave002.flac
Normal file
BIN
assets/sound/ambient/ocean/wave002.flac
Normal file
Binary file not shown.
BIN
assets/sound/ambient/ocean/wave003.flac
Normal file
BIN
assets/sound/ambient/ocean/wave003.flac
Normal file
Binary file not shown.
BIN
assets/sound/ambient/ocean/wave004.flac
Normal file
BIN
assets/sound/ambient/ocean/wave004.flac
Normal file
Binary file not shown.
@@ -6,6 +6,7 @@
|
||||
#include "Cubed/gameplay/client_player.hpp"
|
||||
#include "Cubed/gameplay/game_time.hpp"
|
||||
#include "Cubed/gameplay/network_client.hpp"
|
||||
#include "Cubed/tools/cubed_random.hpp"
|
||||
#include "Cubed/tools/priority_thread_pool.hpp"
|
||||
|
||||
#include <absl/container/flat_hash_set.h>
|
||||
@@ -153,6 +154,8 @@ private:
|
||||
|
||||
std::atomic<std::shared_ptr<PriorityThreadPool>> m_thread_pool;
|
||||
|
||||
Random m_random;
|
||||
|
||||
void client_run(std::stop_token token);
|
||||
|
||||
void report_player_info();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "Cubed/gameplay/client_world.hpp"
|
||||
|
||||
#include "Cubed/config.hpp"
|
||||
#include "Cubed/gameplay/chunk_generator.hpp"
|
||||
#include "Cubed/gameplay/game_time.hpp"
|
||||
#include "Cubed/gameplay/packet.hpp"
|
||||
#include "Cubed/tools/math_tools.hpp"
|
||||
@@ -357,6 +358,8 @@ void ClientWorld::init(std::string_view player_name,
|
||||
std::shared_ptr<NetworkClient> client) {
|
||||
m_player.init(player_name);
|
||||
m_client = client;
|
||||
m_random.init(ChunkGenerator::seed());
|
||||
|
||||
// timer
|
||||
register_ticktimer("player_pos", 1, [this]() { report_player_info(); });
|
||||
m_timers.try_emplace("Birds Sound", 60.0f, [this]() {
|
||||
@@ -375,6 +378,26 @@ void ClientWorld::init(std::string_view player_name,
|
||||
}
|
||||
});
|
||||
|
||||
m_timers.try_emplace("Ocean Wave", 3.0f, [this]() {
|
||||
auto player_pos = m_player.get_player_pos();
|
||||
if (player_pos.y < SEA_LEVEL - 10 || player_pos.y > SEA_LEVEL + 10) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto ans = m_random.random_int(1, 4);
|
||||
std::string sound =
|
||||
"ambient/ocean/wave00" + std::to_string(ans) + ".flac";
|
||||
ChunkPos pos = get_chunk_pos(player_pos.x, player_pos.z);
|
||||
{
|
||||
chunk_cacc cacc;
|
||||
if (m_chunks.find(cacc, pos)) {
|
||||
if (cacc->second->get_biome() == BiomeType::OCEAN) {
|
||||
m_audio.play_2d(sound, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
LoginReq req;
|
||||
req.set_name(m_player.get_name());
|
||||
while (!client->is_connected()) {
|
||||
|
||||
Reference in New Issue
Block a user