示例#1
0
 def squares(self):
     shape2 = QGraphicsRectItem(0,0,40,40)
     shape2.setX(self.game.endSquare.x)
     shape2.setY(self.game.endSquare.y)
     shape2.setBrush(QColor(0,0,200,0))
     shape2.setPen(QColor(0,0,0,0))
     self.scene.addItem(shape2)
     self.game.endSquare.shape = shape2
     
     self.update()
示例#2
0
 def drawTowers(self):
     for tower in self.game.towers:
         if tower.shape == None:
             shape = QGraphicsRectItem(0,0,40,40)
             shape.setX(tower.x)
             shape.setY(tower.y)
             if tower.ttype == 1:
                 shape.setBrush(QColor(120,100,20))
             elif tower.ttype == 2:
                 shape.setBrush(QColor(70,70,50))
             elif tower.ttype ==3:
                 shape.setBrush(QColor(20,20,20))
             self.scene.addItem(shape)
             tower.shape = shape
             #r = QGraphicsEllipseItem(tower.x+20-tower.range,tower.y+20-tower.range,tower.range*2,tower.range*2)
             #self.scene.addItem(r)
         if tower.ttype == 3:
             for enemy in self.game.enemies:
                 if tower.canFire(enemy):
                     if enemy in tower.firesAt:
                         i = tower.firesAt.index(enemy)
                         tower.lines[i].setLine(tower.x+20,tower.y+20,enemy.x,enemy.y)
                     else:
                         line = QGraphicsLineItem(tower.x+20,tower.y+20,enemy.x,enemy.y)
                         line.setPen(QColor(255,0,0))
                         self.scene.addItem(line)
                         tower.firesAt.append(enemy)
                         tower.lines.append(line)
                     enemy.hp -= tower.damage
                     if enemy.hp <= 0:
                         i = tower.firesAt.index(enemy)
                         self.scene.removeItem(tower.lines[i])
                 else:
                     if enemy in tower.firesAt:
                         i = tower.firesAt.index(enemy)
                         self.scene.removeItem(tower.lines[i])