39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
#!/usr/bin/env python
|
|
from dungeonbattle.entities.player import Player
|
|
from dungeonbattle.interfaces import Map
|
|
from .display import Display
|
|
|
|
|
|
class MapDisplay(Display):
|
|
player: Player
|
|
|
|
def __init__(self, *args):
|
|
super().__init__(*args)
|
|
|
|
def update_map(self, m: Map) -> None:
|
|
self.map = m
|
|
self.pad = self.newpad(m.height, self.pack.tile_width * m.width + 1)
|
|
|
|
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, self.pack.tile_width * e.x,
|
|
self.pack[e.name.upper()])
|
|
|
|
def display(self) -> None:
|
|
y, x = self.map.currenty, self.map.currentx
|
|
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.pack.tile_width * 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.pack.tile_width * self.map.width, pmincol))
|
|
self.pad.clear()
|
|
self.update_pad()
|
|
self.pad.refresh(pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)
|