jcornaz / heron

[DISCONTINUED] An ergonomic physics API for bevy games
MIT License
292 stars 44 forks source link

Query utility for events #19

Closed jcornaz closed 2 years ago

jcornaz commented 3 years ago

As a User, I want an easy way to query for components of the entities involved in a collision, so that it is easier to read/update components as part of the reaction to the event.

Here is how usage could look like:

fn damage_system(
  mut event_reader: Local<EventReader<CollisionEvent>>,
  events: Res<Events<CollisionEvent>>,
  mut damageables: Query<&mut Hp>,
  bullets: Query<Bullet>,
) {
  event_reader.iter(events)
    .flat_map(|event| event.query(&mut damageables, &bullets))
    .for_each(|(mut hp, bullet)| {
       hp.take_dmg(bullet.dmg());
    });
}
jcornaz commented 2 years ago

Closing in favor of #207