Added a MainMenuDisplay class and fixed errors in display
This commit is contained in:
parent
10bbb28471
commit
91a8919a01
11
dungeonbattle/display/ascii_art.txt
Normal file
11
dungeonbattle/display/ascii_art.txt
Normal file
@ -0,0 +1,11 @@
|
||||
██████ █████ █ ██ ██▓ ██▀███ ██▀███ ▓█████ ██▓ ▄▄▄▄ ▄▄▄ ▄▄▄█████▓▄▄▄█████▓ ██▓ ▓█████
|
||||
▒██ ▒ ▒██▓ ██▒ ██ ▓██▒▓██▒▓██ ▒ ██▒▓██ ▒ ██▒▓█ ▀ ▓██▒ ▓█████▄ ▒████▄ ▓ ██▒ ▓▒▓ ██▒ ▓▒▓██▒ ▓█ ▀
|
||||
░ ▓██▄ ▒██▒ ██░▓██ ▒██░▒██▒▓██ ░▄█ ▒▓██ ░▄█ ▒▒███ ▒██░ ▒██▒ ▄██▒██ ▀█▄ ▒ ▓██░ ▒░▒ ▓██░ ▒░▒██░ ▒███
|
||||
▒ ██▒░██ █▀ ░▓▓█ ░██░░██░▒██▀▀█▄ ▒██▀▀█▄ ▒▓█ ▄ ▒██░ ▒██░█▀ ░██▄▄▄▄██░ ▓██▓ ░ ░ ▓██▓ ░ ▒██░ ▒▓█ ▄
|
||||
▒██████▒▒░▒███▒█▄ ▒▒█████▓ ░██░░██▓ ▒██▒░██▓ ▒██▒░▒████▒░██████▒ ░▓█ ▀█▓ ▓█ ▓██▒ ▒██▒ ░ ▒██▒ ░ ░██████▒░▒████▒
|
||||
▒ ▒▓▒ ▒ ░░░ ▒▒░ ▒ ░▒▓▒ ▒ ▒ ░▓ ░ ▒▓ ░▒▓░░ ▒▓ ░▒▓░░░ ▒░ ░░ ▒░▓ ░ ░▒▓███▀▒ ▒▒ ▓▒█░ ▒ ░░ ▒ ░░ ░ ▒░▓ ░░░ ▒░ ░
|
||||
░ ░▒ ░ ░ ░ ▒░ ░ ░░▒░ ░ ░ ▒ ░ ░▒ ░ ▒░ ░▒ ░ ▒░ ░ ░ ░░ ░ ▒ ░ ▒░▒ ░ ▒ ▒▒ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░
|
||||
░ ░ ░ ░ ░ ░░░ ░ ░ ▒ ░ ░░ ░ ░░ ░ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ░
|
||||
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
|
||||
░
|
||||
|
@ -15,8 +15,8 @@ class Display:
|
||||
def __init__(self, screen: Any, texture: Any):
|
||||
self.screen = screen
|
||||
self.texture = texture
|
||||
self.mapdisplay = MapDisplay(self.screen, self.texture, curses.LINES * 4//5, curses.COLS)
|
||||
self.statsdisplay = StatsDisplay(self.screen, curses.LINES//5, curses.COLS)
|
||||
self.mapdisplay = MapDisplay(self.texture, curses.LINES * 4//5, curses.COLS)
|
||||
self.statsdisplay = StatsDisplay(curses.LINES//5, curses.COLS, curses.LINES * 4//5, 0)
|
||||
|
||||
def refresh(self, m : Map, p : Player) -> None:
|
||||
self.map = m
|
||||
|
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
from typing import Any
|
||||
import curses
|
||||
|
||||
from dungeonbattle.display.display import Display
|
||||
from dungeonbattle.display.texturepack import TexturePack
|
||||
@ -11,19 +12,18 @@ class MapDisplay:
|
||||
self.map: Map
|
||||
self.player: Player
|
||||
|
||||
def __init__(self, screen: Any, pack: TexturePack, height : int, width : int):
|
||||
self.screen = screen
|
||||
def __init__(self, pack: TexturePack, height : int, width : int):
|
||||
self.height = height
|
||||
self.width = width
|
||||
self.pack = pack
|
||||
self.pad = self.newpad(m.height, m.width + 1)
|
||||
self.pad = curses.newpad(m.height, m.width + 1)
|
||||
|
||||
def update_pad(self) -> None:
|
||||
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.pack.PLAYER)
|
||||
|
||||
def display(self) -> None:
|
||||
def display(self, y, x) -> None:
|
||||
deltay, deltax = (self.height // 2) + 1, (self.width // 2) + 1
|
||||
pminrow, pmincol = y - deltay, x - deltax
|
||||
sminrow, smincol = max(-pminrow, 0), max(-pmincol, 0)
|
||||
@ -42,4 +42,4 @@ class MapDisplay:
|
||||
self.map = m
|
||||
self.player = p
|
||||
y, x = self.map.currenty, self.map.currentx
|
||||
return self.display()
|
||||
self.display(y,x)
|
||||
|
@ -1,12 +1,11 @@
|
||||
from dungeonbattle.menus import Menu
|
||||
from dungeonbattle.menus import Menu, MainMenu
|
||||
from typing import Any
|
||||
import curses
|
||||
|
||||
class MenuDisplay:
|
||||
position: int
|
||||
|
||||
def __init__(self, menu : Menu, screen: Any, height : int, width : int, topleftx: int, toplefty: int) :
|
||||
self.screen = screen
|
||||
def __init__(self, menu : Menu, height : int, width : int, topleftx: int, toplefty: int) :
|
||||
self.values = menu.values
|
||||
self.width = width
|
||||
self.height = height
|
||||
@ -46,3 +45,25 @@ class MenuDisplay:
|
||||
self.pad.refresh(cornery, 0, self.toplefty+1, self.topleftx+1,
|
||||
self.height-2 + self.toplefty,
|
||||
self.width-2 + self.topleftx)
|
||||
|
||||
class MainMenuDisplay:
|
||||
def __init__(self, menu : MainMenu) :
|
||||
self.menu = menu
|
||||
self.pad = curses.newpad(curses.LINES, curses.COLS)
|
||||
|
||||
with open("ascii_art.txt", "r") as file:
|
||||
title = file.read().split("\n")
|
||||
|
||||
width = len(title[0])
|
||||
height = len(title)
|
||||
|
||||
for i in range(len(title)) :
|
||||
self.pad.addstr(4+i,curses.COLS//2-width//2-1,title[i])
|
||||
self.pad.refresh(0,0,0,0,curses.LINES,curses.COLS)
|
||||
|
||||
self.menudisplay = MenuDisplay(self.menu, 15, 15, height+8, curses.COLS//2-15//2-1)
|
||||
|
||||
def refresh(self, position) -> None:
|
||||
self.menudisplay.refresh(position)
|
||||
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
from typing import Any
|
||||
import curses
|
||||
|
||||
from dungeonbattle.display.display import Display
|
||||
from dungeonbattle.entities.player import Player
|
||||
@ -7,15 +8,14 @@ from dungeonbattle.entities.player import Player
|
||||
class StatsDisplay(Display):
|
||||
self.player: Player
|
||||
|
||||
def __init__(self, screen: Any, height: int, width: int,
|
||||
def __init__(self, height: int, width: int,
|
||||
topleftx: int, toplefty: int):
|
||||
super().__init__(screen)
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.topleftx = topleftx
|
||||
self.toplefty = toplefty
|
||||
|
||||
self.pad = self.newpad(height, width)
|
||||
self.pad = curses.newpad(height, width)
|
||||
|
||||
def update_pad(self) -> None:
|
||||
string = ""
|
||||
|
17
dungeonbattle/display/test.py
Normal file
17
dungeonbattle/display/test.py
Normal file
@ -0,0 +1,17 @@
|
||||
import curses
|
||||
import time
|
||||
|
||||
def main(screen) :
|
||||
pad = curses.newpad(curses.LINES, curses.COLS)
|
||||
with open("ascii_art.txt", "r") as file:
|
||||
title = file.read().split("\n")
|
||||
|
||||
width = len(title[0])
|
||||
for i in range(len(title)) :
|
||||
pad.addstr(4+i,curses.COLS//2-width//2-1,title[i])
|
||||
pad.refresh(0,0,0,0,curses.LINES,curses.COLS)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
|
||||
curses.wrapper(main)
|
Loading…
Reference in New Issue
Block a user