5 IFS="," read -u 3 -a instructions
9 basedir=$(dirname $(readlink -f ${BASH_SOURCE}))
11 . $basedir/computer.sh
16 coproc computer (run_program instructions 2>computer_output.txt)
18 comp_pid=${computer_PID}
19 comp_stdin=${computer[1]}
20 comp_stdout=${computer[0]}
29 where_paddle_should_be_x=0
31 get_joystick_direction() {
32 if [ $ball_dir_left -eq -2 ]; then
37 if [ $paddle_x -lt $ball_x ]; then
39 elif [ $paddle_x -gt $ball_x ]; then
41 elif [ $paddle_x -eq $ball_x ]; then
45 echo "Where we think the paddle should be: $where_ball_will_be_on_paddle_line" >&4
46 echo "Where we are: $paddle_x,$paddle_y" >&4
47 echo "Where the ball is: $ball_x, $ball_y" >&4
48 echo "Direction of ball: $ball_dir_left,$ball_dir_up" >&4
49 echo "Direction of paddle: $paddle_dir" >&4
63 # work out if we're going up or down
65 if [ $x -gt $ball_x ]; then
67 elif [ $x -lt $ball_x ]; then
73 if [ $y -gt $ball_y ]; then
75 elif [ $y -lt $ball_y ]; then
87 while ps -p $comp_pid >/dev/null 2>/dev/null; do
88 read -u $comp_stdout x || break
89 if [ $x == "input:" ]; then
90 echo "$(get_joystick_direction)" >&$comp_stdin
91 continue # go back to main loop
94 if [ "x$x" == "xinput: " ]; then
97 read -u $comp_stdout y || break
99 read -u $comp_stdout z || break
104 update_paddle_pos $x $y
107 update_ball_pos $x $y
111 if [ $x -eq -1 ]; then
112 update_score_board $z
115 arcade_screen_update $x $y $z