115 lines
3.3 KiB
Python
115 lines
3.3 KiB
Python
# Render the window
|
|
|
|
import curses
|
|
|
|
class Render():
|
|
|
|
def __init__(self):
|
|
print("Starting Render-Engine")
|
|
|
|
|
|
def renderScreen(stdscr, gamestate, centerx, centery):
|
|
|
|
# Calculate what to render
|
|
# Get screen y and x
|
|
height, width = stdscr.getmaxyx()
|
|
|
|
top_left_x = centerx - round(width/2)
|
|
top_left_y = centery - round(height/2)
|
|
|
|
xoffset = 0
|
|
yoffset = 0
|
|
if width > gamestate.metadata['width']:
|
|
xoffset = round( (width - gamestate.metadata['width'])/2 )
|
|
if height > gamestate.metadata['height']:
|
|
yoffset = round( (height-gamestate.metadata['height'])/2 )
|
|
|
|
|
|
# Draw the visible segment of the map
|
|
for y in range(1,height):
|
|
top_left_x = centerx - round(width/2)
|
|
for x in range(1,width-3):
|
|
if top_left_y <= 0 or top_left_y > gamestate.metadata['height'] or top_left_x <= 0 or top_left_x > gamestate.metadata['width']:
|
|
stdscr.addstr( y-1, x-1, " ", curses.color_pair(7))
|
|
elif gamestate.terrain[top_left_x][top_left_y] == "l":
|
|
stdscr.addstr( y-1, x-1, "+", curses.color_pair(1) )
|
|
elif gamestate.terrain[top_left_x][top_left_y] == "w":
|
|
stdscr.addstr( y-1, x-1, ".", curses.color_pair(2) )
|
|
elif gamestate.terrain[top_left_x][top_left_y] == "c":
|
|
stdscr.addstr( y-1, x-1, "*" )
|
|
top_left_x += 1
|
|
top_left_y += 1
|
|
|
|
|
|
##### Print the horizontal ruler at the bottom of the screen
|
|
xruler = ""
|
|
xrulery = 0
|
|
xrulerx = 0
|
|
xrulerx_offset = 0
|
|
|
|
|
|
if width > gamestate.metadata['width']:
|
|
xrulerx_offset = xoffset + 1
|
|
xrulerx = gamestate.metadata['width']
|
|
elif width < gamestate.metadata['width']:
|
|
xrulerx = width
|
|
else:
|
|
xrulerx = gamestate.metadata['width']
|
|
|
|
|
|
if gamestate.metadata['height']-1 < height-1:
|
|
xrulery = yoffset+gamestate.metadata['height']
|
|
else:
|
|
xrulery = height-1
|
|
|
|
|
|
skip = 0
|
|
if width > gamestate.metadata['width']:
|
|
xruler_start = 0
|
|
xruler_end = gamestate.metadata['width']
|
|
else:
|
|
xruler_start = centerx - round(width/2)
|
|
xruler_end = (xruler_start + width) - 4
|
|
|
|
for scale in range(xruler_start,xruler_end):
|
|
if skip != 0:
|
|
skip-=1
|
|
continue
|
|
if scale%10 == 0:
|
|
skip=len(str(scale))-1
|
|
xruler+=str(scale)
|
|
elif str(scale)[-1:]=="5":
|
|
xruler+="|"
|
|
else:
|
|
xruler+="."
|
|
stdscr.addstr( xrulery, xrulerx_offset, xruler )
|
|
|
|
|
|
##### Print the verticle ruler
|
|
yruler = centery - round(height/2)
|
|
yruler_offset = 0
|
|
yrulery = 1
|
|
#yruler = 0
|
|
yrulerx = 0
|
|
|
|
if width > gamestate.metadata['width']:
|
|
yrulerx = int((width - gamestate.metadata['width'])/2)+1+gamestate.metadata['width']
|
|
yruler_offset = (width - gamestate.metadata['width'])/2
|
|
elif gamestate.metadata['width'] < width-4:
|
|
yrulerx = gamestate.metadata['width']
|
|
else:
|
|
yrulerx = width-4
|
|
|
|
while yrulery < height-1 and yrulery-yruler_offset < gamestate.metadata['height'] and yruler <= gamestate.metadata['height']-1:
|
|
if yruler >= 0:
|
|
if yruler%5==0:
|
|
yruler_text = "{: >3}".format( yruler )
|
|
stdscr.addstr( yrulery, yrulerx, yruler_text )
|
|
else:
|
|
stdscr.addstr( yrulery, yrulerx, "{: >3}".format(".") )
|
|
yruler+=1
|
|
yrulery+=1
|
|
|
|
# Return stdscr asif nothing happened
|
|
return stdscr
|