diff gamelib/tiles.py @ 218:5cb0e0b9cd16

Make sprite cursors stay on top by fudging the sprite list. :/
author Simon Cross <hodgestar@gmail.com>
date Fri, 04 Sep 2009 22:12:47 +0000
parents a4e3d26d16f0
children e694aa7731ed
line wrap: on
line diff
--- a/gamelib/tiles.py	Fri Sep 04 22:11:47 2009 +0000
+++ b/gamelib/tiles.py	Fri Sep 04 22:12:47 2009 +0000
@@ -41,6 +41,34 @@
 TILE_MAP = TileMap()
 REVERSE_TILE_MAP = TILE_MAP._reverse_map
 
+class FarmSprites(list):
+    def __init__(self):
+        list.__init__(self)
+        self.removed = []
+        self._cursor = None
+
+    def append(self, sprite):
+        if self._cursor is not None:
+            # pop cursor
+            assert(self._cursor is self.pop())
+            list.append(self, sprite)
+            list.append(self, self._cursor)
+        else:
+            list.append(self, sprite)
+        sprite.updated = 1
+
+    def remove(self, sprite):
+        list.remove(self, sprite)
+        sprite.updated = 1
+        self.removed.append(sprite)
+
+    def set_cursor(self, cursor):
+        if self._cursor is not None:
+            self.remove(self._cursor)
+        self._cursor = cursor
+        if cursor is not None:
+            list.append(self, cursor)
+
 
 class FarmVid(tilevid.Tilevid):
     """Extension of pgu's TileVid class to handle the complications
@@ -48,6 +76,7 @@
        """
     def __init__(self):
         tilevid.Tilevid.__init__(self)
+        self.sprites = FarmSprites()
 
     def png_folder_load_tiles(self, path):
         """Load tiles from a folder of PNG files."""