コード例 #1
0
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
コード例 #2
0
class LoP(QtWidgets.QMainWindow):
    movimiento = pyqtSignal()

    def __init__(self, brain):

        super().__init__()

        self.brain = brain
        self.key = None
        self.teclas_activas = {87: False, 68: False, 83: False, 65: False}
        self.label = Label(self)
        self.label.setGeometry(QtCore.QRect(0, 0, 1300, 750))
        self.label.setPixmap(QtGui.QPixmap("IMGS/background.png"))
        self.label.setScaledContents(True)
        self.label.setObjectName("label")
        self.label.setMouseTracking(True)
        self.label.setDisabled(False)
        self.label.show()
        self.label.raise_()

        self.minions_timer = QtCore.QTimer()
        self.minions_timer.start(10000)
        self.minions_timer.timeout.connect(self.minion_spawner)
        self.mouse = None
        self.instanciar_personajes()
        engine = back_end.ShopEngine(self.champ)
        self.shop = Shop(engine)

    @staticmethod
    def actualizar_imagen(myImageEvent):
        # Recibo el objeto con la información necesaria para mover a bastián
        # Hagamos un print para corroborar su posición?
        label = myImageEvent.image
        label.move(myImageEvent.x, myImageEvent.y)

    @staticmethod
    def direccion_mouse(objeto, other):
        if other.mouse:
            return other.mouse
        else:
            return None

    @staticmethod
    def direccion_key(objeto, other):
        if other.key:
            return other.key
        else:
            return None

    @staticmethod
    def crear_juego():
        pass

    def mouseMoveEvent(self, event):
        super(LoP, self).mouseMoveEvent(event)
        if event.buttons() == Qt.NoButton:
            self.mouse = event.pos()

    def keyPressEvent(self, event):
        llaves = {87: "W", 68: "D", 83: "S", 65: "A"}
        super(LoP, self).keyPressEvent(event)
        if event.key() in llaves:
            self.key = llaves[event.key()]
        elif event.key() == QtCore.Qt.Key_O:
            self.shop.show()
        elif event.key() == QtCore.Qt.Key_P:
            self.pausar()

    def iniciar(self):
        self.champ.start()
        self.inhibidor_blue.start()
        self.inhibidor_purple.start()
        self.torre_blue.start()
        self.torre_purple.start()
        self.nexo_blue.start()
        self.nexo_purple.start()

    def minion_spawner(self):
        colores = ("purple", "blue")
        for color in colores:
            self.minion_3 = Minion(self, "Subditos_fuertes", color, self.brain)
            self.minion_2 = Minion(self, "Subditos_debiles", color, self.brain)
            self.minion_1 = Minion(self, "Subditos_debiles", color, self.brain)
            self.minion_4 = Minion(self, "Subditos_debiles", color, self.brain)
            self.minion_5 = Minion(self, "Subditos_debiles", color, self.brain)
            minions = {
                1: self.minion_1,
                2: self.minion_2,
                3: self.minion_3,
                4: self.minion_4,
                5: self.minion_5,
            }
            circulo = {
                1: (-1, 0),
                3: (-1, -1),
                2: (0, 1),
                4: (1, 1),
                5: (1, 0)
            }

            for i in minions:
                minions[i].position = (minions[i].position[0] +
                                       circulo[i][0] * 100,
                                       minions[i].position[1] +
                                       circulo[i][1] * 100)
                minions[i].start()

    def instanciar_personajes(self):
        lista_threads = []
        # Aca se instancian los objetos desde el archivo de constantes
        # Simplemente cambiar el nombre para probar los otros champions!,
        # Los nombres estan en constantes.json
        self.champ = Character(self, 0, 0, "Hechicera", "purple")
        self.inhibidor_blue = Edificio(self, "Inhibidor", "blue", self.brain)
        self.inhibidor_purple = Edificio(self, "Inhibidor", "purple",
                                         self.brain)
        self.torre_purple = Edificio(self, "Torre", "purple", self.brain)
        self.torre_blue = Edificio(self, "Torre", "blue", self.brain)
        self.nexo_blue = Edificio(self, "Nexo", "blue", self.brain)
        self.nexo_purple = Edificio(self, "Nexo", "purple", self.brain)
コード例 #3
0
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