class Edificio(MyThread): newid = next(funciones.counter()) # El generado de id, lo encontre en este link: # https://stackoverflow.com/questions/1045344/ # how-do-you-create-an-incremental-id-in-a-python-class def __init__(self, parent, tipo, team, back): super().__init__() self.id = Edificio.newid self.tipo = tipo self.team = team self.parent = parent if tipo == "Torre": self.torre_init(parent, team, back) elif tipo == "Inhibidor": self.inhib_init(parent, team, back) else: self.nexo_init(parent, team, back) def nexo_init(self, parent, team, back): self.image = Label(parent) self.image.barra = QtWidgets.QProgressBar(parent) self.parent = parent self.image.brain = self if team == "blue": self.image.setPixmap(QtGui.QPixmap("IMGS/nexus.png")) self.image.setGeometry(QtCore.QRect(30, 30, 100, 100)) self.image.barra.setGeometry(QtCore.QRect(30, 30 - 8, 100, 7)) self.position = (30, 30) else: self.image.setPixmap(QtGui.QPixmap("IMGS/red_nexus.png")) self.image.setGeometry(QtCore.QRect(1120, 600, 150, 120)) self.image.barra.setGeometry(QtCore.QRect(1140, 600 - 8, 100, 7)) self.position = (1120, 600) self.image.setText("") self.image.brain = self self.image.setScaledContents(True) self.image.setMouseTracking(True) self.image.setVisible(True) self.image.setObjectName("image") self.image.barra.setProperty("value", 100) self.image.barra.setTextVisible(False) self.image.barra.setObjectName("barra") back.make_connection = self.image self.image.raise_() self.image.show() self.agregar_constantes("Nexo") self.image.barra.setMaximum(self.life) self.image.barra.setProperty("value", self.life) def torre_init(self, parent, team, back): if team == "blue": self.pos_inicial = (150, 130) self.position = (150, 130) blue = "IMGS/blue.png" pixmap = QtGui.QPixmap(blue) size = 151, 100 else: self.pos_inicial = (1000, 500) self.position = (1000, 500) blue = "IMGS/t_purple.png" pixmap = QtGui.QPixmap(blue).transformed(QTransform().scale(-1, 1)) size = 80, 120 self.parent = parent self.image = Label(parent) self.image.brain = self self.image.setGeometry( QtCore.QRect(self.pos_inicial[0], self.pos_inicial[1], size[0], size[1])) self.image.setPixmap(pixmap) self.image.setScaledContents(True) self.image.setVisible(True) self.image.barra = QtWidgets.QProgressBar(parent) self.image.barra.setGeometry( QtCore.QRect(self.pos_inicial[0] + 30, self.pos_inicial[1] - 8, 100, 7)) self.image.barra.setTextVisible(False) self.image.barra.show() self.image.barra.raise_() back.make_connection = self.image self.image.show() self.agregar_constantes("Torre") self.image.barra.setMaximum(self.life) self.image.barra.setProperty("value", self.life) # self.trigger.connect(parent.actualizar_imagen) def inhib_init(self, parent, team, back): self.team = team if team == "blue": self.pos_inicial = (90, 90) self.position = (90, 90) else: self.pos_inicial = (1050, 570) self.position = (1050, 570) self.parent = parent self.image = Label(parent) self.image.brain = self self.image.setGeometry( QtCore.QRect(self.pos_inicial[0], self.pos_inicial[1], 120, 80)) self.image.setPixmap(QtGui.QPixmap("IMGS/inhib.png")) self.image.setScaledContents(True) self.image.setObjectName("label_2") self.image.setVisible(True) self.image.barra = QtWidgets.QProgressBar(parent) self.image.barra.setGeometry( QtCore.QRect(self.pos_inicial[0] + 33, self.pos_inicial[1] + 15, 50, 7)) self.image.barra.setTextVisible(False) self.image.barra.setInvertedAppearance(False) self.image.barra.show() self.image.barra.raise_() back.make_connection = self.image self.image.raise_() self.image.show() self.agregar_constantes("Inhibidor") self.image.barra.setMaximum(self.life) self.image.barra.setProperty("value", self.life) def run(self): self.inital_life = self.life self.image.show() self.image.barra.show() self.image.raise_() self.image.barra.raise_() self.__position = self.position while True: time.sleep(0.05) if self.life <= 0: self.image.barra.hide() self.image.hide() break
class Minion(MyThread): newid = next(funciones.counter()) def __init__(self, parent, tipo, team, back): super().__init__() self.id = Minion.newid self.parent = parent self.back = back self.team = team self.tipo = tipo self.agregar_constantes(tipo) self.image = Label(parent) self.image.thread = self self.image.setGeometry(QtCore.QRect(1000, 747, 50, 50)) self.distance_down = 50 self.distance_right = 50 self.image.setPixmap( QPixmap("IMGS/Minions/{}_{}.png".format(tipo, team))) self.image.setText("") self.image.setScaledContents(True) self.image.barra = QtWidgets.QProgressBar(parent) self.image.brain = self self.image.barra.setTextVisible(False) self.image.barra.setGeometry(QtCore.QRect(1000, 747, 50, 10)) self.image.barra.setProperty("value", 100) self.image.setMouseTracking(True) self.agregar_constantes(tipo) self._trigger.connect(parent.actualizar_imagen) back.make_connection = self.image if team == "blue": self.pos_inicial = (290, 241) else: self.pos_inicial = (914, 525) self.__position = (0, 0) self.position = (self.pos_inicial[0], self.pos_inicial[1]) self.agregar_constantes(tipo) self.image.barra.setMaximum(self.life) self.image.barra.setProperty("value", self.life) self.rubberband = QtWidgets.QRubberBand( QtWidgets.QRubberBand.Rectangle, self.image) self.collided = False self.atacando = False def collision(self, tupla): self.collided = True @property def position(self): return self.__position @position.setter def position(self, value): self.__position = value # El trigger emite su señal a la ventana cuando cambiamos la posición self._trigger.emit( MoveMyImageEvent(self.image, self.position[0], self.position[1], self)) self._trigger.emit( MoveMyImageEvent(self.image.barra, self.position[0], self.position[1], self)) def run(self): self.image.show() self.image.barra.show() self.image.raise_() self.image.barra.raise_() while not (self.is_dead): time.sleep(0.05) self.move() self.image.hide() self.image.barra.hide() self.image.deleteLater() self.image.barra.deleteLater() def move(self): brain.what_to_do(self, self.parent) new = brain.aim(self, self.parent) m = self.movement_speed teams = {"blue": (-1, 1), "purple": (1, -1)} if self.collided and not self.atacando: self.position = (self.position[0] + new[0] + teams[self.team][0], self.position[1] + new[1] + teams[self.team][1]) elif not self.atacando: self.position = (self.position[0] + new[0], self.position[1] + new[1]) self.collided = False def atacar(self, other): self.atacando = True while other.life >= 0 and self.life >= 0: other.disminuir_vida(self.attack_damage) self.atacando = False