Added landing and jumping sounds

dev
Shariq Shah 6 years ago
parent dcb62add68
commit e9ab3ae4af
  1. 31
      assets/entities/door.symtres
  2. 6
      assets/scenes/scene_1.symtres
  3. BIN
      assets/sounds/player_jump_grunt.wav
  4. BIN
      assets/sounds/player_sprint.wav
  5. BIN
      assets/sounds/player_walk.wav
  6. 2
      src/common/version.h
  7. 1
      src/game/entity.h
  8. 58
      src/game/player.c
  9. 4
      src/game/scene.c

@ -2,31 +2,31 @@ Entity
{
type : 10
scale : 1.000 1.000 1.000
door_state : 0
door_open_position : -7.0000
rotation : 0.000 0.000 0.000 1.000
door_close_position : 0.0000
active : true
position : 0.000 0.000 0.000
bounding_box_min : -0.500 -0.500 -0.500
door_speed : 6.0000
position : -18.500 1.000 -30.000
door_mask : 0
name : Door
bounding_box_min : -0.500 -0.500 -0.500
bounding_box_max : 0.500 0.500 0.500
door_speed : 6.000
door_state : 0
door_mask : 0
door_open_position : -7.000
door_close_position : 0.000
}
Entity
{
type : 9
scale : 1.000 1.000 1.000
scale : 7.000 11.000 14.000
rotation : 0.000 0.000 0.000 1.000
trigger_mask : 1
active : true
position : 0.000 0.000 0.000
bounding_box_min : -3.000 -3.000 -5.000
bounding_box_max : 3.000 3.000 5.000
position : 0.000 5.000 0.000
trigger_type : 1
name : Door_Trigger
bounding_box_min : -0.500 -0.500 -0.500
bounding_box_max : 0.500 0.500 0.500
}
Entity
@ -39,15 +39,15 @@ Entity
loop : false
sound_min_distance : 0.0000
active : true
paused : true
position : 0.000 0.000 0.000
bounding_box_min : -0.500 -0.500 -0.500
source_filename : sounds/door_close.wav
sound_type : 1
sound_max_distance : 30.0000
name : Door_Sound
bounding_box_max : 0.500 0.500 0.500
bounding_box_min : -0.500 -0.500 -0.500
sound_attenuation_type : 2
paused : true
bounding_box_max : 0.500 0.500 0.500
}
Entity
@ -66,4 +66,5 @@ Entity
specular_strength : 62.0000
name : Door_Mesh
uv_scale : 0.300 0.200
}
}

