1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
use glam::{IVec2, Vec2};
use crate::{
sim::{
entity::{EntityBehaviour, EntityCells, EntityDef, EntityUpdateCtx},
lib::force::apply_explosion,
sim_manager::SimCtx,
},
sprite_loader::load_sprite_to_cells,
};
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 {
let sprite_cells = load_sprite_to_cells("assets/sprites/tnt");
let entity_cells = EntityCells {
cells: sprite_cells.cells,
size: IVec2::new(sprite_cells.width as i32, sprite_cells.height as i32),
};
EntityDef::from_cells(
position,
entity_cells,
Some(Box::new(TntEntityBehaviour { fuse: 3.0 })),
)
}
|