summaryrefslogtreecommitdiff
path: root/src/sim/entity/entities/entity_grenade.rs
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2026-08-22 17:52:57 -0700
committerKai Stevenson <kai@kaistevenson.com>2026-08-22 17:52:57 -0700
commit020a67107b0fb78f053fa9f45205c093dfbaaeb3 (patch)
tree1e970cba6f94e053db284a8394b9a9790a359f77 /src/sim/entity/entities/entity_grenade.rs
parentbdad89910dcf3a56790dba60ed1f0db679432323 (diff)
entity behavour, grenades
Diffstat (limited to 'src/sim/entity/entities/entity_grenade.rs')
-rw-r--r--src/sim/entity/entities/entity_grenade.rs64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/sim/entity/entities/entity_grenade.rs b/src/sim/entity/entities/entity_grenade.rs
new file mode 100644
index 0000000..eead416
--- /dev/null
+++ b/src/sim/entity/entities/entity_grenade.rs
@@ -0,0 +1,64 @@
+use glam::{IVec2, Vec2};
+
+use crate::sim::{
+ cell::{cell::Cell, materials::MaterialId},
+ entity::{EntityBehaviour, EntityCells, EntityDef, EntityUpdateCtx, SimCtx},
+ lib::force::apply_explosion,
+};
+
+struct GrenadeEntityBehaviour {
+ pub fuse: f32,
+}
+
+impl EntityBehaviour for GrenadeEntityBehaviour {
+ fn physics_update(
+ &mut self,
+ _update_ctx: &mut EntityUpdateCtx,
+ _ctx: &mut SimCtx,
+ _delta_time: f32,
+ ) -> () {
+ }
+ fn update(
+ &mut self,
+ update_ctx: &mut EntityUpdateCtx,
+ ctx: &mut SimCtx,
+ delta_time: f32,
+ ) -> () {
+ self.fuse -= delta_time;
+ if self.fuse <= 0.0 {
+ apply_explosion(
+ ctx,
+ update_ctx.entity_data.transform(ctx).unwrap().0,
+ 15,
+ Vec2::new(0.0, -0.6),
+ 200.0,
+ );
+ update_ctx.deferred_destroy(update_ctx.entity_data.id);
+ }
+ }
+}
+
+pub fn entity_grenade_def(position: Vec2, fuse: f32) -> EntityDef {
+ let w = 3;
+ let h = 3;
+ let mut raw_cells = vec![Cell::void(); (w * h) as usize];
+
+ for x in 0..w {
+ for y in 0..h {
+ let cell_idx = x + y * w;
+ raw_cells[cell_idx as usize] = Cell::from_material(MaterialId::Wood);
+ raw_cells[cell_idx as usize].set_entity(true);
+ }
+ }
+
+ let entity_cells = EntityCells {
+ cells: raw_cells,
+ size: IVec2::new(w, h),
+ };
+
+ EntityDef::from_cells(
+ position,
+ entity_cells,
+ Some(Box::new(GrenadeEntityBehaviour { fuse })),
+ )
+}