diff options
Diffstat (limited to 'src/vfx/mod.rs')
| -rw-r--r-- | src/vfx/mod.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/vfx/mod.rs b/src/vfx/mod.rs new file mode 100644 index 0000000..3a7d1a5 --- /dev/null +++ b/src/vfx/mod.rs @@ -0,0 +1,58 @@ +use glam::Vec2; + +use crate::content::vfx::VfxMaterialId; + +pub struct VfxLine { + pub a: Vec2, + pub b: Vec2, + pub width: f32, + pub material: VfxMaterialId, + pub alive_for: f32, + pub lifetime: f32, +} + +impl VfxLine { + pub fn new(a: Vec2, b: Vec2, width: f32, material: VfxMaterialId, lifetime: f32) -> Self { + VfxLine { + a, + b, + width, + material, + alive_for: 0.0, + lifetime, + } + } +} + +pub trait VfxWriter { + fn write_vfx_line(&mut self, line: VfxLine) -> (); +} + +pub struct VfxManager { + pub lines: Vec<VfxLine>, +} + +impl VfxManager { + pub fn after_render(&mut self, delta_time: f32) { + let mut i = 0; + while i < self.lines.len() { + let l = &mut self.lines[i]; + l.alive_for += delta_time; + if l.alive_for > l.lifetime { + self.lines.swap_remove(i); + continue; + } + i += 1; + } + } + + pub fn new() -> Self { + VfxManager { lines: Vec::new() } + } +} + +impl VfxWriter for VfxManager { + fn write_vfx_line(&mut self, line: VfxLine) -> () { + self.lines.push(line); + } +} |
