Start game button is working

This commit is contained in:
Yohann D'ANELLO 2020-11-08 23:08:38 +01:00
parent 715fad1817
commit 7e92086601
2 changed files with 8 additions and 36 deletions

View File

@ -1,8 +1,9 @@
import sys
from typing import Any
from .display.display import Display
from .display.mapdisplay import MapDisplay
from .display.menudisplay import MenuDisplay
from .display.texturepack import TexturePack
from .entities.player import Player
from .interfaces import Map
from .settings import Settings
@ -39,7 +40,11 @@ class Game:
self.player = Player()
self.player.move(1, 6)
self.m.add_entity(self.player)
self.current_display = MenuDisplay(self, self.main_menu, 0, 0)
self.menu_display = MenuDisplay(screen, self.main_menu, 0, 0)
self.map_display = MapDisplay(
screen, self.m, self.player,
TexturePack.get_pack(self.settings.TEXTURE_PACK))
self.current_display = self.menu_display
@staticmethod
def load_game(filename: str) -> None:
@ -90,6 +95,7 @@ class Game:
option = self.main_menu.validate()
if option == menus.MainMenuValues.START:
self.state = GameMode.PLAY
self.current_display = self.map_display
elif option == menus.MainMenuValues.SETTINGS:
self.state = GameMode.SETTINGS
elif option == menus.MainMenuValues.EXIT:

View File

@ -1,34 +0,0 @@
#!/usr/bin/env python
import curses
from dungeonbattle.entities.player import Player
from dungeonbattle.interfaces import Map
class MapDisplay:
def __init__(self, m: Map, player: Player, init_pad: bool = True):
self.map = m
self.player = player
if init_pad:
self.pad = curses.newpad(m.height, m.width + 1)
def update_pad(self) -> None:
self.pad.addstr(0, 0, self.map.draw_string())
# TODO Not all entities should be a player
for e in self.map.entities:
self.pad.addstr(e.y, e.x, '🐿')
def display(self, y: int, x: int) -> None:
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)