feat(player): efectes de so configurables al despegue i a l'aterratge
This commit is contained in:
1 parent
f3f5fa5e92
commit
3646e6a4aa
4 files changed
+30
No files matched your search
@@ -7,6 +7,7 @@
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
|
||||
#include "core/audio/audio.hpp"
|
||||
#include "core/input/gamepad_manager.hpp"
|
||||
#include "core/input/input_state.hpp"
|
||||
#include "core/rendering/screen.hpp"
|
||||
@@ -147,6 +148,17 @@ void Player::readJumpBlock(const fkyaml::node& yaml) {
|
||||
if (j.contains("gravity")) { jump_config.gravity_px_per_s2 = j["gravity"].get_value<float>(); }
|
||||
if (j.contains("landing_stun_ms")) { jump_config.landing_stun_ms = j["landing_stun_ms"].get_value<int>(); }
|
||||
if (j.contains("shadow_y_offset")) { jump_config.shadow_y_offset = j["shadow_y_offset"].get_value<int>(); }
|
||||
// Sons opcionals: el nom del fitxer (relatiu a data/sounds/) val tant
|
||||
// de clau al Resource::Cache com de basename per a la càrrega. Si el
|
||||
// camp manca, la clau queda buida i `playSound` no es crida.
|
||||
if (j.contains("sound")) {
|
||||
jump_config.sound_key = j["sound"].get_value<std::string>();
|
||||
Resource::Cache::get().loadSound(jump_config.sound_key, "data/sounds/" + jump_config.sound_key);
|
||||
}
|
||||
if (j.contains("land_sound")) {
|
||||
jump_config.land_sound_key = j["land_sound"].get_value<std::string>();
|
||||
Resource::Cache::get().loadSound(jump_config.land_sound_key, "data/sounds/" + jump_config.land_sound_key);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::applyCardinal(Cardinal c) {
|
||||
@@ -492,6 +504,9 @@ void Player::startJump() {
|
||||
state_ = State::AIRBORNE;
|
||||
jump_z_ = 0.0F;
|
||||
jump_vz_ = jump_config.impulse_px_per_s;
|
||||
if (!jump_config.sound_key.empty() && Audio::get() != nullptr) {
|
||||
Audio::get()->playSound(jump_config.sound_key, Audio::Group::GAME);
|
||||
}
|
||||
// Prou: la velocitat horitzontal del salt és la `intended_v*` actual
|
||||
// (input del frame). El facing també queda com està. Ja no es
|
||||
// tocaran fins a aterrar.
|
||||
@@ -506,6 +521,9 @@ auto Player::integrateJump(float delta_time) -> bool {
|
||||
jump_vz_ = 0.0F;
|
||||
state_ = State::LANDING_STUN;
|
||||
landing_stun_remaining_ms_ = static_cast<float>(jump_config.landing_stun_ms);
|
||||
if (!jump_config.land_sound_key.empty() && Audio::get() != nullptr) {
|
||||
Audio::get()->playSound(jump_config.land_sound_key, Audio::Group::GAME);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user