import map import utils class WaterTile(map.Tile): def __init__(self, pos, source=False, noupdate=False): self.source = source self.noupdate = noupdate if source: self.waterlevel = 10 # ten is maximum else: self.waterlevel = 0 super(WaterTile, self).__init__(pos, "liquid", "water") def update(self, tiles): if self.noupdate: self.noupdate = False return if self.waterlevel == 0 or self.waterlevel == 1: # we can't spread water, so don't update return # get a list of all tiles around current tile surround = utils.BoardUtils.surround(self.getCoords()) dist = False for i in surround: tile = utils.BoardUtils.tileAtPosition(tiles, i) if not tile: # there's no tile here, so create one t = WaterTile(i, noupdate=True) t.waterlevel = 1 tiles.append(t) dist = True elif tile.name == "water": # we can populate into this tile tile.waterlevel += 1 dist = True if dist and not self.source: self.waterlevel -= 1 def render(self): return "s"