use glam::Vec2; use crate::sim::{ entity::{EntityBehaviour, EntityDef, EntityUpdateCtx}, lib::force::apply_explosion, sim_manager::SimCtx, }; struct TntEntityBehaviour { pub fuse: f32, } impl EntityBehaviour for TntEntityBehaviour { 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, 35, Vec2::new(0.0, -0.6), 400.0, ); update_ctx.deferred_destroy(update_ctx.entity_data.id); } } } pub fn entity_tnt_def(position: Vec2) -> EntityDef { EntityDef::from_sprite( position, "assets/sprites/tnt", Some(Box::new(TntEntityBehaviour { fuse: 3.0 })), ) }