bevy_two_entities

Crates.iobevy_two_entities
lib.rsbevy_two_entities
version0.2.0
sourcesrc
created_at2024-05-16 20:03:26.408656
updated_at2024-07-04 19:01:33.504451
descriptionA few convenience traits for working with Bevy Queries
homepagehttps://github.com/rparrett/bevy_two_entities
repositoryhttps://github.com/rparrett/bevy_two_entities
max_upload_size
id1242428
size18,733
Rob Parrett (rparrett)

documentation

https://docs.rs/bevy_two_entities

README

bevy_two_entities

A tiny crate offering a few convenience traits on Bevy's Query and (&Query, &Query) for scenarios involving exactly two entities.

Examples

fn game_over(
    collisions: Query<&Collision>,
    players: Query<(), With<Player>>,
    enemies: Query<(), With<Enemy>>,
    mut next_state: ResMut<NextState<GameState>>,
) {
    for collision in &collisions {
        if (&players, &enemies).both(collision.0, collision.1) {
            next_state.set(GameState::GameOver);
        }
    }
}
fn damage_enemy(
    collisions: Query<&Collision>,
    players: Query<(), With<Player>>,
    mut enemies: Query<&mut HitPoints, With<Enemy>>,
) {
    for collision in &collisions {
        let mut queries = (&players, &mut enemies);
        let Some((_, mut enemy_hp)) = queries.get_both_mut(collision.0, collision.1) else {
            continue;
        };

        enemy_hp.0 -= 1;
    }
}

Compatibility

bevy_two_entities bevy
0.2 0.14
0.1 0.13
Commit count: 20

cargo fmt