diff options
author | Colin Noga <Tempus@Spectrum-Song.local> | 2011-11-04 22:02:59 -0500 |
---|---|---|
committer | Colin Noga <Tempus@Spectrum-Song.local> | 2011-11-04 22:02:59 -0500 |
commit | a8d9f1a2ccfb412af8b9d0a9398247204bfc05d1 (patch) | |
tree | ae17551d1a7183a645674f3c0240f48de087e392 /src/tileset.py | |
parent | 38e50fb9870ff1b253a28ba6143339727a5b476f (diff) | |
parent | e47b198bb0d967282de1e170d9d0fe17e45b4910 (diff) | |
download | koopatlas-a8d9f1a2ccfb412af8b9d0a9398247204bfc05d1.tar.gz koopatlas-a8d9f1a2ccfb412af8b9d0a9398247204bfc05d1.zip |
Merge branch 'master' of ssh://treeki.shacknet.nu:30000/Koopatlas
Diffstat (limited to 'src/tileset.py')
-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 = [] + + |