48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
class RendererLoopBreak(BaseException):
|
|
pass
|
|
|
|
class Renderer:
|
|
"""
|
|
Class responsible for updating tiles, their states, animations, etc.
|
|
|
|
In the future, also takes in a WaterLayer and updates it with the game map.
|
|
"""
|
|
def __init__(self):
|
|
self.tiles = []
|
|
# location of the top left corner of the viewpoint
|
|
self.pos = [0, 0]
|
|
self.viewport = [80, 24]
|
|
|
|
def addTile(self, tile):
|
|
self.tiles.append(tile)
|
|
|
|
def massUpdate(self):
|
|
for i in self.tiles:
|
|
if i.ttype == "standard":
|
|
i.update(self.tiles)
|
|
|
|
def selectForRendering(self):
|
|
"""
|
|
Returns what tiles are in the viewport.
|
|
"""
|
|
|
|
tilesInScene = []
|
|
|
|
for i in self.tiles:
|
|
dims = i.dims
|
|
pos = i.getCoords()
|
|
|
|
try:
|
|
for j in range(dims[0]):
|
|
for k in range(dims[1]):
|
|
if self.inViewport([pos[0] + j, pos[1] + k]):
|
|
tilesInScene.append(i)
|
|
raise RendererLoopBreak
|
|
except RendererLoopBreak:
|
|
pass
|
|
|
|
self.cachedTiles = tilesInScene
|
|
|
|
return tilesInScene
|
|
|