An experimental, status effects-as-entities system for Bevy.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update decaying speed auto plugin example to match.

+31 -7
+2 -2
examples/immediate_stats/decaying_speed.rs
··· 51 51 mode: EffectMode::Insert, // Block having multiple of effect stacked on a single target. 52 52 lifetime: Some(Lifetime::from_seconds(2.0)), // The duration of the effect. 53 53 bundle: DecayingSpeed { 54 - // Start with double move speed. 55 54 start_speed_boost: Modifier { 56 - bonus: 20, 55 + bonus: 10, 57 56 multiplier: 2.0, 58 57 }, 59 58 }, ··· 80 79 } 81 80 } 82 81 82 + /// Updates the UI to match thw world state. 83 83 fn update_ui( 84 84 mut ui: Single<&mut Text>, 85 85 target: Single<&MovementSpeed>,
+29 -5
examples/immediate_stats/decaying_speed_auto_plugin.rs
··· 25 25 #[auto_component(plugin = DecayingSpeedPlugin)] 26 26 struct MovementSpeed(Stat); 27 27 28 - /// Applies a 2x speed boost, which decreases throughout its duration. 28 + /// Applies a speed boost, which decreases throughout its duration. 29 29 #[derive(Component, Default)] 30 30 struct DecayingSpeed { 31 31 start_speed_boost: Modifier, ··· 35 35 #[auto_system(plugin = DecayingSpeedPlugin, schedule = Startup)] 36 36 fn init_scene(mut commands: Commands) { 37 37 commands.spawn((Name::new("Target"), MovementSpeed(Stat::new(100)))); 38 + commands.spawn(Text::default()); 39 + commands.spawn(Camera2d); 38 40 } 39 41 40 42 /// When space is pressed, apply decaying speed to the target. ··· 48 50 return; 49 51 } 50 52 51 - info!("Applying Effect"); 52 53 commands.entity(*target).with_effect(EffectBundle { 53 54 mode: EffectMode::Insert, // Block having multiple of effect stacked on a single target. 54 55 lifetime: Some(Lifetime::from_seconds(2.0)), // The duration of the effect. 55 56 bundle: DecayingSpeed { 56 - // Start with double move speed. 57 - start_speed_boost: Modifier::from_multiplier(2.0), 57 + start_speed_boost: Modifier { 58 + bonus: 10, 59 + multiplier: 2.0, 60 + }, 58 61 }, 59 62 ..default() 60 63 }); ··· 77 80 effect.start_speed_boost, 78 81 lifetime.timer.fraction_remaining(), 79 82 ); 83 + } 84 + } 80 85 81 - info!("The target now has {} movement speed.", speed.0.total()); 86 + /// Updates the UI to match thw world state. 87 + #[auto_system(plugin = DecayingSpeedPlugin, schedule = PostUpdate)] 88 + fn update_ui( 89 + mut ui: Single<&mut Text>, 90 + target: Single<&MovementSpeed>, 91 + effects: Query<(Entity, &Lifetime, &DecayingSpeed)>, 92 + ) { 93 + ui.0 = "Press Space to apply decaying movement speed\n\n".to_string(); 94 + 95 + ui.0 += &format!("Speed: {:.1} ({:.1})\n\n", target.0.total(), target.0); 96 + 97 + for (entity, lifetime, speed) in &effects { 98 + ui.0 += &format!( 99 + "{} - {:.1}s ({:.1})\n", 100 + entity, 101 + lifetime.timer.remaining_secs(), 102 + speed 103 + .start_speed_boost 104 + .scaled(lifetime.timer.fraction_remaining()) 105 + ); 82 106 } 83 107 }