From 4ce1e606f98f5f87f7727cc768b3f97620266b78 Mon Sep 17 00:00:00 2001 From: Fabien JUIF Date: Sat, 11 Nov 2023 10:06:22 +0100 Subject: [PATCH] :sparkles: minion explosion visual --- src/minions.rs | 163 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 120 insertions(+), 43 deletions(-) diff --git a/src/minions.rs b/src/minions.rs index b2826d7..7872313 100644 --- a/src/minions.rs +++ b/src/minions.rs @@ -11,13 +11,18 @@ const MINION_SCALE: f32 = 190.; const DESTROY_MINIONS_AFTER_SECS: f32 = 120.; const DECAY_VALUE_PER_SEC: f32 = 10.; const REWARDS_GOLD: f32 = 1.; -const MINION_TOUCH_DAMAGE: f32 = 80.; pub struct MinionsPlugin; +// TODO: move this into common +#[derive(Component)] +struct TimeDestroyable { + timer: Timer, +} + #[derive(Component)] struct Minion { - destroy_timer: Timer, + had_exploded: bool, } impl Plugin for MinionsPlugin { @@ -26,7 +31,7 @@ impl Plugin for MinionsPlugin { Update, (update_move_minions, check_collisions_minions, decay_life), ) - .add_systems(PostUpdate, destroy_minions); + .add_systems(PostUpdate, (destroy_minions, destroy_after_timer)); } } @@ -43,6 +48,7 @@ pub struct MinionBundle { body: RigidBody, collider: Collider, events: ActiveEvents, + timer_destroyable: TimeDestroyable, } impl MinionBundle { @@ -70,12 +76,7 @@ impl MinionBundle { // ..default() // }, minion: Minion { - // to avoid leaks - // maybe a better option on top of that is to leach health every seconds on minions and make them die! - destroy_timer: Timer::from_seconds( - DESTROY_MINIONS_AFTER_SECS, - bevy::time::TimerMode::Once, - ), + had_exploded: false, }, health: Health::new(20.) .with_health_bar_position(Vec3::new(0.0, 15.0, 0.1)) @@ -86,6 +87,48 @@ impl MinionBundle { body: RigidBody::Dynamic, collider: Collider::ball(6.), events: ActiveEvents::COLLISION_EVENTS, + timer_destroyable: TimeDestroyable { + timer: Timer::from_seconds(DESTROY_MINIONS_AFTER_SECS, bevy::time::TimerMode::Once), + }, + } + } +} + +#[derive(Component)] +struct Explosion; + +#[derive(Bundle)] +struct ExplosionBundle { + mesh: MaterialMesh2dBundle, + explosion: Explosion, + team: Team, + sensor: Sensor, + collider: Collider, + timer_destroyable: TimeDestroyable, +} + +impl ExplosionBundle { + pub fn new( + meshes: &mut ResMut>, + materials: &mut ResMut>, + translation: Vec3, + team: Team, + ) -> Self { + let radius = 20.; + ExplosionBundle { + mesh: MaterialMesh2dBundle { + mesh: meshes.add(shape::Circle::new(radius).into()).into(), + material: materials.add(ColorMaterial::from(team.color)), + transform: Transform::from_translation(translation), + ..default() + }, + explosion: Explosion, + team, + collider: Collider::ball(radius), + sensor: Sensor, + timer_destroyable: TimeDestroyable { + timer: Timer::from_seconds(0.5, bevy::time::TimerMode::Once), + }, } } } @@ -147,16 +190,14 @@ fn update_move_minions( } fn destroy_minions( - time: Res