Browse Source

added support for different size of terminal

main
crunk 5 years ago
parent
commit
9af0edf8f5
  1. 8
      readme.md
  2. 28
      snakelogan

8
readme.md

@ -2,5 +2,11 @@
the cursive plaintext snake writer
* new so it still works pretty bad
* you need your terminal to 80 characters wide and 30 characters high.
* now support for any size of terminal
* use w,s,a,d to move the snake use q to exit and save the snake
toekomstmuziek:
* build a more TUI like interface where we don't clear the screen
* removing the flasing effect while drawing.
* put a blinking cursor where the snake currently is
* implement pen-up and pen-down

28
snakelogan

@ -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

Loading…
Cancel
Save