Пример #1
0
 def loadTiles(self, file):
     ''' load tilemap form a file '''
     tiles = []
     with open(file) as f:
         r = 0
         for line in f:
             c = 0
             row = []
             # split the data in tiles for the row
             rowdata = line.replace('\n', '')
             tiledata = rowdata.split(', ')
             # create each tile
             for tile in tiledata:
                 d = tile.strip('()').split(',')
                 newtile = Tile()
                 newtile.color = int(d[0])
                 newtile.ht = int(d[1])
                 newtile.hr = int(d[2])
                 newtile.hl = int(d[3])
                 newtile.hb = int(d[4])
                 newtile.r = r
                 newtile.c = c
                 row.append(newtile)
                 c += 1
             # add the row to the tile array
             tiles.append(row)
             r += 1
         self.tiles = tiles
Пример #2
0
 def createTiles(self, rows, columns):
     ''' Create a new blank tilemap '''
     tiles = []
     for r in range(rows):
         row = []
         for c in range(columns):
             newtile = Tile()
             newtile.color = 0
             newtile.ht = 0
             newtile.hr = 0
             newtile.hl = 0
             newtile.hb = 0
             newtile.r = r
             newtile.c = c
             row.append(newtile)
         tiles.append(row)
     self.tiles = tiles