Permalink
Browse files

upgrade to new version of Crysis Engine

  • Loading branch information...
1 parent f268378 commit 3f259418f3d6167492b7d849c659dfcee0c6aa3d @Xion committed Aug 22, 2016
Showing with 45 additions and 28 deletions.
  1. +44 −27 flappybash.sh
  2. +1 −1 minify.py
View
@@ -12,7 +12,7 @@ H4=$[H/4]
DT=0.05 # 20 FPS
G=2 # minimum height of the pipe gap (is double this number)
-KEY=. # last pressed key (dot is ignored)
+K=. # last pressed key (dot is ignored)
X=2
Y=$H2
VY=0 # vertical velocity
@@ -21,18 +21,19 @@ D=0
# current pipe is stored as an array of $H chars
P=( ) # start as empty array
PX='' # pipe's current X
-PVX='-100'
+PVX=-100
S=0 # score
-tick() {
+# update & draw, called every $DT seconds
+a() {
# Update
########
- case "$KEY" in
+ case "$K" in
q) exit ;;
- *[!\ ]*) ;; # non-space
- *) VY='-60'; KEY=. ;; # space
+ *[!\ ]*) ;; # non-space
+ *) VY='-60'; K=. ;; # space
esac
VY=`_ "$VY+($AY*$DT)"`
@@ -41,9 +42,13 @@ tick() {
PX=`_ "$PX+($PVX*$DT)"`; PX=`t $PX`
# 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 D=1; exit; fi
- if [ $PX -le 0 ]; then S=$[S+1]; np; fi
+ # won't fit within the limit
+ if [ $PX -le $X ] && [ ${P[tY]} = '' ]; then D=1; exit; fi
+ if [ $PX -le 0 ]; then
+ ( s 700 0.1; s 350 0.1 )& # be-boop
+ S=$[S+1]
+ np
+ fi
# Draw
######
@@ -62,52 +67,64 @@ tick() {
p `_ "$W2-5"` 2 "\e[1;37;49mScore: $S" # bold white-on-default
# schedule the next call of this function
- ( sleep $DT; kill -ALRM $$ ) &
+ ( sleep $DT; kill -14 $$ )&
}
# create a new pipe and place it all the way to the right
np() {
_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=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=$_l; i<=$H; i++)) do P[i]=''; done
PX=$[W-1] # start from the right side
}
-quit() {
- printf "\e[?12l\e[?25h" # cursor on
+# cleanup and exit
+q() {
+ $p "\e[?12l\e[?25h" # cursor on
tput rmcup
- echo -en "\e[0m"
+ $e -en "\e[0m"
clear
- if [ $D -gt 0 ]; then printf "score:$S (diff:-$W)\ngit gud\n"; fi
- exit
+
+ # handle failure
+ if [ $D -gt 0 ]; then
+ $e -en "\a"; # BEL
+ $p "score:$S\ngit gud\n";
+ fi
}
# put text at given position: p $x $y $text
-p() { echo -en "\e[$2;${1}f$3"; }
+p() { $e -en "\e[$2;${1}f$3"; }
+# play a sine wave (requires ALSA): s $frequency $duration
+s() { ( speaker-test >$n -t sine -f $1 )& _p=$!; sleep $2; kill -9 $_p; }
# wrapper over bc (basic POSIX calculator) that makes all computations shorter
-_() { echo "$*" | bc; }
+_() { $e "$*" | bc; }
# truncate fractional part
-t() { printf "%.*f" 0 $1; }
+t() { $p "%.*f" 0 $1; }
+
+
+p=printf
+e=echo
+n=/dev/null
#
# Main
#
-exec 2>/dev/null # swallow errors, because obviously they're just noise
+exec 2>$n # swallow errors, because obviously they're just noise
tput smcup
-printf "\e[?25l" # cursor off
-trap quit ERR EXIT
+$p "\e[?25l" # cursor off
+trap q ERR EXIT
# set terminal title and start main loop
-printf "\e]0;FLAPPY BASH\007"
-trap tick ALRM
+$p "\e]0;FLAPPY BASH\007"
+trap a 14 # handler for the ALRM signal
np # create new pipe
-tick
+a
while :; do
- read -rsn1 KEY
+ read -rsn1 K
done
View
@@ -38,7 +38,7 @@ def main(argv):
minified = minified.replace('&;}', '&}')
print(source.splitlines()[0]) # copy the original shebang
- print(minified)
+ print(minified.encode('utf8'))
if __name__ == '__main__':

0 comments on commit 3f25941

Please sign in to comment.