Skip to content

Commit e3f2942

Browse files
authored
Merge pull request #262 from ryanbreen/fix/bounce-speed-scaling
fix: proportional speed scaling for +/- keys in bounce demo
2 parents fe8b224 + f5e1176 commit e3f2942

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

userspace/programs/src/bounce.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,18 @@ fn run_window_loop(win: &mut Window, spheres: &mut [Sphere; NUM_SPHERES]) {
432432
Event::KeyPress { ascii, .. } => {
433433
match ascii {
434434
b'+' | b'=' => {
435-
for sphere in spheres.iter_mut() { sphere.impel(); }
435+
// Scale all velocities up by ~15%
436+
for sphere in spheres.iter_mut() {
437+
sphere.vx = sphere.vx * 23 / 20;
438+
sphere.vy = sphere.vy * 23 / 20;
439+
}
436440
}
437441
b'-' => {
438-
for sphere in spheres.iter_mut() { sphere.dampen(); }
442+
// Scale all velocities down by ~15%
443+
for sphere in spheres.iter_mut() {
444+
sphere.vx = sphere.vx * 20 / 23;
445+
sphere.vy = sphere.vy * 20 / 23;
446+
}
439447
}
440448
_ => {}
441449
}

0 commit comments

Comments
 (0)