diff options
author | Treeki <treeki@gmail.com> | 2011-11-04 04:40:25 +0100 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2011-11-04 04:40:25 +0100 |
commit | 65ac156131c0cc874f5e908bb925a647ed3c8de8 (patch) | |
tree | 5c6f5860048b2f1eca19bd02a6f82e02dffded92 /src/tileset.py | |
parent | e86dd60fb52a68ef96930bfa4f2632265bf629fa (diff) | |
download | koopatlas-65ac156131c0cc874f5e908bb925a647ed3c8de8.tar.gz koopatlas-65ac156131c0cc874f5e908bb925a647ed3c8de8.zip |
lots of unfinished tileset stuff
Diffstat (limited to '')
-rw-r--r-- | src/tileset.py | 89 |
1 files changed, 89 insertions, 0 deletions
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 = [] + + |