     key-s keys nth [ player walk-backward ] when 
     key-a keys nth [ player walk-leftward ] when 
     key-d keys nth [ player walk-rightward ] when 
+    key-left-arrow keys nth [ player -1 look-horizontally ] when 
+    key-right-arrow keys nth [ player 1 look-horizontally ] when 
+    key-down-arrow keys nth [ player -1 look-vertically ] when 
+    key-up-arrow keys nth [ player 1 look-vertically ] when 
     key-space keys nth [ player jump ] when 
     key-escape keys nth [ world close-window ] when
     player read-mouse rotate-with-mouse

: walk-rightward ( player -- )
    dup rightward-vector [ v+ ] curry change-velocity drop ;
: jump ( player -- )
    [ { 0.0 $ JUMP 0.0 } v+ ] change-velocity drop ;

: clamp-pitch ( pitch -- pitch' )
    90.0 min -90.0 max ;

: rotate-with-mouse ( player mouse -- )
    [ dx>> MOUSE-SCALE * [ + ] curry change-yaw ]
    [ dy>> MOUSE-SCALE * [ + clamp-pitch ] curry change-pitch ] bi
    drop ;

:: handle-input ( world -- )
    world player>> :> player


: forward-vector ( player -- v )
    yaw>> 0.0
    ${ 0.0 0.0 MOVEMENT-SPEED } vneg eye-rotate ;
: rightward-vector ( player -- v )
    yaw>> 0.0
    ${ MOVEMENT-SPEED 0.0 0.0 } eye-rotate ;
: clamp-pitch ( pitch -- pitch' )
    90.0 min -90.0 max ;


: walk-forward ( player -- )
    dup forward-vector [ v+ ] curry change-velocity drop ;
