diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-25 00:32:16 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-25 00:32:16 -0700 |
| commit | a779011b9048cdda04887c77e20ee8936f332a7a (patch) | |
| tree | 6a771ff692d1717967755cc56e4534a582dd117a /src/content | |
| parent | 9cb48c504ddb3882f39e2b17048f0593316a95ce (diff) | |
vfx pipeline
Diffstat (limited to 'src/content')
| -rw-r--r-- | src/content/entities/entity_bullet_emitter.rs | 17 | ||||
| -rw-r--r-- | src/content/mod.rs | 1 | ||||
| -rw-r--r-- | src/content/vfx/mod.rs | 29 |
3 files changed, 44 insertions, 3 deletions
diff --git a/src/content/entities/entity_bullet_emitter.rs b/src/content/entities/entity_bullet_emitter.rs index c014e8c..3788dd9 100644 --- a/src/content/entities/entity_bullet_emitter.rs +++ b/src/content/entities/entity_bullet_emitter.rs @@ -2,7 +2,7 @@ use glam::{IVec2, Vec2}; use rapier2d::dynamics::RigidBodyBuilder; use crate::{ - content::materials::MaterialId, + content::{materials::MaterialId, vfx::VfxMaterialId}, input::Input, sim::{ cell::Cell, @@ -10,6 +10,7 @@ use crate::{ lib::force::apply_bullet, sim_manager::SimCtx, }, + vfx::VfxLine, }; struct BulletEmitterEntityBehaviour { @@ -27,11 +28,21 @@ impl EntityBehaviour for BulletEmitterEntityBehaviour { if let Some(target) = self.target { let pos = update_ctx.entity_data.transform(ctx).unwrap().0; let dir = (target - pos).normalize(); + let from = pos + (dir * 4.0); self.shot_timer -= delta_time; if self.shot_timer <= 0.0 { - apply_bullet(ctx, pos + (dir * 4.0), target, 70); - self.shot_timer = 0.1; + apply_bullet(ctx, from, target, 70); + // 0.1 seconds to travel 200 cells + let lifetime = (target - from).length() / 1000.0; + ctx.vfx_writer.write_vfx_line(VfxLine::new( + from, + target, + 1.3, + VfxMaterialId::Tracer, + lifetime, + )); + self.shot_timer = 0.2; } self.life -= delta_time; diff --git a/src/content/mod.rs b/src/content/mod.rs index 2044048..ee2f47c 100644 --- a/src/content/mod.rs +++ b/src/content/mod.rs @@ -1,2 +1,3 @@ pub mod entities; pub mod materials; +pub mod vfx; diff --git a/src/content/vfx/mod.rs b/src/content/vfx/mod.rs new file mode 100644 index 0000000..8843bf1 --- /dev/null +++ b/src/content/vfx/mod.rs @@ -0,0 +1,29 @@ +#[repr(u8)] +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum VfxMaterialId { + Tracer = 0, +} + +pub struct VfxMaterialDef { + pub name: &'static str, + pub color: (u8, u8, u8, u8), + pub length: f32, +} + +static MATERIALS: [VfxMaterialDef; 1] = [VfxMaterialDef { + name: "Tracer", + color: (0xFF, 0xAA, 0xAA, 0xFF), + length: 15.0, +}]; + +impl VfxMaterialId { + pub const ALL: [VfxMaterialId; 1] = [VfxMaterialId::Tracer]; + #[inline] + pub fn def(self) -> &'static VfxMaterialDef { + &MATERIALS[self as usize] + } + + pub fn from_index(idx: u8) -> VfxMaterialId { + VfxMaterialId::ALL[idx as usize] + } +} |
