############################################################################# ## This file is part of TunnelHack II. ## ##-------------------------------------------------------------------------## ## Copyright 2007-2008 Bryce Schroeder ## ## bryce.schroeder@gmail.com ## ## http://www.ferazelhosting.net/~bryce/ ## ##-------------------------------------------------------------------------## ## This program is free software: you can redistribute it and/or modify ## ## it under the terms of the GNU General Public License as published by ## ## the Free Software Foundation, either version 3 of the License, or ## ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## ## along with this program. If not, see . ## ############################################################################# from .standard_interpreters import Resource, R import cStringIO import pygame class Tile: def __init__(self, x, y, descriptor, set): #ppdrr self.set = set self.descriptor = descriptor self.x = x self.y = y def blit(self, target, x, y): """Draw this tile onto the target.""" target.blit(self.set.image, (x,y), (self.x*32,self.y*32,32,32)) class Tileset(Resource): MANDATORY = ['image', 'map'] #OPTIONAL = ['meta'] def init(self): self.meta = {} if self.parts.has_key('meta'): self.meta = self.process_meta(self.parts['meta']) self.image = pygame.image.load(cStringIO.StringIO( self.parts['image'])).convert_alpha() self.tiles = [] y = 0 for row in self.parts['map'].split("\n"): x = 0 for collumn in row.split(): if collumn[0] != '-': self.tiles.append(Tile(x,y,collumn,self)) else: self.tiles.append(None) x += 1 y += 1 def get(self, index): return self.tiles[index] #def load_palette(self):