Texture packs are working
This commit is contained in:
@ -1,11 +1,17 @@
|
||||
import curses
|
||||
from .mapdisplay import MapDisplay
|
||||
from .texturepack import TexturePack
|
||||
|
||||
|
||||
class Display:
|
||||
def __init__(self, game, screen):
|
||||
self.screen = screen
|
||||
self.game = game
|
||||
self.mapDisplay = MapDisplay(game.m, game.settings, curses.LINES, curses.COLS * 4/5)
|
||||
|
||||
self.mapDisplay = MapDisplay(game.m,
|
||||
TexturePack.get_pack(
|
||||
game.settings.TEXTURE_PACK),
|
||||
curses.LINES,
|
||||
curses.COLS * 4 // 5)
|
||||
|
||||
def refresh(self):
|
||||
self.mapDisplay.refresh()
|
||||
|
@ -1,25 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
import curses
|
||||
from dungeonbattle.interfaces import Map
|
||||
from dungeonbattle.settings import Settings
|
||||
import .texturepack as tp
|
||||
from .texturepack import TexturePack
|
||||
|
||||
|
||||
class MapDisplay:
|
||||
|
||||
def __init__(self, m: Map, settings : Settings, height: int, width: int):
|
||||
def __init__(self, m: Map, pack: TexturePack, height: int, width: int):
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.map = m
|
||||
self.pad = curses.newpad(m.height, m.width+1)
|
||||
if self.settings.TEXTURE_PACK == 'ASCII' :
|
||||
self.textures = tp.ascii_textures
|
||||
if self.settings.TEXTURE_PACK == 'SQUIRREL' :
|
||||
self.textures = tp.squirrel_textures
|
||||
self.pack = pack
|
||||
|
||||
def update_pad(self):
|
||||
self.pad.addstr(0, 0, self.map.draw_string())
|
||||
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.textures[e.name])
|
||||
self.pad.addstr(e.y, e.x, self.pack.PLAYER)
|
||||
|
||||
def display(self, y, x):
|
||||
deltay, deltax = (self.height // 2) + 1, (self.width //2) + 1
|
||||
|
@ -1,13 +1,34 @@
|
||||
ascii_textures = {
|
||||
"EMPTY" : ' ',
|
||||
"WALL" : '#',
|
||||
"FLOOR" : '.',
|
||||
"PLAYER" : '@'
|
||||
}
|
||||
class TexturePack:
|
||||
_packs = dict()
|
||||
|
||||
squirrel_textures = {
|
||||
"EMPTY" : ' ',
|
||||
"WALL" : '█',
|
||||
"FLOOR" : '.',
|
||||
"PLAYER" : '🐿️'
|
||||
}
|
||||
name: str
|
||||
EMPTY: str
|
||||
WALL: str
|
||||
FLOOR: str
|
||||
PLAYER: str
|
||||
|
||||
def __init__(self, name: str, **kwargs):
|
||||
self.name = name
|
||||
self.__dict__.update(**kwargs)
|
||||
TexturePack._packs[name] = self
|
||||
|
||||
@classmethod
|
||||
def get_pack(cls, name: str) -> "TexturePack":
|
||||
return cls._packs[name]
|
||||
|
||||
|
||||
TexturePack.ASCII_PACK = TexturePack(
|
||||
name="ascii",
|
||||
EMPTY=' ',
|
||||
WALL='#',
|
||||
FLOOR='.',
|
||||
PLAYER='@',
|
||||
)
|
||||
|
||||
TexturePack.SQUIRREL_PACK = TexturePack(
|
||||
name="squirrel",
|
||||
EMPTY=' ',
|
||||
WALL='█',
|
||||
FLOOR='.',
|
||||
PLAYER='🐿️',
|
||||
)
|
||||
|
Reference in New Issue
Block a user