Corrected equations in mapdisplay.MapDisplay.display. Closes #1

This commit is contained in:
Charles Peyrat 2020-10-16 18:14:47 +02:00
parent 722ff07952
commit 14f93fd596
1 changed files with 6 additions and 6 deletions

View File

@ -6,25 +6,25 @@ class MapDisplay:
def __init__(self, m: Map): def __init__(self, m: Map):
self.map = m self.map = m
self.pad = curses.newpad(m.height, m.width) self.pad = curses.newpad(m.height, m.width+1)
def update_pad(self): def update_pad(self):
for i in range(self.map.height): for i in range(self.map.height):
self.pad.addstr(i, 0, self.map.tiles[i][:-1]) self.pad.addstr(i, 0, self.map.tiles[i])
for e in self.map.entities: for e in self.map.entities:
self.pad.addch(e.y, e.x, e.img) self.pad.addch(e.y, e.x, e.img)
def display(self, y, x): def display(self, y, x):
self.pad.clear()
deltay, deltax = (curses.LINES // 2) + 1, (curses.COLS //2) + 1 deltay, deltax = (curses.LINES // 2) + 1, (curses.COLS //2) + 1
pminrow, pmincol = y-deltay, x-deltax pminrow, pmincol = y-deltay, x-deltax
sminrow, smincol = max(-pminrow, 0), max(-pmincol, 0) sminrow, smincol = max(-pminrow, 0), max(-pmincol, 0)
deltay, deltax = curses.LINES - deltay, curses.COLS - deltay deltay, deltax = curses.LINES - deltay, curses.COLS - deltax
smaxrow = self.map.height - (y + deltay) + curses.LINES smaxrow = self.map.height - (y + deltay) + curses.LINES -1
smaxrow = min(smaxrow, curses.LINES-1) smaxrow = min(smaxrow, curses.LINES-1)
smaxcol = self.map.width - (x + deltax) + curses.COLS smaxcol = self.map.width - (x + deltax) + curses.COLS -1
smaxcol = min(smaxcol, curses.COLS-1) smaxcol = min(smaxcol, curses.COLS-1)
pminrow = max(0, min(self.map.height, pminrow)) pminrow = max(0, min(self.map.height, pminrow))
pmincol = max(0, min(self.map.width, pmincol)) pmincol = max(0, min(self.map.width, pmincol))
self.pad.clear()
self.update_pad() self.update_pad()
self.pad.refresh(pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol) self.pad.refresh(pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)