Mercurial > qq
changeset 14:441252535ee9
change the level file format
| author | Radomir Dopieralski <moindev@sheep.art.pl> |
|---|---|
| date | Thu, 28 Aug 2008 12:10:21 +0200 |
| parents | 320ce875b24d |
| children | d8731b40e57e |
| files | level.map qq.py |
| diffstat | 2 files changed, 47 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/level.map Thu Aug 28 11:24:14 2008 +0200 +++ b/level.map Thu Aug 28 12:10:21 2008 +0200 @@ -1,24 +1,38 @@ [level] -tileset = ground.png -\#: wall -\.: floor -\@: player -\S: skeleton -\b: crate -\>: stairs -\h: house -map: ###.########### - #.......#.#.#.# - #.>....#.#.h.## - #...@.......#.# - #......s...#.## - #.............. - ##.#.#.#...#.## - #...........#.# - ##.#.#.#......# - ...........s..# - ##.##.###..b..# - #..##.###.bb#.# - ##.##.###....## - #.....###...#.# - ############### +tileset: ground.png +map:###.########### + #.......#.#.#.# + #.>....#.#.h.## + #...@.......#.# + #......s...#.## + #.............. + ##.#.#.#...#.## + #...........#.# + ##.#.#.#......# + ...........s..# + ##.##.###..b..# + #..##.###.bb#.# + ##.##.###....## + #.....###...#.# + ############### + +[#] +name: wall + +[.] +name: floor + +[@] +name: player + +[s] +name: skeleton + +[>] +name: stairs + +[b] +name: crate + +[h] +name: house
--- a/qq.py Thu Aug 28 11:24:14 2008 +0200 +++ b/qq.py Thu Aug 28 12:10:21 2008 +0200 @@ -88,6 +88,7 @@ self.animation.next() class Items: + """ Group all the item classes together.""" Wall = 0 Floor = 1 Stairs = 4 @@ -110,6 +111,7 @@ class Player(Sprite): + """ Display and animate the player character.""" is_player = True def __init__(self, pos=(1, 1)): @@ -139,16 +141,18 @@ class Level: + """ Load and store the map of the level, together with all the items.""" def __init__(self, filename="level.map"): + """ Load the level from specified file.""" parser = ConfigParser.ConfigParser() parser.read(filename) self.items = {} self.key = {} self.map = parser.get("level", "map").split("\n") - for option in parser.options("level"): - if option.startswith('\\'): - value = parser.get("level", option).strip() - self.key[option[1]] = getattr(Items, value.capitalize()) + for section in parser.sections(): + if len(section) == 1: + value = parser.get(section, "name") + self.key[section] = getattr(Items, value.capitalize()) tile_width, tile_height = 24, 16 self.tiles = tiles(parser.get("level", "tileset"), tile_width, tile_height) @@ -205,12 +209,14 @@ y += 1 def __call__(self, x, y): + """ Tell what is at this position on the map.""" try: return self.key[self.map[y][x]] except IndexError: return None def draw(self, surface): + """ Draw the map on the provided surface.""" surface.blit(self.image, (0, 0))