@ -16,11 +16,11 @@ Player
{
type : 2
scale : 1.000 1.000 1.000
rotation : 0.000 -1.000 0.000 -0.033
rotation : 0.000 -1.001 0.000 -0.000
active : true
position : -20.255 2.167 -50.978
player_health : 100
player_key_mask : 0
position : -18.634 2.167 -45.517
player_health : 100
name : Player
bounding_box_min : -1.500 -1.500 -1.000
camera_clear_color : 0.310 0.412 0.529 1.000

Binary file not shown.

Binary file not shown.

@ -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 344
#define SYMMETRY_VERSION_REVISION 345
#define SYMMETRY_VERSION_BRANCH "dev"
#endif

@ -198,6 +198,7 @@ struct Player
struct Camera* camera;
struct Sound_Source* weapon_sound;
struct Sound_Source* footstep_sound;
struct Sound_Source* grunt_sound;
int health;
int key_mask;
float move_speed;

@ -67,11 +67,18 @@ void player_init(struct Player* player, struct Scene* scene)
else
log_error("player:init", "Could not add footstep entity to player");
struct Sound_Source* grunt_sound = scene_sound_source_create(scene, "Player_Grunt_Sound_Source", player, "sounds/player_jump_grunt.wav", ST_WAV, false, false);
if(grunt_sound)
player->grunt_sound = grunt_sound;
else
log_error("player:init", "Could not add grunt entity to player");
// Mark player camera and mesh as transient for now. We don't need to save them to file since we recreate them here anyway
player->camera->base.flags |= EF_TRANSIENT;
player->mesh->base.flags |= EF_TRANSIENT;
player->weapon_sound->base.flags |= EF_TRANSIENT;
player->footstep_sound->base.flags |= EF_TRANSIENT;
player->grunt_sound->base.flags |= EF_TRANSIENT;
transform_parent_set(player_camera, player, true);
@ -143,11 +150,14 @@ void player_update_physics(struct Player* player, struct Scene* scene, float fix
vec3 move_direction = { 0.f };
static bool jumping = false;
static bool landed = false;
static float move_speed_vertical = 0.f;
// If we started jumping last frame, set jumpig to false
if(jumping) jumping = false;
if(landed) landed = false;
if(input_map_state_get("Sprint", KS_PRESSED)) move_speed *= player->move_speed_multiplier;
if(input_map_state_get("Move_Forward", KS_PRESSED)) move_direction.z -= 1.f;
if(input_map_state_get("Move_Backward", KS_PRESSED)) move_direction.z += 1.f;
@ -226,7 +236,11 @@ void player_update_physics(struct Player* player, struct Scene* scene, float fix
if(distance > 0.f && distance <= player->min_downward_distance && !jumping)
{
move_speed_vertical = 0.f;
player->grounded = true;
if(!player->grounded)
{
player->grounded = true;
landed = true;
}
}
}
}
@ -240,32 +254,44 @@ void player_update_physics(struct Player* player, struct Scene* scene, float fix
translation.y = move_speed_vertical * fixed_dt;
transform_translate(player, &translation, TS_WORLD);
if(translation.x != 0.f || translation.z != 0.f)
// Sounds
if(translation.x != 0.f || translation.z != 0.f || landed)
{
if(player->grounded)
{
// Sprinting/Walking
if(input_map_state_get("Sprint", KS_PRESSED))
if(sound_source_is_paused(sound, player->footstep_sound)) // if a sound is already playing, let it finish first then switch to avoid abrupt transition
{
if(strncmp(player->footstep_sound->source_buffer->filename, "sounds/player_sprint.wav", MAX_FILENAME_LEN) != 0)
sound_source_buffer_set(sound, player->footstep_sound, "sounds/player_sprint.wav", ST_WAV);
}
else 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);
}
// Sprinting/Walking/Jump Landing
if(landed)
{
if(strncmp(player->footstep_sound->source_buffer->filename, "sounds/player_jump_land.wav", MAX_FILENAME_LEN) != 0)
sound_source_buffer_set(sound, player->footstep_sound, "sounds/player_jump_land.wav", ST_WAV);
}
else if(input_map_state_get("Sprint", KS_PRESSED))
{
if(strncmp(player->footstep_sound->source_buffer->filename, "sounds/player_sprint.wav", MAX_FILENAME_LEN) != 0)
sound_source_buffer_set(sound, player->footstep_sound, "sounds/player_sprint.wav", ST_WAV);
}
else 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
if(jumping)
{
// Stopped walking
if(sound_source_is_paused(sound, player->grunt_sound))
{
if(strncmp(player->grunt_sound->source_buffer->filename, "sounds/player_jump_grunt.wav", MAX_FILENAME_LEN) != 0)
sound_source_buffer_set(sound, player->grunt_sound, "sounds/player_jump_grunt.wav", ST_WAV);
sound_source_play(sound, player->grunt_sound);
}
}
debug_vars_show_bool("Grounded", player->grounded);
}

@ -270,8 +270,8 @@ bool scene_save(struct Scene* scene, const char* filename, int directory_type)
struct Parser_Object* player_object = parser_object_new(parser, PO_PLAYER);
entity_write(&scene->player, player_object, true);
hashmap_vec4_set(player_object->data, "camera_clear_color", &scene->player.camera->clear_color);
hashmap_int_set(player_object->data, "player_health", &scene->player.health);
hashmap_int_set(player_object->data, "player_key_mask", &scene->player.key_mask);
hashmap_int_set(player_object->data, "player_health", scene->player.health);
hashmap_int_set(player_object->data, "player_key_mask", scene->player.key_mask);
scene_write_entity_list(scene, ET_DEFAULT, parser);
scene_write_entity_list(scene, ET_LIGHT, parser);

Loading…
Cancel
Save