summaryrefslogtreecommitdiff
path: root/src/content/entities/entity_tnt.rs
blob: 595ebd4c27384cd3409bd7c96845421a5b861f5b (plain)
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
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 })),
    )
}