@@ -33,32 +33,41 @@ fn logic(game_state: &mut Engine, _: &mut ()) {
3333
3434 // Handle keyboard input
3535 let ks = & mut game_state. keyboard_state ;
36+ if ks. pressed_any ( & [ KeyCode :: A , KeyCode :: Left ] ) {
37+ race_car. translation . x -= move_amount;
38+ }
39+ if ks. pressed_any ( & [ KeyCode :: D , KeyCode :: Right , KeyCode :: E ] ) {
40+ race_car. translation . x += move_amount;
41+ }
42+ if ks. pressed_any ( & [ KeyCode :: O , KeyCode :: Down , KeyCode :: S ] ) {
43+ race_car. translation . y -= move_amount;
44+ }
45+ if ks. pressed_any ( & [ KeyCode :: W , KeyCode :: Up , KeyCode :: Comma ] ) {
46+ race_car. translation . y += move_amount;
47+ }
48+ if ks. pressed_any ( & [ KeyCode :: Z , KeyCode :: Semicolon ] ) {
49+ race_car. rotation += rotation_amount;
50+ }
51+ if ks. pressed_any ( & [ KeyCode :: C , KeyCode :: J ] ) {
52+ race_car. rotation -= rotation_amount;
53+ }
54+ if ks. pressed_any ( & [ KeyCode :: Plus , KeyCode :: Equals ] ) {
55+ race_car. scale *= 1.0 + scale_amount;
56+ }
57+ if ks. pressed_any ( & [ KeyCode :: Minus , KeyCode :: Underline ] ) {
58+ race_car. scale *= 1.0 - scale_amount;
59+ }
3660
37- ks //
38- . pressed_any_do ( & [ KeyCode :: A , KeyCode :: Left ] , |_| {
39- race_car. translation . x -= move_amount;
40- } )
41- . pressed_any_do ( & [ KeyCode :: D , KeyCode :: Right , KeyCode :: E ] , |_| {
42- race_car. translation . x += move_amount;
43- } )
44- . pressed_any_do ( & [ KeyCode :: O , KeyCode :: Down , KeyCode :: S ] , |_| {
45- race_car. translation . y -= move_amount;
46- } )
47- . pressed_any_do ( & [ KeyCode :: W , KeyCode :: Up , KeyCode :: Comma ] , |_| {
48- race_car. translation . y += move_amount;
49- } )
50- . pressed_any_do ( & [ KeyCode :: Z , KeyCode :: Semicolon ] , |_| {
51- race_car. rotation += rotation_amount;
52- } )
53- . pressed_any_do ( & [ KeyCode :: C , KeyCode :: J ] , |_| {
54- race_car. rotation -= rotation_amount;
55- } )
56- . pressed_any_do ( & [ KeyCode :: Plus , KeyCode :: Equals ] , |_| {
57- race_car. scale *= 1.0 + scale_amount;
58- } )
59- . pressed_any_do ( & [ KeyCode :: Minus , KeyCode :: Underline ] , |_| {
60- race_car. scale *= 1.0 - scale_amount;
61- } ) ;
61+ // If you prefer a more functional style, there are also methods ending in `_do` that accept a
62+ // closure to perform your logic with and are chainable, like this:
63+ //
64+ // ks.pressed_any_do(&[KeyCode::A, KeyCode::Left], |_| {
65+ // race_car.translation.x -= move_amount;
66+ // })
67+ // .pressed_any_do(&[KeyCode::D, KeyCode::Right, KeyCode::E], |_| {
68+ // race_car.translation.x += move_amount;
69+ // })
70+ // ...etc
6271
6372 // Clamp the scale to a certain range so the scaling is reasonable
6473 race_car. scale = race_car. scale . clamp ( 0.1 , 3.0 ) ;
0 commit comments