Reworked graphics to make it more modular
This commit is contained in:
@ -5,15 +5,15 @@ import curses
|
||||
from dungeonbattle.display.texturepack import TexturePack
|
||||
from dungeonbattle.entities.player import Player
|
||||
from dungeonbattle.interfaces import Map
|
||||
from .display import Display
|
||||
|
||||
|
||||
class MapDisplay:
|
||||
class MapDisplay(Display):
|
||||
player: Player
|
||||
|
||||
def __init__(self, m: Map, pack: TexturePack, height : int, width : int):
|
||||
self.height = height
|
||||
self.width = width
|
||||
self.pack = pack
|
||||
def __init__(self, *args):
|
||||
super().__init__(*args)
|
||||
|
||||
def update_map(self, m: Map):
|
||||
self.map = m
|
||||
self.pad = curses.newpad(m.height, m.width + 1)
|
||||
|
||||
@ -22,7 +22,8 @@ class MapDisplay:
|
||||
for e in self.map.entities:
|
||||
self.pad.addstr(e.y, e.x, self.pack.PLAYER)
|
||||
|
||||
def display(self, y, x) -> None:
|
||||
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)
|
||||
@ -35,10 +36,4 @@ class MapDisplay:
|
||||
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)
|
||||
self.pad.refresh(pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol)
|
Reference in New Issue
Block a user