|
|
@ -2,24 +2,34 @@ |
|
|
|
|
|
|
|
|
|
|
|
_STTY=$(stty -g) # Save current terminal setup |
|
|
|
#printf "\e[2J" # clear screen, set cursos at beginning |
|
|
|
printf "\e[2J" # clear screen, set cursos at beginning |
|
|
|
stty -echo -icanon # Turn off line buffering |
|
|
|
printf '\e[?25h' |
|
|
|
|
|
|
|
# VARIABLES |
|
|
|
typeset -A IMAGE |
|
|
|
X=0 |
|
|
|
Y=24 |
|
|
|
height=0 |
|
|
|
width=0 |
|
|
|
snake='═' |
|
|
|
|
|
|
|
vertical=false |
|
|
|
forward=true |
|
|
|
upward=true |
|
|
|
|
|
|
|
function get_size() { |
|
|
|
# Get terminal size ('stty' is POSIX and always available). |
|
|
|
read -r LINES COLUMNS < <(stty size) |
|
|
|
height=$((LINES-1)) |
|
|
|
width=$((COLUMNS-1)) |
|
|
|
} |
|
|
|
|
|
|
|
function start_the_snake() { |
|
|
|
rm thesnake |
|
|
|
for i in {0..29} |
|
|
|
for i in {0..$height} |
|
|
|
do |
|
|
|
for j in {0..79} |
|
|
|
for j in {0..$width} |
|
|
|
do |
|
|
|
IMAGE["${i};${j}"]=' ' ; printf ${IMAGE["${i};${j}"]} |
|
|
|
done |
|
|
@ -27,20 +37,21 @@ function start_the_snake() { |
|
|
|
} |
|
|
|
|
|
|
|
function save_the_snake() { |
|
|
|
for i in {0..29} |
|
|
|
for i in {0..$height} |
|
|
|
do |
|
|
|
for j in {0..79} |
|
|
|
for j in {0..$width} |
|
|
|
do |
|
|
|
printf ${IMAGE["${i};${j}"]} |
|
|
|
done |
|
|
|
done >> thesnake |
|
|
|
#sed -e "s/.\{$((width-1))\}/&\n/g" < thesnake > snake80 |
|
|
|
} |
|
|
|
|
|
|
|
function show_the_snake() { |
|
|
|
clear |
|
|
|
for i in {0..29} |
|
|
|
printf '\e[2J\e[H' |
|
|
|
for i in {0..$height} |
|
|
|
do |
|
|
|
for j in {0..79} |
|
|
|
for j in {0..$width} |
|
|
|
do |
|
|
|
printf ${IMAGE["${i};${j}"]} |
|
|
|
done |
|
|
@ -110,6 +121,7 @@ function move_snake_backward() { |
|
|
|
} |
|
|
|
|
|
|
|
# Main # |
|
|
|
get_size |
|
|
|
start_the_snake |
|
|
|
while read -s -k 1 cr; |
|
|
|
do |
|
|
@ -117,7 +129,7 @@ do |
|
|
|
w) move_snake_up ; show_the_snake ;; |
|
|
|
s) move_snake_down ; show_the_snake ;; |
|
|
|
a) move_snake_backward ; show_the_snake ;; |
|
|
|
d) move_snake_forward ; show_the_snake ;; |
|
|
|
d) move_snake_forward ; show_the_snake ;; |
|
|
|
q) save_the_snake && at_exit ;; |
|
|
|
esac |
|
|
|
done |
|
|
|