Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
csaez committed May 16, 2015
1 parent fb68f95 commit fa29fd2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
flASCII bird
============

In the past few days has been a lot of buzz about [Flappy Bird](https://en.wikipedia.org/wiki/Flappy_Bird).
I'm not a big gamer, but I couldn't resist and did this terminal-based tribute... and I won't take it down ;D
There has been a lot of buzz about [Flappy
Bird](https://en.wikipedia.org/wiki/Flappy_Bird) in the past few days.

I'm not big on games or anything, but I couldn't resist the temptation and put
together this terminal-based tribute as a weekend project... and I won't take
it down ;D

![](flascii_bird.png?raw=true)

Have fun!
Enjoy!
45 changes: 38 additions & 7 deletions flascii_bird.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
# This file is part of flascii_bird.
# Copyright (C) 2014 Cesar Saez

Expand All @@ -14,12 +15,42 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.


import sys
import time
import msvcrt # windows-only :_(
from math import fmod, sqrt
from threading import Timer
from random import randint

try:
import msvcrt
PLATFORM = "win"
except ImportError:
PLATFORM = "unix"
import tty
import termios
from select import select


def getch():
if PLATFORM == "win":
ch = msvcrt.getch()
return ch
elif PLATFORM == "unix":
fd = sys.stdin.fileno()
old_setting = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
i, o, e = select([sys.stdin.fileno()], [], [], 5)
if i:
ch = sys.stdin.read(1)
else:
ch = ""
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_setting)
return ch
else:
return ""


class Vector(object):

Expand Down Expand Up @@ -105,12 +136,12 @@ def draw(self, BG):
else:
x = s[abs(self.pos.x):] + x[self.pos.x + len(s):] + (" " * 79)
BG[i + self.pos.y] = x
return "\n".join([x[:79] for x in BG][:25])
return "\n".join([ch[:79] for ch in BG][:25])


def key_pressed():
global KEY_PRESSED
if msvcrt.getch() == " ":
if getch() == " ":
KEY_PRESSED = True


Expand Down Expand Up @@ -180,16 +211,16 @@ def flascii_bird():
docs.pos = Vector(5, 23)
for x in (s, docs):
frame = x.draw(frame)
print BIRD.draw(frame)
print(BIRD.draw(frame))

# collisions
colliders = list(TUBES)
colliders.append(GROUND)
if BIRD.collide(colliders) or BIRD.pos.y < 0:
# game over
print (" " * TERMINAL_SIZE.x + "\n") * TERMINAL_SIZE.y
print "GAME OVER"
print "SCORE:", SCORE
print((" " * TERMINAL_SIZE.x + "\n") * TERMINAL_SIZE.y)
print("GAME OVER")
print("SCORE:", SCORE)
return

if __name__ == "__main__":
Expand Down
9 changes: 4 additions & 5 deletions flascii_bird_linux.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

# This file is part of flascii_bird.
# Copyright (C) 2014 Cesar Saez
Expand All @@ -15,14 +15,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


import time
import select
import sys
import tty
import termios
import time
import tty
from math import fmod, sqrt
from random import randint
import select


class Vector(object):
Expand Down

0 comments on commit fa29fd2

Please sign in to comment.