This commit is contained in:
Yohann D'ANELLO
2020-11-06 21:15:09 +01:00
parent 2e667cdebe
commit 0bd26a1bd0
5 changed files with 54 additions and 31 deletions

View File

@ -16,21 +16,21 @@ class MapDisplay:
if init_pad:
self.pad = curses.newpad(m.height, m.width + 1)
def update_pad(self):
def update_pad(self) -> None:
self.pad.addstr(0, 0, self.map.draw_string(self.pack))
for e in self.map.entities:
self.pad.addstr(e.y, e.x, self.pack.PLAYER)
def display(self, y, x):
deltay, deltax = (self.height // 2) + 1, (self.width //2) + 1
pminrow, pmincol = y-deltay, x-deltax
def display(self, y: int, x: int) -> None:
deltay, deltax = (self.height // 2) + 1, (self.width // 2) + 1
pminrow, pmincol = y - deltay, x - deltax
sminrow, smincol = max(-pminrow, 0), max(-pmincol, 0)
deltay, deltax = self.height - deltay, self.width - deltax
smaxrow = self.map.height - (y + deltay) + self.height -1
smaxrow = min(smaxrow, self.height-1)
smaxcol = self.map.width - (x + deltax) + self.width -1
smaxcol = min(smaxcol, self.width-1)
pminrow = max(0, min(self.map.height, pminrow))
smaxrow = self.map.height - (y + deltay) + self.height - 1
smaxrow = min(smaxrow, self.height - 1)
smaxcol = self.map.width - (x + deltax) + self.width - 1
smaxcol = min(smaxcol, self.width - 1)
pminrow = max(0, min(self.map.height, pminrow))
pmincol = max(0, min(self.map.width, pmincol))
self.pad.clear()
self.update_pad()