added ghost guide
parent
58df82795c
commit
2e14bf377d
|
@ -31,6 +31,7 @@ class Afutc:
|
||||||
self.input = stdscr.getkey
|
self.input = stdscr.getkey
|
||||||
self.board = np.zeros(shape=(HEIGHT, WIDTH))
|
self.board = np.zeros(shape=(HEIGHT, WIDTH))
|
||||||
self.current_move = 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.board_center = WIDTH // 2
|
||||||
self.current_piece = None
|
self.current_piece = None
|
||||||
self.score = 0
|
self.score = 0
|
||||||
|
@ -54,16 +55,37 @@ class Afutc:
|
||||||
row = str(self.score).center(self.board.shape[1], "═")
|
row = str(self.score).center(self.board.shape[1], "═")
|
||||||
print("ANOTHER F TETRIS CLONE")
|
print("ANOTHER F TETRIS CLONE")
|
||||||
print(f"╔{row}╗")
|
print(f"╔{row}╗")
|
||||||
for n, row in enumerate(self.board + self.current_move):
|
for i, row in enumerate(self.board + self.current_move):
|
||||||
# row = "".join("" if field else " " for field in row)
|
row_str = ""
|
||||||
row = "".join(self.char if field else " " for field in row)
|
for j, field in enumerate(row):
|
||||||
print(f"║{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])
|
row = "═" * (self.board.shape[1])
|
||||||
print(f"╚{row}╝")
|
# print(f"╚{row}╝")
|
||||||
# print(str(self.pivot) + "\t" + self.debug)
|
print(str(self.pivot) + "\t" + self.debug)
|
||||||
except CursesException:
|
except CursesException:
|
||||||
self.pause()
|
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):
|
def new_random_piece(self):
|
||||||
# Clear rows completed
|
# Clear rows completed
|
||||||
count = 0
|
count = 0
|
||||||
|
@ -86,6 +108,7 @@ class Afutc:
|
||||||
if not self.is_valid(self.current_move):
|
if not self.is_valid(self.current_move):
|
||||||
self.running = False
|
self.running = False
|
||||||
self.pivot = [0, position]
|
self.pivot = [0, position]
|
||||||
|
catch(self.recalculate_ghost)
|
||||||
|
|
||||||
def move(self, direction):
|
def move(self, direction):
|
||||||
if direction == "down":
|
if direction == "down":
|
||||||
|
@ -112,6 +135,7 @@ class Afutc:
|
||||||
return
|
return
|
||||||
self.current_move = temp_board
|
self.current_move = temp_board
|
||||||
self.pivot[1] -= 1
|
self.pivot[1] -= 1
|
||||||
|
self.recalculate_ghost()
|
||||||
elif direction == "right" and self.pivot[1] < (
|
elif direction == "right" and self.pivot[1] < (
|
||||||
WIDTH - self.current_piece.shape[1]):
|
WIDTH - self.current_piece.shape[1]):
|
||||||
temp_board = self.current_move.copy()
|
temp_board = self.current_move.copy()
|
||||||
|
@ -122,6 +146,7 @@ class Afutc:
|
||||||
return
|
return
|
||||||
self.current_move = temp_board
|
self.current_move = temp_board
|
||||||
self.pivot[1] += 1
|
self.pivot[1] += 1
|
||||||
|
self.recalculate_ghost()
|
||||||
|
|
||||||
def rotate(self):
|
def rotate(self):
|
||||||
temp_board = self.current_move.copy()
|
temp_board = self.current_move.copy()
|
||||||
|
@ -145,6 +170,7 @@ class Afutc:
|
||||||
if self.is_valid(temp_board):
|
if self.is_valid(temp_board):
|
||||||
self.current_move = temp_board.copy()
|
self.current_move = temp_board.copy()
|
||||||
self.current_piece = temp_piece.copy()
|
self.current_piece = temp_piece.copy()
|
||||||
|
self.recalculate_ghost()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
scr = self.stdscr
|
scr = self.stdscr
|
||||||
|
@ -187,6 +213,16 @@ class Afutc:
|
||||||
self.running = False
|
self.running = False
|
||||||
break
|
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():
|
def start():
|
||||||
stdscr = curses.initscr()
|
stdscr = curses.initscr()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "afutc"
|
name = "afutc"
|
||||||
version = "1.0.0"
|
version = "1.1.0"
|
||||||
description = "Another Fucking Ugly Tetris Clone"
|
description = "Another Fucking Ugly Tetris Clone"
|
||||||
authors = ["kirbylife <gabriel13m@gmail.com>"]
|
authors = ["kirbylife <gabriel13m@gmail.com>"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue