diff --git a/dungeonbattle/display/display.py b/dungeonbattle/display/display.py index 07db361..de5c280 100644 --- a/dungeonbattle/display/display.py +++ b/dungeonbattle/display/display.py @@ -7,11 +7,14 @@ class Display: def __init__(self, game, screen): self.screen = screen self.game = game - self.mapDisplay = MapDisplay(game.m, - TexturePack.get_pack( + self.map_display = MapDisplay(game.m, + TexturePack.get_pack( game.settings.TEXTURE_PACK), - curses.LINES, - curses.COLS * 4 // 5) + curses.LINES, + curses.COLS * 4 // 5) def refresh(self): - self.mapDisplay.refresh() + self.map_display.update_pad() + + def display(self, y, x): + self.map_display.display(y, x) diff --git a/dungeonbattle/display/mapdisplay.py b/dungeonbattle/display/mapdisplay.py index 3774f1d..03cf092 100644 --- a/dungeonbattle/display/mapdisplay.py +++ b/dungeonbattle/display/mapdisplay.py @@ -1,17 +1,20 @@ #!/usr/bin/env python import curses + +from dungeonbattle.display.texturepack import TexturePack from dungeonbattle.interfaces import Map -from .texturepack import TexturePack class MapDisplay: - def __init__(self, m: Map, pack: TexturePack, height: int, width: int): + def __init__(self, m: Map, pack: TexturePack, height: int, width: int, + init_pad: bool = True): self.width = width self.height = height - self.map = m - self.pad = curses.newpad(m.height, m.width+1) self.pack = pack + self.map = m + if init_pad: + self.pad = curses.newpad(m.height, m.width + 1) def update_pad(self): self.pad.addstr(0, 0, self.map.draw_string(self.pack)) @@ -32,7 +35,3 @@ class MapDisplay: self.pad.clear() self.update_pad() self.pad.refresh(pminrow, pmincol, sminrow, smincol, smaxrow, smaxcol) - - def refresh(self) : - self.display(self.map.currenty,self.map.currentx) - diff --git a/dungeonbattle/game.py b/dungeonbattle/game.py index e0e707d..5445bd2 100644 --- a/dungeonbattle/game.py +++ b/dungeonbattle/game.py @@ -1,9 +1,9 @@ import sys from typing import Any +from .display.display import Display from .entities.player import Player from .interfaces import Map -from .mapdisplay import MapDisplay from .settings import Settings from enum import Enum, auto from . import menus @@ -32,13 +32,13 @@ class Game: self.settings.load_settings() self.settings.write_settings() - def new_game(self, init_pad: bool = True) -> None: + def new_game(self, screen: Any) -> None: # TODO generate a new map procedurally self.m = Map.load("example_map.txt") self.player = Player() self.player.move(1, 6) self.m.add_entity(self.player) - self.d = MapDisplay(self.m, self.player, init_pad) + self.d = Display(self, screen) @staticmethod def load_game(filename: str) -> None: diff --git a/main.py b/main.py index 2e44d9d..40530b9 100755 --- a/main.py +++ b/main.py @@ -5,5 +5,5 @@ from dungeonbattle.term_manager import TermManager if __name__ == "__main__": with TermManager() as term_manager: game = Game() - game.new_game() + game.new_game(term_manager.screen) game.run(term_manager.screen)