This commit is contained in:
Yohann D'ANELLO 2020-11-06 21:15:09 +01:00
parent 2e667cdebe
commit 0bd26a1bd0
5 changed files with 54 additions and 31 deletions

View File

@ -1,21 +1,25 @@
import curses import curses
from typing import Any
from .mapdisplay import MapDisplay from .mapdisplay import MapDisplay
from .texturepack import TexturePack from .texturepack import TexturePack
from ..game import Game
class Display: class Display:
def __init__(self, game, screen): def __init__(self, game: Game, screen: Any):
self.screen = screen self.screen = screen
self.game = game self.game = game
lines = curses.LINES if screen else 4 lines = curses.LINES if screen else 4
cols = curses.COLS * 4 // 5 if screen else 4 cols = curses.COLS * 4 // 5 if screen else 4
self.map_display = MapDisplay(game.m, self.map_display = MapDisplay(game.m,
TexturePack.get_pack( TexturePack.get_pack(
game.settings.TEXTURE_PACK), game.settings.TEXTURE_PACK
),
lines, cols, screen is not None) lines, cols, screen is not None)
def refresh(self): def refresh(self) -> None:
self.map_display.update_pad() self.map_display.update_pad()
def display(self, y, x): def display(self, y: int, x: int) -> None:
self.map_display.display(y, x) self.map_display.display(y, x)

View File

@ -16,20 +16,20 @@ class MapDisplay:
if init_pad: if init_pad:
self.pad = curses.newpad(m.height, m.width + 1) self.pad = curses.newpad(m.height, m.width + 1)
def update_pad(self): def update_pad(self) -> None:
self.pad.addstr(0, 0, self.map.draw_string(self.pack)) self.pad.addstr(0, 0, self.map.draw_string(self.pack))
for e in self.map.entities: for e in self.map.entities:
self.pad.addstr(e.y, e.x, self.pack.PLAYER) self.pad.addstr(e.y, e.x, self.pack.PLAYER)
def display(self, y, x): def display(self, y: int, x: int) -> None:
deltay, deltax = (self.height // 2) + 1, (self.width //2) + 1 deltay, deltax = (self.height // 2) + 1, (self.width // 2) + 1
pminrow, pmincol = y-deltay, x-deltax pminrow, pmincol = y - deltay, x - deltax
sminrow, smincol = max(-pminrow, 0), max(-pmincol, 0) sminrow, smincol = max(-pminrow, 0), max(-pmincol, 0)
deltay, deltax = self.height - deltay, self.width - deltax deltay, deltax = self.height - deltay, self.width - deltax
smaxrow = self.map.height - (y + deltay) + self.height -1 smaxrow = self.map.height - (y + deltay) + self.height - 1
smaxrow = min(smaxrow, self.height-1) smaxrow = min(smaxrow, self.height - 1)
smaxcol = self.map.width - (x + deltax) + self.width -1 smaxcol = self.map.width - (x + deltax) + self.width - 1
smaxcol = min(smaxcol, self.width-1) smaxcol = min(smaxcol, self.width - 1)
pminrow = max(0, min(self.map.height, pminrow)) pminrow = max(0, min(self.map.height, pminrow))
pmincol = max(0, min(self.map.width, pmincol)) pmincol = max(0, min(self.map.width, pmincol))
self.pad.clear() self.pad.clear()

View File

@ -1,15 +1,31 @@
import curses import curses
from dungeonbattle.entities.player import Player
class StatsDisplay: class StatsDisplay:
def __init__(self, player, height, width, topleftx, toplefty) : def __init__(self, player: Player, height: int, width: int,
topleftx: int, toplefty: int):
self.width = width self.width = width
self.height = height self.height = height
self.topleftx = topleftx
self.toplefty = toplefty
self.player = player
self.pad = curses.newpad(height, width) self.pad = curses.newpad(height, width)
def update_pad(self) :
string = "Player -- LVL {} EXP {}/{} HP {}/{}\nStats : STR {} INT {} CHR {} DEX {} CON {}".format(player.level, player.currentXP, player.maxXP, player.health, player.maxhealth, player.strength, player.intelligence, player.charisma, player.dexterity, player.constitution) def update_pad(self) -> None:
string = "Player -- LVL {} EXP {}/{} HP {}/{}\n" \
"Stats : STR {} INT {} CHR {} DEX {} CON {}"\
.format(self.player.level, self.player.current_xp,
self.player.max_xp, self.player.health,
self.player.maxhealth, self.player.strength,
self.player.intelligence, self.player.charisma,
self.player.dexterity, self.player.constitution)
self.pad.addstr(0, 0, string) self.pad.addstr(0, 0, string)
def refresh(self) :
def refresh(self) -> None:
self.pad.clear() self.pad.clear()
self.update_pad() self.update_pad()
self.pad.refresh(0, 0, toplefty, topleftx, heigth+toplefty, width+topleftx) self.pad.refresh(0, 0, self.toplefty, self.topleftx,
self.heigth + self.toplefty,
self.width + self.topleftx)

View File

@ -17,14 +17,15 @@ class Player(FightingEntity):
def move_right(self) -> bool: def move_right(self) -> bool:
return self.check_move(self.y, self.x + 1, True) return self.check_move(self.y, self.x + 1, True)
currentXP: int current_xp: int
maxXP: int max_xp: int
def level_up(self): def level_up(self) -> None:
if currentXP>maxXP : if self.current_xp > self.max_xp:
self.level+=1 self.level += 1
currentXP = 0 self.current_xp = 0
maxXP = self.level*10 self.max_xp = self.level * 10
def addXP(self, xp) :
currentXP+=xp def add_xp(self, xp: int) -> None:
self.current_xp += xp
self.level_up() self.level_up()

View File

@ -12,8 +12,10 @@ class Map:
width: int width: int
height: int height: int
tiles: list tiles: list
currentx : int #coordinates of the point that should be on the topleft corner of the screen # coordinates of the point that should be
currenty : int # on the topleft corner of the screen
currentx: int
currenty: int
def __init__(self, width: int, height: int, tiles: list): def __init__(self, width: int, height: int, tiles: list):
self.width = width self.width = width
@ -88,7 +90,7 @@ class Tile(Enum):
class Entity: class Entity:
y: int y: int
x: int x: int
name : str name: str
map: Map map: Map
def __init__(self): def __init__(self):