summaryrefslogtreecommitdiff
path: root/src/mapdata.py
diff options
context:
space:
mode:
authorColin Noga <Tempus@Spectrum-Song.local>2011-11-04 22:02:59 -0500
committerColin Noga <Tempus@Spectrum-Song.local>2011-11-04 22:02:59 -0500
commita8d9f1a2ccfb412af8b9d0a9398247204bfc05d1 (patch)
treeae17551d1a7183a645674f3c0240f48de087e392 /src/mapdata.py
parent38e50fb9870ff1b253a28ba6143339727a5b476f (diff)
parente47b198bb0d967282de1e170d9d0fe17e45b4910 (diff)
downloadkoopatlas-a8d9f1a2ccfb412af8b9d0a9398247204bfc05d1.tar.gz
koopatlas-a8d9f1a2ccfb412af8b9d0a9398247204bfc05d1.zip
Merge branch 'master' of ssh://treeki.shacknet.nu:30000/Koopatlas
Diffstat (limited to '')
-rw-r--r--src/mapdata.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/mapdata.py b/src/mapdata.py
index 5e65599..b43ff38 100644
--- a/src/mapdata.py
+++ b/src/mapdata.py
@@ -1,5 +1,21 @@
from common import *
+TILE_SIZE = (24,24)
+MAP_SIZE_IN_TILES = (512,512)
+MAP_SIZE = (MAP_SIZE_IN_TILES[0] * TILE_SIZE[0], MAP_SIZE_IN_TILES[1] * TILE_SIZE[1])
+
+class KPObject(object):
+ def __init__(self):
+ self.position = (0,0)
+ self.size = (1,1)
+ self.kind = 0
+ self.cache = []
+ self.tileset = None
+
+ def updateCache(self):
+ self.cache = KP.map.tilesets[self.tileset].objects[self.kind].render(self.size)
+
+
class KPLayer(object):
def __repr__(self):
return "<KPLayer %r>" % self.name
@@ -9,6 +25,59 @@ class KPLayer(object):
self.tileset = ''
self.objects = []
self.visible = True
+ self.cache = []
+
+ def updateCache(self):
+ x1, x2 = MAP_SIZE_IN_TILES[0] - 1, 0
+ y1, y2 = MAP_SIZE_IN_TILES[1] - 1, 0
+
+ for obj in self.objects:
+ pos, size = obj.position, obj.size
+
+ if pos[0] < x1:
+ x1 = pos[0]
+ if pos[1] < y1:
+ y1 = pos[1]
+ if (pos[0] + size[0]) > x2:
+ x2 = pos[0] + size[0]
+ if (pos[1] + size[1]) > y2:
+ y2 = pos[1] + size[1]
+
+
+ # resize the cache if needed
+ cache = self.cache
+ size = (x2 - x1, y2 - y1)
+ width, height = size
+ oldSize = self.cacheSize
+
+ if oldSize[1] < size[1]:
+ for i in xrange(size[1] - oldSize[1]):
+ cache.append([0 for i in xrange(width)])
+ elif oldSize[1] > size[1]:
+ del cache[size[1]:]
+
+ for i, elem in enumerate(cache):
+ if len(elem) != width:
+ cache[i] = [0 for i in xrange(width)]
+
+ self.cacheBasePos = (x1, y1)
+ self.cacheSize = size
+
+ # now generate the thing
+ for obj in self.objects:
+ oX, oY = obj.position
+ baseX = oX - x1
+ y = oY - y1
+
+ for row in obj.cache:
+ destRow = cache[y]
+ x = baseX
+ for tile in row:
+ destRow[x] = tile
+ x += 1
+ y += 1
+
+
class KPNodeAction(object):
@@ -52,6 +121,7 @@ class KPMap(object):
self.nodes = []
self.paths = []
self.doodads = []
+ self.tilesets = {}
# LAYERS