From 34d7984b7386d7b436c46f38af25c72112634584 Mon Sep 17 00:00:00 2001 From: randomuser Date: Thu, 28 Apr 2022 06:54:28 -0500 Subject: [PATCH] demo under construction --- demo.py | 32 ++++++++++++++++++++++++++++++++ map.py | 3 ++- render.py | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 demo.py diff --git a/demo.py b/demo.py new file mode 100644 index 0000000..d12aad6 --- /dev/null +++ b/demo.py @@ -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() diff --git a/map.py b/map.py index 915a2a4..9131473 100644 --- a/map.py +++ b/map.py @@ -79,7 +79,8 @@ class Tile: this Tile is visible. """ try: - return self.textures[0] + # this is unsafe, do something different as default + return self.textures[list(self.textures.keys())[0]].texture except IndexError: raise TileError("no textures to render!") diff --git a/render.py b/render.py index ae76006..163bc7e 100644 --- a/render.py +++ b/render.py @@ -21,6 +21,13 @@ class Renderer: if i.ttype == "standard": 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): """ Returns what tiles are in the viewport. @@ -45,3 +52,32 @@ class Renderer: 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)) + + +