Added player walk footstep sound

dev
Shariq Shah 6 years ago
parent d635bab4ec
commit a44e61c4e5
  1. BIN
      assets/sounds/player_walk.wav
  2. 2
      src/common/version.h
  3. 23
      src/game/player.c
  4. 5
      src/game/sound_source.c
  5. 1
      todo.txt

Binary file not shown.

@ -4,7 +4,7 @@
/* Auto generated version file. DO NOT MODIFY */ /* Auto generated version file. DO NOT MODIFY */
#define SYMMETRY_VERSION_MAJOR 0 #define SYMMETRY_VERSION_MAJOR 0
#define SYMMETRY_VERSION_MINOR 1 #define SYMMETRY_VERSION_MINOR 1
#define SYMMETRY_VERSION_REVISION 342 #define SYMMETRY_VERSION_REVISION 343
#define SYMMETRY_VERSION_BRANCH "dev" #define SYMMETRY_VERSION_BRANCH "dev"
#endif #endif

@ -18,6 +18,7 @@
#include "sound_source.h" #include "sound_source.h"
#include <float.h> #include <float.h>
#include <string.h>
static void player_on_mousebutton_released(const struct Event* event); static void player_on_mousebutton_released(const struct Event* event);
@ -60,7 +61,7 @@ void player_init(struct Player* player, struct Scene* scene)
else else
log_error("player:init", "Could not add weapon entity to player"); 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) if(footstep_sound)
player->footstep_sound = footstep_sound; player->footstep_sound = footstep_sound;
else else
@ -93,6 +94,8 @@ void player_destroy(struct Player* player)
void player_update_physics(struct Player* player, struct Scene* scene, float fixed_dt) void player_update_physics(struct Player* player, struct Scene* scene, float fixed_dt)
{ {
struct Sound* sound = game_state_get()->sound;
/* Look around */ /* Look around */
float total_pitch = quat_get_pitch(&player->camera->base.transform.rotation); float total_pitch = quat_get_pitch(&player->camera->base.transform.rotation);
float pitch = 0.f; 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.x *= move_speed * fixed_dt;
translation.z *= 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); 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); debug_vars_show_bool("Grounded", player->grounded);
} }

@ -4,6 +4,8 @@
#include "transform.h" #include "transform.h"
#include "../common/log.h" #include "../common/log.h"
#include <string.h>
void sound_source_validate_instance(struct Sound* sound, struct Sound_Source* entity) void sound_source_validate_instance(struct Sound* sound, struct Sound_Source* entity)
{ {
if(!sound_source_instance_is_valid(sound, entity->source_instance)) 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) 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); struct Sound_Source_Buffer* new_buffer = sound_source_buffer_create(sound, filename, type);
if(new_buffer) if(new_buffer)
{ {

@ -1,4 +1,5 @@
Todo: Todo:
- Implement player footstep sounds for walking, running and jumping
- RGB keys to progress to next level - RGB keys to progress to next level
- Player/enemies getting hit by bullets - Player/enemies getting hit by bullets
- Win/fail States - Win/fail States

Loading…
Cancel
Save