63 lines
1.3 KiB
Rust
63 lines
1.3 KiB
Rust
use godot::{
|
|
classes::{AudioStreamPlayer3D, GpuParticles3D},
|
|
prelude::*,
|
|
};
|
|
|
|
#[derive(GodotClass)]
|
|
#[class(base=Node3D, init)]
|
|
pub struct PlayerEffects {
|
|
#[export]
|
|
splorch: Option<Gd<GpuParticles3D>>,
|
|
#[export]
|
|
hit_sound: Option<Gd<AudioStreamPlayer3D>>,
|
|
#[export]
|
|
walk_sound: Option<Gd<AudioStreamPlayer3D>>,
|
|
#[export]
|
|
walk_sfx_cd: f64,
|
|
|
|
walk_sfx_cd_remaining: f64,
|
|
|
|
base: Base<Node3D>,
|
|
}
|
|
|
|
#[godot_api]
|
|
impl INode3D for PlayerEffects {
|
|
fn process(&mut self, delta: f64) {
|
|
self.walk_sfx_cd_remaining -= delta;
|
|
}
|
|
}
|
|
|
|
impl PlayerEffects {
|
|
pub fn death(&mut self) {
|
|
if let Some(splorch) = &mut self.splorch {
|
|
splorch.set_emitting(true);
|
|
}
|
|
if let Some(sfx) = &mut self.hit_sound {
|
|
sfx.play();
|
|
}
|
|
}
|
|
|
|
pub fn hit(&mut self) {
|
|
if let Some(sfx) = &mut self.hit_sound {
|
|
sfx.play();
|
|
}
|
|
}
|
|
|
|
pub fn walk(&mut self) {
|
|
if self.walk_sfx_cd_remaining > 0. {
|
|
return;
|
|
}
|
|
if let Some(walk) = &mut self.walk_sound {
|
|
walk.play();
|
|
}
|
|
self.walk_sfx_cd_remaining = self.walk_sfx_cd;
|
|
}
|
|
|
|
pub fn jump(&mut self) {
|
|
if let Some(walk) = &mut self.walk_sound {
|
|
walk.play();
|
|
}
|
|
self.walk_sfx_cd_remaining = 0.;
|
|
}
|
|
}
|