From 65ac156131c0cc874f5e908bb925a647ed3c8de8 Mon Sep 17 00:00:00 2001 From: Treeki Date: Fri, 4 Nov 2011 04:40:25 +0100 Subject: lots of unfinished tileset stuff --- src/tileset.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/tileset.py (limited to 'src/tileset.py') diff --git a/src/tileset.py b/src/tileset.py new file mode 100644 index 0000000..7fa8733 --- /dev/null +++ b/src/tileset.py @@ -0,0 +1,89 @@ +from common import * + +class KPObjectDefinition(object): + def __init__(self): + self.rows = [] + + def render(self, size): + buf = [] + + beforeRepeat = [] + inRepeat = [] + afterRepeat = [] + + foundRepeat = False + for row in self.rows: + if (row[0][0] & 2) != 0: + inRepeat.append(row) + foundRepeat = True + else: + if foundRepeat: + afterRepeat.append(row) + else: + beforeRepeat.append(row) + + bC, iC, aC = len(beforeRepeat), len(inRepeat), len(afterRepeat) + + if iC == 0: + for y in xrange(size[1]): + buf.append(self._renderRow(beforeRepeat[y % bC], size[0])) + else: + middleUntil = size[1] - aC + + for y in xrange(size[1]): + if y < bC: + buf.append(self._renderRow(beforeRepeat[y], size[0])) + elif y < middleUntil: + buf.append(self._renderRow(inRepeat[(y - bC) % iC], size[0])) + else: + buf.append(self._renderRow(afterRepeat[y - bC - iC], size[0])) + + return buf + + def _renderRow(self, row, width): + buf = [-1 for i in xrange(width)] + + beforeRepeat = [] + inRepeat = [] + afterRepeat = [] + + foundRepeat = False + for tile in row: + if (tile[0] & 1) != 0: + inRepeat.append(tile[1]) + foundRepeat = True + else: + if foundRepeat: + afterRepeat.append(tile[1]) + else: + beforeRepeat.append(tile[1]) + + bC, iC, aC = len(beforeRepeat), len(inRepeat), len(afterRepeat) + + if iC == 0: + for x in xrange(width): + buf[x] = beforeRepeat[x % bC] + else: + middleUntil = width - aC + + for x in xrange(width): + if x < bC: + buf[x] = beforeRepeat[y] + elif x < middleUntil: + buf[x] = inRepeat[(y - bC) % iC] + else: + buf[x] = afterRepeat[y - bC - iC] + + return buf + + + + + + +class KPTileset(object): + def __init__(self): + self.texture = None + self.objects = [] + + -- cgit v1.2.3