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

    let win = wins.get_primary().unwrap();

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

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

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

        // clamp the translation to not go out of the bounds
        if bottom < ground {
            t.translation.y = ground + SPRITE_SIZE / 2.0;
            // apply an impulse upwards
            v.translation.y = rnd.gen_range(700.0..1000.0);
        }
        if top > ceiling {
            t.translation.y = ceiling - SPRITE_SIZE / 2.0;
        }
        // on side walls flip the horizontal velocity
        if left < wall_left {
            t.translation.x = wall_left + SPRITE_SIZE / 2.0;
            v.translation.x *= -1.0;
            v.rotation *= -1.0;
        }
        if right > wall_right {
            t.translation.x = wall_right - SPRITE_SIZE / 2.0;
            v.translation.x *= -1.0;
            v.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(
    wins: Res<Windows>,
    mut q: Query<(&mut Velocity, &mut Transform), With<Contributor>>,
) {
    let mut rnd = rand::thread_rng();
    let win = wins.get_primary().unwrap();
    let ceiling = win.height() / 2.;
    let ground = -(win.height() / 2.);
    let wall_left = -(win.width() / 2.);
    let wall_right = win.width() / 2.;
    for (mut v, mut t) in q.iter_mut() {
        let left = t.translation.x - SPRITE_SIZE / 2.0;
        let right = t.translation.x + SPRITE_SIZE / 2.0;
        let top = t.translation.y + SPRITE_SIZE / 2.0;
        let bottom = t.translation.y - SPRITE_SIZE / 2.0;
        // clamp the translation to not go out of the bounds
        if bottom < ground {
            t.translation.y = ground + SPRITE_SIZE / 2.0;
            // apply an impulse upwards
            v.translation.y = rnd.gen_range(700.0..1000.0);
        }
        if top > ceiling {
            t.translation.y = ceiling - SPRITE_SIZE / 2.0;
        }
        // on side walls flip the horizontal velocity
        if left < wall_left {
            t.translation.x = wall_left + SPRITE_SIZE / 2.0;
            v.translation.x *= -1.0;
            v.rotation *= -1.0;
        }
        if right > wall_right {
            t.translation.x = wall_right - SPRITE_SIZE / 2.0;
            v.translation.x *= -1.0;
            v.rotation *= -1.0;
        }
    }
}
fn collision_system ( wins : Res < Windows > , mut q : Query < ( & mut Velocity , & mut Transform ) , With < Contributor > > , ) { let mut rnd = rand :: thread_rng ( ) ; let win = wins . get_primary ( ) . unwrap ( ) ; let ceiling = win . height ( ) / 2. ; let ground = - ( win . height ( ) / 2. ) ; let wall_left = - ( win . width ( ) / 2. ) ; let wall_right = win . width ( ) / 2. ; for ( mut v , mut t ) in q . iter_mut ( ) { let left = t . translation . x - SPRITE_SIZE / 2.0 ; let right = t . translation . x + SPRITE_SIZE / 2.0 ; let top = t . translation . y + SPRITE_SIZE / 2.0 ; let bottom = t . translation . y - SPRITE_SIZE / 2.0 ; // clamp the translation to not go out of the bounds if bottom < ground { t . translation . y = ground + SPRITE_SIZE / 2.0 ; // apply an impulse upwards v . translation . y = rnd . gen_range ( 700.0 .. 1000.0 ) ; } if top > ceiling { t . translation . y = ceiling - SPRITE_SIZE / 2.0 ; } // on side walls flip the horizontal velocity if left < wall_left { t . translation . x = wall_left + SPRITE_SIZE / 2.0 ; v . translation . x *= - 1.0 ; v . rotation *= - 1.0 ; } if right > wall_right { t . translation . x = wall_right - SPRITE_SIZE / 2.0 ; v . translation . x *= - 1.0 ; v . rotation *= - 1.0 ; } } }
Checks for collisions of contributor-birds.
Checks for collisions of contributor - birds .
wins
Res<Windows>
q
Query<(&mut Velocity, &mut Transform), With<Contributor>>
wins
Res<Windows>
q
Query<(&mut Velocity, &mut Transform), With<Contributor>>