added ghost guide

master
kirbylife 2019-11-07 19:56:30 -06:00
parent 58df82795c
commit 2e14bf377d
2 changed files with 43 additions and 7 deletions

View File

@ -31,6 +31,7 @@ class Afutc:
self.input = stdscr.getkey
self.board = np.zeros(shape=(HEIGHT, WIDTH))
self.current_move = np.zeros(shape=(HEIGHT, WIDTH))
self.ghost = np.zeros(shape=(HEIGHT, WIDTH))
self.board_center = WIDTH // 2
self.current_piece = None
self.score = 0
@ -54,16 +55,37 @@ class Afutc:
row = str(self.score).center(self.board.shape[1], "")
print("ANOTHER F TETRIS CLONE")
print(f"{row}")
for n, row in enumerate(self.board + self.current_move):
# row = "".join("" if field else " " for field in row)
row = "".join(self.char if field else " " for field in row)
print(f"{row}")
for i, row in enumerate(self.board + self.current_move):
row_str = ""
for j, field in enumerate(row):
if self.ghost[i, j]:
row_str += ""
elif field:
row_str += self.char
else:
row_str += " "
print(f"{row_str}")
row = "" * (self.board.shape[1])
print(f"{row}")
# print(str(self.pivot) + "\t" + self.debug)
# print(f"╚{row}╝")
print(str(self.pivot) + "\t" + self.debug)
except CursesException:
self.pause()
def recalculate_ghost(self):
pivot = self.pivot[:]
current_piece = self.current_piece.copy()
self.ghost.fill(0.)
count = 0
while True:
result = self.fuse_matrix(
self.ghost, current_piece,
(pivot[1], HEIGHT - current_piece.shape[0] - count))
if self.is_valid(result):
self.ghost = result.copy()
break
else:
count += 1
def new_random_piece(self):
# Clear rows completed
count = 0
@ -86,6 +108,7 @@ class Afutc:
if not self.is_valid(self.current_move):
self.running = False
self.pivot = [0, position]
catch(self.recalculate_ghost)
def move(self, direction):
if direction == "down":
@ -112,6 +135,7 @@ class Afutc:
return
self.current_move = temp_board
self.pivot[1] -= 1
self.recalculate_ghost()
elif direction == "right" and self.pivot[1] < (
WIDTH - self.current_piece.shape[1]):
temp_board = self.current_move.copy()
@ -122,6 +146,7 @@ class Afutc:
return
self.current_move = temp_board
self.pivot[1] += 1
self.recalculate_ghost()
def rotate(self):
temp_board = self.current_move.copy()
@ -145,6 +170,7 @@ class Afutc:
if self.is_valid(temp_board):
self.current_move = temp_board.copy()
self.current_piece = temp_piece.copy()
self.recalculate_ghost()
def start(self):
scr = self.stdscr
@ -187,6 +213,16 @@ class Afutc:
self.running = False
break
@classmethod
def fuse_matrix(self, mat1, mat2, xypos=(0, 0)):
mat1 = mat1.copy()
mat2 = mat2.copy()
x, y = xypos
ysize, xsize = mat2.shape
xmax, ymax = (x + xsize), (y + ysize)
mat1[y:ymax, x:xmax] += mat2
return mat1
def start():
stdscr = curses.initscr()

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "afutc"
version = "1.0.0"
version = "1.1.0"
description = "Another Fucking Ugly Tetris Clone"
authors = ["kirbylife <gabriel13m@gmail.com>"]