mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add delay to walking sounds
This commit is contained in:
parent
f38d3781b3
commit
7321488ff1
@ -10,13 +10,22 @@ use common::comp::{
|
|||||||
use client::Client;
|
use client::Client;
|
||||||
use vek::*;
|
use vek::*;
|
||||||
use specs::{Entity as EcsEntity, Join};
|
use specs::{Entity as EcsEntity, Join};
|
||||||
|
use hashbrown::HashMap;
|
||||||
|
use std::{f32, time::Instant};
|
||||||
|
|
||||||
|
pub struct AnimState {
|
||||||
|
last_step_sound: Instant,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct SoundMgr {
|
pub struct SoundMgr {
|
||||||
|
character_states: HashMap<EcsEntity, AnimState>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SoundMgr {
|
impl SoundMgr {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {}
|
Self {
|
||||||
|
character_states: HashMap::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn maintain(&mut self, audio: &mut AudioFrontend, client: &Client) {
|
pub fn maintain(&mut self, audio: &mut AudioFrontend, client: &Client) {
|
||||||
@ -43,9 +52,17 @@ impl SoundMgr {
|
|||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
let state = self
|
||||||
|
.character_states
|
||||||
|
.entry(entity)
|
||||||
|
.or_insert_with(|| AnimState {last_step_sound: Instant::now()});
|
||||||
|
|
||||||
if let Run = &character.movement {
|
if let Run = &character.movement {
|
||||||
|
if state.last_step_sound.elapsed().as_secs_f64() > 0.5 {
|
||||||
let rand_step = (rand::random::<usize>() % 7) + 1;
|
let rand_step = (rand::random::<usize>() % 7) + 1;
|
||||||
audio.play_sound(format!("voxygen.audio.footsteps.stepdirt_{}", rand_step));
|
audio.play_sound(format!("voxygen.audio.footsteps.stepdirt_{}", rand_step));
|
||||||
|
state.last_step_sound = Instant::now();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user