46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
#!/usr/bin/env python
|
|
from typing import Any
|
|
import curses
|
|
|
|
from dungeonbattle.display.display import Display
|
|
from dungeonbattle.display.texturepack import TexturePack
|
|
from dungeonbattle.entities.player import Player
|
|
from dungeonbattle.interfaces import Map
|
|
|
|
|
|
class MapDisplay:
|
|
self.map: Map
|
|
self.player: Player
|
|
|
|
def __init__(self, pack: TexturePack, height : int, width : int):
|
|
self.height = height
|
|
self.width = width
|
|
self.pack = pack
|
|
self.pad = curses.newpad(m.height, 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, e.x, self.pack.PLAYER)
|
|
|
|
def display(self, y, x) -> 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))
|
|
pmincol = max(0, min(self.map.width, pmincol))
|
|
self.pad.clear()
|
|
self.update_pad()
|
|
self.pad.refresh(pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)
|
|
|
|
def refresh(self, m : Map, p : Player) -> None:
|
|
self.map = m
|
|
self.player = p
|
|
y, x = self.map.currenty, self.map.currentx
|
|
self.display(y,x)
|