示例#1
0
    def addUnit(self, unit):
        global mapSize
        unit.tile = self
        self.units.append(unit)
        img = QImage(unit.image).scaledToWidth(self.getImageRect().width())
        if unit.owner:
            rect = img.rect()
            painter = QPainter(img)
            painter.setPen(unit.owner.unitColor())
            painter.drawEllipse(rect)

            hpWidth = 20
            greenWidth = unit.hp / float(unit.maxHp) * hpWidth
            painter.fillRect(5, 5, greenWidth, 5, Qt.green)
            painter.fillRect(5 + greenWidth, 5, hpWidth-greenWidth, 5, Qt.red)
            painter.end()
        image = QGraphicsPixmapItem(QPixmap(img), self)
        if mapSize == 0:
            mapSize = 1
        image.setOffset(self.x + 12/(2*mapSize), self.y + 10/(2*mapSize))
        self.unitImages.append(image)
示例#2
0
 def addUnit(self, unit):
     unit.tile = self
     self.units.append(unit)
     image = QGraphicsPixmapItem(QPixmap(unit.image), self)
     image.setOffset(self.x + 12, self.y + 10)
     self.unitImages.append(image)