def testgetTilesInPixelArea_MultipleTilesPartial(self): setupPlayfield([\ 'BB', \ 'BB']) tiles = list(playfield.getTilesInPixelArea(2, 2, 10, 10)) self.assertEqual(4, len(tiles)) self.assertEqual(playfield.getTile(0, 0), tiles[0]) self.assertEqual(playfield.getTile(1, 0), tiles[2]) self.assertEqual(playfield.getTile(0, 1), tiles[1]) self.assertEqual(playfield.getTile(1, 1), tiles[3])
def testgetTilesInPixelArea_SingleTile(self): setupPlayfield([\ 'BB', \ 'BB']) tiles = list(playfield.getTilesInPixelArea(0, 0, 8, 8)) self.assertEqual(1, len(tiles)) self.assertEqual(playfield.getTile(0, 0), tiles[0])
def writeLevelLayoutToFile(file): for y in range(playfield.height): for x in range(playfield.width): tankSpawner = findTankSpawnerAtTile((x, y)) tile = playfield.getTile(x, y) if baseLocation == (x, y): file.write('X') elif playerStartLocation == (x, y): file.write('P') elif tankSpawner != None: file.write('S') elif tile == None: file.write('_') elif tile.tileType == playfield.TileType.BRICK: file.write('B') elif tile.tileType == playfield.TileType.CONCRETE: file.write('C') elif tile.tileType == playfield.TileType.WATER: file.write('~') elif tile.tileType == playfield.TileType.TREE: file.write('^') file.write('\n')
def generateTerrainBasedGrid(grid, cellValueFunction): for x in range(grid.width): for y in range(grid.height): tile = playfield.getTile(x, y) grid.set(x, y, cellValueFunction(tile))