diff --git a/assets/sounds/player_walk.wav b/assets/sounds/player_walk.wav new file mode 100644 index 0000000..6ef64f1 Binary files /dev/null and b/assets/sounds/player_walk.wav differ diff --git a/src/common/version.h b/src/common/version.h index dcab449..01f9006 100755 --- a/src/common/version.h +++ b/src/common/version.h @@ -4,7 +4,7 @@ /* Auto generated version file. DO NOT MODIFY */ #define SYMMETRY_VERSION_MAJOR 0 #define SYMMETRY_VERSION_MINOR 1 -#define SYMMETRY_VERSION_REVISION 342 +#define SYMMETRY_VERSION_REVISION 343 #define SYMMETRY_VERSION_BRANCH "dev" #endif \ No newline at end of file diff --git a/src/game/player.c b/src/game/player.c index ad6f607..bdd40b1 100755 --- a/src/game/player.c +++ b/src/game/player.c @@ -18,6 +18,7 @@ #include "sound_source.h" #include +#include static void player_on_mousebutton_released(const struct Event* event); @@ -60,7 +61,7 @@ void player_init(struct Player* player, struct Scene* scene) else log_error("player:init", "Could not add weapon entity to player"); - struct Sound_Source* footstep_sound = scene_sound_source_create(scene, "Player_Footstep_Sound_Source", player, "sounds/player_walk.wav", ST_WAV, true, false); + struct Sound_Source* footstep_sound = scene_sound_source_create(scene, "Player_Footstep_Sound_Source", player, "sounds/player_walk.wav", ST_WAV, false, false); if(footstep_sound) player->footstep_sound = footstep_sound; else @@ -93,6 +94,8 @@ void player_destroy(struct Player* player) void player_update_physics(struct Player* player, struct Scene* scene, float fixed_dt) { + struct Sound* sound = game_state_get()->sound; + /* Look around */ float total_pitch = quat_get_pitch(&player->camera->base.transform.rotation); float pitch = 0.f; @@ -234,9 +237,25 @@ void player_update_physics(struct Player* player, struct Scene* scene, float fix translation.x *= move_speed * fixed_dt; translation.z *= move_speed * fixed_dt; - translation.y = move_speed_vertical * fixed_dt; + translation.y = move_speed_vertical * fixed_dt; transform_translate(player, &translation, TS_WORLD); + if(translation.x != 0.f || translation.z != 0.f) + { + // Walking + if(player->grounded) + { + if(strncmp(player->footstep_sound->source_buffer->filename, "sounds/player_walk.wav", MAX_FILENAME_LEN) != 0) + sound_source_buffer_set(sound, player->footstep_sound, "sounds/player_walk.wav", ST_WAV); + + if(sound_source_is_paused(sound, player->footstep_sound)) + sound_source_play(sound, player->footstep_sound); + } + } + else + { + // Stopped walking + } debug_vars_show_bool("Grounded", player->grounded); } diff --git a/src/game/sound_source.c b/src/game/sound_source.c index 57807e8..42e66c5 100644 --- a/src/game/sound_source.c +++ b/src/game/sound_source.c @@ -4,6 +4,8 @@ #include "transform.h" #include "../common/log.h" +#include + void sound_source_validate_instance(struct Sound* sound, struct Sound_Source* entity) { if(!sound_source_instance_is_valid(sound, entity->source_instance)) @@ -56,6 +58,9 @@ void sound_source_update_position(struct Sound* sound, struct Sound_Source* enti void sound_source_buffer_set(struct Sound* sound, struct Sound_Source* entity, const char* filename, int type) { + if(strncmp(filename, entity->source_buffer->filename, MAX_FILENAME_LEN) == 0) + return; + struct Sound_Source_Buffer* new_buffer = sound_source_buffer_create(sound, filename, type); if(new_buffer) { diff --git a/todo.txt b/todo.txt index 72fa549..3df09dc 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,5 @@ Todo: + - Implement player footstep sounds for walking, running and jumping - RGB keys to progress to next level - Player/enemies getting hit by bullets - Win/fail States