Merge remote-tracking branch 'origin/master' into player_move
# Conflicts: # dungeonbattle/interfaces.py # dungeonbattle/interfaces_test.py
This commit is contained in:
commit
008773c01e
|
@ -11,10 +11,11 @@ class Map:
|
||||||
height: int
|
height: int
|
||||||
tiles: list
|
tiles: list
|
||||||
|
|
||||||
def __init__(self, width: int, height: int, tiles: list):
|
def __init__(self, width: int, height: int, tiles: list, entities: list):
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.tiles = tiles
|
self.tiles = tiles
|
||||||
|
self.entities = entities
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load(filename: str):
|
def load(filename: str):
|
||||||
|
@ -36,7 +37,7 @@ class Map:
|
||||||
width = len(lines[0])
|
width = len(lines[0])
|
||||||
tiles = [[Tile(c)
|
tiles = [[Tile(c)
|
||||||
for x, c in enumerate(line)] for y, line in enumerate(lines)]
|
for x, c in enumerate(line)] for y, line in enumerate(lines)]
|
||||||
return Map(width, height, tiles)
|
return Map(width, height, tiles, [])
|
||||||
|
|
||||||
def draw_string(self) -> str:
|
def draw_string(self) -> str:
|
||||||
"""
|
"""
|
||||||
|
@ -63,8 +64,14 @@ class Tile(Enum):
|
||||||
|
|
||||||
|
|
||||||
class Entity:
|
class Entity:
|
||||||
x: int
|
|
||||||
y: int
|
y: int
|
||||||
|
x: int
|
||||||
|
img: str
|
||||||
|
|
||||||
|
def __init__(self, y: int, x: int, img: str):
|
||||||
|
self.y = y
|
||||||
|
self.x = x
|
||||||
|
self.img = img
|
||||||
|
|
||||||
def move(self, x: int, y: int) -> None:
|
def move(self, x: int, y: int) -> None:
|
||||||
self.x = x
|
self.x = x
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
import curses
|
||||||
|
from dungeonbattle.interfaces import Map
|
||||||
|
|
||||||
|
class MapDisplay:
|
||||||
|
|
||||||
|
def __init__(self, m: Map):
|
||||||
|
self.map = m
|
||||||
|
self.pad = curses.newpad(m.height, m.width+1)
|
||||||
|
|
||||||
|
def update_pad(self):
|
||||||
|
for i in range(self.map.height):
|
||||||
|
self.pad.addstr(i, 0, self.map.tiles[i])
|
||||||
|
for e in self.map.entities:
|
||||||
|
self.pad.addch(e.y, e.x, e.img)
|
||||||
|
|
||||||
|
def display(self, y, x):
|
||||||
|
deltay, deltax = (curses.LINES // 2) + 1, (curses.COLS //2) + 1
|
||||||
|
pminrow, pmincol = y-deltay, x-deltax
|
||||||
|
sminrow, smincol = max(-pminrow, 0), max(-pmincol, 0)
|
||||||
|
deltay, deltax = curses.LINES - deltay, curses.COLS - deltax
|
||||||
|
smaxrow = self.map.height - (y + deltay) + curses.LINES -1
|
||||||
|
smaxrow = min(smaxrow, curses.LINES-1)
|
||||||
|
smaxcol = self.map.width - (x + deltax) + curses.COLS -1
|
||||||
|
smaxcol = min(smaxcol, curses.COLS-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)
|
Loading…
Reference in New Issue