Пример #1
0
    def move(self):
        self.angle = calc_angle(self.position, self.target.position)
        t = QtGui.QTransform().rotateRadians(self.angle)
        self.state = (self.state + 1) % 7
        pixmap = QtGui.QPixmap(self.paths[self.state])
        pixmap = pixmap.transformed(t)
        pos = self.position
        pos = (pos[0] - self.speed*math.cos(self.angle+(math.pi/2)),
               pos[1] - self.speed*math.sin(self.angle+(math.pi/2)))
        self.position = pos

        # Para evitar choques entre zombies
        #for zombie in self.ventana.zombies:
        #    if death_collision(self, zombie):
        #        pos = random.choice((pos[0] + math.cos(self.angle), pos[1] + math.sin(self.angle)),
        #                           (pos[0] - math.cos(self.angle), pos[1] - math.sin(self.angle)))
        #        self.position = pos

        self.image.setPixmap(pixmap)
        if self.damage > 0:
            if death_collision(self, self.target):
                self.target.hit(self.damage)
                self.damage = 0
                self.no_damage_iterations = 1
        else:
            if self.no_damage_iterations >= 3:
                self.damage = 1
            else:
                self.no_damage_iterations += 1
Пример #2
0
 def __init__(self, parent, x, y, c):
     path = "img/bullet.gif"
     super().__init__(parent, path, x, y)
     self.initial = (x, y)
     self.hp = 10
     self.click = c
     self.angle = calc_angle(self.position, self.click)
     self.dim = 6
     self.range = 350
     self.image.setGeometry(self.position[0], self.position[1], self.dim, self.dim)
     self.__center = (self.position[0] + self.dim/2, self.position[1] + self.dim/2)
     self.timer = QtCore.QTimer(self.ventana)
     self.timer.timeout.connect(self.move)
     self.timer.start(10)