Permalink
Browse files

Go readability is best readability

  • Loading branch information...
1 parent a5a9254 commit f2683785a8049fc385e5c6705f66dbb835ad84bc @Xion committed Aug 22, 2016
Showing with 17 additions and 16 deletions.
  1. +16 −15 flappybash.sh
  2. +1 −1 minify.py
View
@@ -10,14 +10,14 @@ H2=$[H/2]
H4=$[H/4]
DT=0.05 # 20 FPS
-G=2 # minimum height of pipe gap (is double this number)
+G=2 # minimum height of the pipe gap (is double this number)
KEY=. # last pressed key (dot is ignored)
X=2
Y=$H2
VY=0 # vertical velocity
AY=100 # vertical acceleration
-DEAD=0
+D=0
# current pipe is stored as an array of $H chars
P=( ) # start as empty array
PX='' # pipe's current X
@@ -42,7 +42,7 @@ tick() {
# the -le check below is bad and I should feel bad, but doing it properly
# (i.e. keeping previous and current value of PX, and checking if X is in between)
# probably won't fit within the limit; oh well, maybe I'll try that later
- if [ $PX -le $X ] && [ ${P[tY]} = '#' ]; then DEAD=1; exit; fi
+ if [ $PX -le $X ] && [ ${P[tY]} = '#' ]; then D=1; exit; fi
if [ $PX -le 0 ]; then S=$[S+1]; np; fi
# Draw
@@ -52,45 +52,46 @@ tick() {
# draw the pipe
for ((i=1; i<=$H; i++)); do
- echo -en "\e[$i;${PX}f\e[1;32;49m${P[i]}" # bold green-on-default
+ p $PX $i "\e[1;32;49m${P[i]}" # bold green-on-default
done
# draw the player
- echo -en "\e[$tY;${X}f\e[1;37;41mB" # bold white-on-red
+ p $X $tY "\e[1;37;41mB" # bold white-on-red
# draw the score
- echo -en "\e[2;`_ "$W2-5"`f\e[1;37;49mScore: $S" # bold white-on-default
+ p `_ "$W2-5"` 2 "\e[1;37;49mScore: $S" # bold white-on-default
# schedule the next call of this function
( sleep $DT; kill -ALRM $$ ) &
}
-# create a new pipe and place it all the way to right
+# create a new pipe and place it all the way to the right
np() {
- local u=$[H4+RANDOM % (H2-H4-G)] # upper pipe is < this coordinate
- local l=$[H2+G+RANDOM % (H2-H4-G)] # lower pipe is >= this one
+ _u=$[H4+RANDOM%(H2-H4-G)] # upper pipe is < this coordinate
+ _l=$[H2+G+RANDOM%(H2-H4-G)] # lower pipe is >= this one
- for ((i=1; i<$u; i++)) do P[i]='#'; done
- for ((i=$u; i<$l; i++)) do P[i]=' '; done
- for ((i=$l; i<=$H; i++)) do P[i]='#'; done
+ for ((i=1; i<$_u; i++)) do P[i]='#'; done
+ for ((i=$_u; i<$_l; i++)) do P[i]=' '; done
+ for ((i=$_l; i<=$H; i++)) do P[i]='#'; done
PX=$[W-1] # start from the right side
}
quit() {
- trap : ALRM
printf "\e[?12l\e[?25h" # cursor on
tput rmcup
echo -en "\e[0m"
clear
- if [ $DEAD -gt 0 ]; then printf "score:$S (diff:-$W)\ngit gud\n"; fi
+ if [ $D -gt 0 ]; then printf "score:$S (diff:-$W)\ngit gud\n"; fi
exit
}
+# put text at given position: p $x $y $text
+p() { echo -en "\e[$2;${1}f$3"; }
# wrapper over bc (basic POSIX calculator) that makes all computations shorter
_() { echo "$*" | bc; }
# truncate fractional part
-t() { printf "%.*f" 0 "$1"; }
+t() { printf "%.*f" 0 $1; }
#
View
@@ -37,7 +37,7 @@ def main(argv):
r';(\w+)\(\)', lambda m: '; %s()' % m.group(1), minified)
minified = minified.replace('&;}', '&}')
- print("#!/bin/bash")
+ print(source.splitlines()[0]) # copy the original shebang
print(minified)

0 comments on commit f268378

Please sign in to comment.