def addTileSprites(self, tile): if tile.terrain != None: if tile.terrain == Terrain.MOUNTAIN: batch_group = self.big_terrain_group else: batch_group = self.terrain_group terr_sprite = TileSprite( map_pos = tile.getMapPos(), sprite_type = SpriteType.TERRAIN, img = tile.terrainImg(), batch = self.batch, group = batch_group) pos = tile.getAbsolutePixelPos() terr_sprite.x = (pos[0] - self.cam_pos[0]) terr_sprite.y = (pos[1] + self.cam_pos[1]) self.draw_list.append(terr_sprite) if tile.feature != None: ftr_sprite = TileSprite(map_pos = tile.getMapPos(), sprite_type = SpriteType.FEATURE, img = tile.featureImg(), batch = self.batch, group = self.feature_group) pos = tile.getAbsolutePixelPos() ftr_sprite.x = pos[0] - self.cam_pos[0] ftr_sprite.y = pos[1] + self.cam_pos[1] if tile.feature == Feature.FOREST: ftr_sprite.scale = 0.8 self.draw_list.append(ftr_sprite) if len(tile.unit_list) > 0: unit_sprite = TileSprite( map_pos = tile.getMapPos(), sprite_type = SpriteType.UNIT, img = tile.unitImg(), batch = self.batch, group = self.unit_group) pos = tile.getAbsolutePixelPos() unit_sprite.x = pos[0] - self.cam_pos[0] unit_sprite.y = pos[1] + self.cam_pos[1] if tile.unit_list[0].unit_type == UnitType.SETTLER: #TODO: multiple units unit_sprite.scale = 0.8 self.draw_list.append(unit_sprite) self.unit_sprites.append(unit_sprite)
def moveUnit(self, unit, start_tile, end_tile): start_pos = start_tile.getMapPos() next_tile = end_tile if start_tile.getMapPos() == end_tile.getMapPos(): return unit_sprite = None sprite_found = False for spr in self.draw_list: if (spr.sprite_type == SpriteType.UNIT and spr.map_pos[0] == start_pos[0] and spr.map_pos[1] == start_pos[1]): spr.moveToMapIdx(next_tile.pos) spr.x = next_tile.abs_pixel_pos[0] - self.cam_pos[0] spr.y = next_tile.abs_pixel_pos[1] + self.cam_pos[1] sprite_found = True break """ This is re-adding any unit sprite that had been trimmed from being offscreen as soon as it moves. TODO: Check if the unit moved onto a tile within current camera view """ if not sprite_found: unit_sprite = TileSprite( map_pos = next_tile.getMapPos(), sprite_type = SpriteType.UNIT, img = next_tile.unitImg(), batch = self.batch, group = self.unit_group) pos = next_tile.getAbsolutePixelPos() unit_sprite.x = pos[0] - self.cam_pos[0] unit_sprite.y = pos[1] + self.cam_pos[1] if next_tile.unit_list[0].unit_type == UnitType.SETTLER: #TODO: multiple units unit_sprite.scale = 0.8 self.draw_list.append(unit_sprite) self.unit_sprites.append(unit_sprite) start_tile = self.map.tileAt(start_pos) start_tile.unit_list = list()