fn collision_system(
    windows: Res<Windows>,
    mut query: Query<(&mut Velocity, &mut Transform), With<Contributor>>,
) {
    let mut rnd = rand::thread_rng();

    let window = windows.get_primary().unwrap();

    let ceiling = window.height() / 2.;
    let ground = -(window.height() / 2.);

    let wall_left = -(window.width() / 2.);
    let wall_right = window.width() / 2.;

    for (mut velocity, mut transform) in query.iter_mut() {
        let left = transform.translation.x - SPRITE_SIZE / 2.0;
        let right = transform.translation.x + SPRITE_SIZE / 2.0;
        let top = transform.translation.y + SPRITE_SIZE / 2.0;
        let bottom = transform.translation.y - SPRITE_SIZE / 2.0;

        // clamp the translation to not go out of the bounds
        if bottom < ground {
            transform.translation.y = ground + SPRITE_SIZE / 2.0;
            // apply an impulse upwards
            velocity.translation.y = rnd.gen_range(700.0..1000.0);
        }
        if top > ceiling {
            transform.translation.y = ceiling - SPRITE_SIZE / 2.0;
        }
        // on side walls flip the horizontal velocity
        if left < wall_left {
            transform.translation.x = wall_left + SPRITE_SIZE / 2.0;
            velocity.translation.x *= -1.0;
            velocity.rotation *= -1.0;
        }
        if right > wall_right {
            transform.translation.x = wall_right - SPRITE_SIZE / 2.0;
            velocity.translation.x *= -1.0;
            velocity.rotation *= -1.0;
        }
    }
}
/// Checks for collisions of contributor-birds.
///
/// On collision with left-or-right wall it resets the horizontal
/// velocity. On collision with the ground it applies an upwards
/// force.
Checks for collisions of contributor-birds.
On collision with left-or-right wall it resets the horizontal
velocity. On collision with the ground it applies an upwards
force.
Checks for collisions of contributor - birds . On collision with left - or - right wall it resets the horizontal velocity . On collision with the ground it applies an upwards force .
fn collision_system(
    windows: Res<Windows>,
    mut query: Query<(&mut Velocity, &mut Transform), With<Contributor>>,
) {
    let mut rnd = rand::thread_rng();
    let window = windows.get_primary().unwrap();
    let ceiling = window.height() / 2.;
    let ground = -(window.height() / 2.);
    let wall_left = -(window.width() / 2.);
    let wall_right = window.width() / 2.;
    for (mut velocity, mut transform) in query.iter_mut() {
        let left = transform.translation.x - SPRITE_SIZE / 2.0;
        let right = transform.translation.x + SPRITE_SIZE / 2.0;
        let top = transform.translation.y + SPRITE_SIZE / 2.0;
        let bottom = transform.translation.y - SPRITE_SIZE / 2.0;
        // clamp the translation to not go out of the bounds
        if bottom < ground {
            transform.translation.y = ground + SPRITE_SIZE / 2.0;
            // apply an impulse upwards
            velocity.translation.y = rnd.gen_range(700.0..1000.0);
        }
        if top > ceiling {
            transform.translation.y = ceiling - SPRITE_SIZE / 2.0;
        }
        // on side walls flip the horizontal velocity
        if left < wall_left {
            transform.translation.x = wall_left + SPRITE_SIZE / 2.0;
            velocity.translation.x *= -1.0;
            velocity.rotation *= -1.0;
        }
        if right > wall_right {
            transform.translation.x = wall_right - SPRITE_SIZE / 2.0;
            velocity.translation.x *= -1.0;
            velocity.rotation *= -1.0;
        }
    }
}
fn collision_system ( windows : Res < Windows > , mut query : Query < ( & mut Velocity , & mut Transform ) , With < Contributor > > , ) { let mut rnd = rand :: thread_rng ( ) ; let window = windows . get_primary ( ) . unwrap ( ) ; let ceiling = window . height ( ) / 2. ; let ground = - ( window . height ( ) / 2. ) ; let wall_left = - ( window . width ( ) / 2. ) ; let wall_right = window . width ( ) / 2. ; for ( mut velocity , mut transform ) in query . iter_mut ( ) { let left = transform . translation . x - SPRITE_SIZE / 2.0 ; let right = transform . translation . x + SPRITE_SIZE / 2.0 ; let top = transform . translation . y + SPRITE_SIZE / 2.0 ; let bottom = transform . translation . y - SPRITE_SIZE / 2.0 ; // clamp the translation to not go out of the bounds if bottom < ground { transform . translation . y = ground + SPRITE_SIZE / 2.0 ; // apply an impulse upwards velocity . translation . y = rnd . gen_range ( 700.0 .. 1000.0 ) ; } if top > ceiling { transform . translation . y = ceiling - SPRITE_SIZE / 2.0 ; } // on side walls flip the horizontal velocity if left < wall_left { transform . translation . x = wall_left + SPRITE_SIZE / 2.0 ; velocity . translation . x *= - 1.0 ; velocity . rotation *= - 1.0 ; } if right > wall_right { transform . translation . x = wall_right - SPRITE_SIZE / 2.0 ; velocity . translation . x *= - 1.0 ; velocity . rotation *= - 1.0 ; } } }
Checks for collisions of contributor-birds.
Checks for collisions of contributor - birds .
windows
Res<Windows>
query
Query<(&mut Velocity, &mut Transform), With<Contributor>>
windows
Res<Windows>
query
Query<(&mut Velocity, &mut Transform), With<Contributor>>