adventure-game #3

Open
Kenwood wants to merge 80 commits from adventure-game into master
3 changed files with 43 additions and 28 deletions
Showing only changes of commit ed4b5abd24 - Show all commits

1
Adventure Game/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
venv

View File

@ -1,35 +1,40 @@
# std imports
from math import floor
# local
from blessed import Terminal
class Graphics:
def __init__(self):
self.bottom_left_corner = u""
self.bottom_right_corner = u""
self.top_left_corner = u""
self.top_right_corner = u""
self.border_horizontal = u""
self.border_vertical = u""
def roundxy(x, y):
return int(floor(x)), int(floor(y))
class Window:
def __init__(self, term, height, width, xpos, ypos, title=None):
self.term = term
self.title = title
term = Terminal()
self.height = height
self.width = width
self.xpos = xpos
self.ypos = ypos
def draw_borders(self):
# Print the top
print(
self.term.move_xy(self.xpos, self.ypos) +
u"" +
u"" * (self.width - 2) +
u""
)
x, y, xs, ys = 2, 2, 0.4, 0.3
with term.cbreak(), term.hidden_cursor():
# clear the screen
print(term.home + term.black_on_olivedrab4 + term.clear)
# Print the middle
# We exclude the top and bottom rows since we'll draw them with other chars
for dx in range (1, self.height - 1):
print(self.term.move_xy(self.xpos + dx, self.ypos) + u'')
print(self.term.move_xy(self.xpos + dx, self.ypos + self.width - 1) + u'')
# loop every 20ms
while term.inkey(timeout=0.02) != 'q':
# erase,
txt_erase = term.move_xy(*roundxy(x, y)) + ' '
# bounce,
if x >= (term.width - 1) or x <= 0:
xs *= -1
if y >= term.height or y <= 0:
ys *= -1
# move,
x, y = x + xs, y + ys
# draw !
txt_ball = term.move_xy(*roundxy(x, y)) + ''
print(txt_erase + txt_ball, end='', flush=True)
terminal = Terminal()
my_window = Window(terminal, 4, 20, 10, 10)
my_window.draw_borders()

View File

@ -0,0 +1,9 @@
from blessed import Terminal
import time
term = Terminal()
for x in range(10):
for y in range(10):
print(term.move_xy(x, y) + '*')
time.sleep(0.1)