//! This example shows how to send, mutate, and receive, events. As well as showing //! how to you might control system ordering so that events are processed in a specific order. //! It does this by simulating a damage over time effect that you might find in a game. use bevy::prelude::*; // In order to send or receive events first you must define them // This event should be sent when something attempts to deal damage to another entity. #[derive(Event, Debug)] struct DealDamage { pub amount: i32, } // This event should be sent when an entity receives damage. #[derive(Event, Debug, Default)] struct DamageReceived; // This event should be sent when an entity blocks damage with armor. #[derive(Event, Debug, Default)] struct ArmorBlockedDamage; // This resource represents a timer used to determine when to deal damage // By default it repeats once per second #[derive(Resource, Deref, DerefMut)] struct DamageTimer(pub Timer); impl Default for DamageTimer { fn default() -> Self { DamageTimer(Timer::from_seconds(1.0, TimerMode::Repeating)) } } // Next we define systems that send, mutate, and receive events // This system reads 'DamageTimer', updates it, then sends a 'DealDamage' event // if the timer has finished. // // Events are sent using an 'EventWriter' by calling 'send' or 'send_default'. // The 'send_default' method will send the event with the default value if the event // has a 'Default' implementation. fn deal_damage_over_time( time: Res