Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WASD keys and speed variable #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions snake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare -i height=$(($(tput lines)-5)) width=$(($(tput cols)-2))
# row and column number of head
declare -i head_r head_c tail_r tail_c

declare -i alive
declare -i alive
declare -i length
declare body

Expand All @@ -27,6 +27,7 @@ SIG_DOWN=URG
SIG_LEFT=IO
SIG_QUIT=WINCH
SIG_DEAD=HUP
SPEED=0.03

# direction arrays: 0=up, 1=right, 2=down, 3=left
move_r=([0]=-1 [1]=0 [2]=1 [3]=0)
Expand Down Expand Up @@ -200,13 +201,13 @@ getchar() {
[qQ]) kill -$SIG_QUIT $game_pid
return
;;
[kK]) kill -$SIG_UP $game_pid
[kKwW]) kill -$SIG_UP $game_pid
;;
[lL]) kill -$SIG_RIGHT $game_pid
[lLdD]) kill -$SIG_RIGHT $game_pid
;;
[jJ]) kill -$SIG_DOWN $game_pid
[jJsS]) kill -$SIG_DOWN $game_pid
;;
[hH]) kill -$SIG_LEFT $game_pid
[hHaA]) kill -$SIG_LEFT $game_pid
;;
esac
done
Expand All @@ -227,9 +228,9 @@ game_loop() {
fi
move_snake
draw_board
sleep 0.03
sleep $SPEED
done

echo -e "${text_color}Oh, No! You 0xdead$no_color"

# signals the input loop that the snake is dead
Expand Down