demo under construction

This commit is contained in:
randomuser 2022-04-28 06:54:28 -05:00
parent 413a3a19ca
commit 34d7984b73
3 changed files with 70 additions and 1 deletions

32
demo.py Normal file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env python3
from map import *
from render import *
def main():
textures = []
textures.append(Texture("char", "#", "hash"))
textures.append(Texture("mchar", "simple", "simple"))
for i in textures:
i.load()
tiles = []
for i in range(10, 20):
for j in range(2, 8):
t = Tile([i, j], "placeholder")
t.addTexture(textures[0])
tiles.append(t)
t = Tile([23, 2], "placeholder")
t.addTexture(textures[1])
tiles.append(t)
render = Renderer()
[render.addTile(i) for i in tiles]
render.finalRender()
if __name__ == "__main__":
main()

3
map.py
View File

@ -79,7 +79,8 @@ class Tile:
this Tile is visible. this Tile is visible.
""" """
try: try:
return self.textures[0] # this is unsafe, do something different as default
return self.textures[list(self.textures.keys())[0]].texture
except IndexError: except IndexError:
raise TileError("no textures to render!") raise TileError("no textures to render!")

View File

@ -21,6 +21,13 @@ class Renderer:
if i.ttype == "standard": if i.ttype == "standard":
i.update(self.tiles) i.update(self.tiles)
def inViewport(self, pos):
if pos[0] < 0 or pos[0] > self.viewport[0] - 1:
return False
if pos[1] < 0 or pos[1] > self.viewport[1] - 1:
return False
return True
def selectForRendering(self): def selectForRendering(self):
""" """
Returns what tiles are in the viewport. Returns what tiles are in the viewport.
@ -45,3 +52,32 @@ class Renderer:
return tilesInScene return tilesInScene
def render(self):
board = [ ["."] * 24 ] * 80
toRender = self.selectForRendering()
for tile in toRender:
rendered = tile.render()
print(rendered)
coords = tile.getCoords()
print(len(rendered), len(rendered[0]))
for j in range(len(rendered)):
for i in range(len(rendered[0])):
print(coords[0], coords[1])
print(i, j)
board[i + coords[0]][j + coords[1]] = rendered[i][j]
return board
def finalRender(self):
rendered = self.render()
for j in range(self.viewport[1] - 1):
buf = []
for i in range(self.viewport[0] - 1):
buf.append(rendered[i][j])
print(''.join(buf))