Пример #1
0
 def test_moveNotOk(self):
     parent = Mock()
     parent.moveOk = Mock(return_value=False)
     tile_sprite = TileSprite(manager, imageFilename, parent, x, y, gtk)
     assert_equal((0,0), tile_sprite.getXY())
     assert_equal(False, tile_sprite.move((0,1)))
     assert_equal((0,0), tile_sprite.getXY())
Пример #2
0
 def test_paintImage(self):
     tile_sprite = TileSprite(manager, imageFilename, parent, x, y, gtk)
     tile_sprite._image = Mock()
     tile_sprite._image.blit = Mock()
     screen = None
     location = (x,y)
     tile_sprite.paint(screen, location)
     tile_sprite._image.blit.assert_called_once()
Пример #3
0
    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()
Пример #4
0
 def __init__(self, manager, name, position, imageFileName, parent, gtk):
     TileSprite.__init__(self, manager, imageFileName, parent, position[0], position[1], gtk)
     self.name = 'Door'
     self.value = 100
     self.amt = 1
Пример #5
0
    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)
Пример #6
0
 def test_printm(self):
     manager.notify = Mock()
     tile_sprite = TileSprite(manager, imageFilename, parent, x, y, gtk)
     tile_sprite.printm("test text")
     manager.notify.assert_called_once()
Пример #7
0
 def test_paint(self):
     tile_sprite = TileSprite(manager, imageFilename, parent, x, y, gtk)
     tile_sprite._image = None
     screen = None
     location = (x,y)
     tile_sprite.paint(screen, location)
Пример #8
0
 def test_occupiedSomeoneElseNoOneThere(self):
     tile_sprite = TileSprite(manager, imageFilename, parent, x, y, gtk)
     assert_equal(False, tile_sprite.occupied((x+1, y+1)))
Пример #9
0
 def test_occupiedBySelf(self):
     tile_sprite = TileSprite(manager, imageFilename, parent, x, y, gtk)
     assert_equal(1, tile_sprite.occupied((x,y)))
Пример #10
0
 def test_getXY(self):
     tile_sprite = TileSprite(manager, imageFilename, parent, x, y, gtk)
     assert_equal((x,y), tile_sprite.getXY())