Mercurial > rinkhals
comparison 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 |
comparison
equal
deleted
inserted
replaced
217:76faa0eb38f0 | 218:5cb0e0b9cd16 |
---|---|
39 yield n | 39 yield n |
40 | 40 |
41 TILE_MAP = TileMap() | 41 TILE_MAP = TileMap() |
42 REVERSE_TILE_MAP = TILE_MAP._reverse_map | 42 REVERSE_TILE_MAP = TILE_MAP._reverse_map |
43 | 43 |
44 class FarmSprites(list): | |
45 def __init__(self): | |
46 list.__init__(self) | |
47 self.removed = [] | |
48 self._cursor = None | |
49 | |
50 def append(self, sprite): | |
51 if self._cursor is not None: | |
52 # pop cursor | |
53 assert(self._cursor is self.pop()) | |
54 list.append(self, sprite) | |
55 list.append(self, self._cursor) | |
56 else: | |
57 list.append(self, sprite) | |
58 sprite.updated = 1 | |
59 | |
60 def remove(self, sprite): | |
61 list.remove(self, sprite) | |
62 sprite.updated = 1 | |
63 self.removed.append(sprite) | |
64 | |
65 def set_cursor(self, cursor): | |
66 if self._cursor is not None: | |
67 self.remove(self._cursor) | |
68 self._cursor = cursor | |
69 if cursor is not None: | |
70 list.append(self, cursor) | |
71 | |
44 | 72 |
45 class FarmVid(tilevid.Tilevid): | 73 class FarmVid(tilevid.Tilevid): |
46 """Extension of pgu's TileVid class to handle the complications | 74 """Extension of pgu's TileVid class to handle the complications |
47 of raising chickens. | 75 of raising chickens. |
48 """ | 76 """ |
49 def __init__(self): | 77 def __init__(self): |
50 tilevid.Tilevid.__init__(self) | 78 tilevid.Tilevid.__init__(self) |
79 self.sprites = FarmSprites() | |
51 | 80 |
52 def png_folder_load_tiles(self, path): | 81 def png_folder_load_tiles(self, path): |
53 """Load tiles from a folder of PNG files.""" | 82 """Load tiles from a folder of PNG files.""" |
54 for dirpath, dirnames, filenames in os.walk(path): | 83 for dirpath, dirnames, filenames in os.walk(path): |
55 abstract_dirpath = "/".join(dirpath.split(os.path.sep)) | 84 abstract_dirpath = "/".join(dirpath.split(os.path.sep)) |