def main():
    ancho = 800
    alto = 600
    init(ancho, alto, "titulo")

    p = Jugador(Vector(180 + 12, 50 + 70))
    r = Reloj(Vector(50, 450))
    fondo = Fondo(Vector(0, 0))
    camara = Camara(p)
    piedra = PlataformaPiedra(Vector(200, 50))
    liana = PlataformaLiana(Vector(400, 150))
    madera = PlataformaMadera(Vector(650, 250))
    liana2 = PlataformaLiana(Vector(500, 400))
    piedra2 = PlataformaPiedra(Vector(200, 500))
    muro = Muros(Vector(0, 0))

    elementos = [fondo, piedra, liana, madera, liana2, piedra2, muro, p, r]
    plataformas = [piedra, liana, madera, liana2, piedra2]
    run = True

    while run:
        pygame.event.pump()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:  # cerrar ventana
                run = False

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    pass
                if event.key == pygame.K_RIGHT:
                    p.pos += Vector(20, 0)
                if event.key == pygame.K_LEFT:
                    p.pos -= Vector(20, 0)
                if event.key == pygame.K_UP:
                    p.pos += Vector(0, 20)
                if event.key == pygame.K_DOWN:
                    p.pos -= Vector(0, 20)

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)  # limpiar buffers

        # dibujar figuras

        p.update(plataformas, camara)
        r.update(fps)
        for elem in elementos:
            elem.dibujar()

        pygame.display.flip()  # actualizar pantalla
        clock.tick(fps)

    pygame.quit()
Example #2
0
    def __init__(self):
        self.lib_dir = "./bibliotecas/"
        mylst = Biblioteca.ObjLstBiblioteca()
        load_alarmas()
        cargar_parametros()
        self.ultimo_minuto_calculado = -1;
        self.lst_biblioteca = mylst.get_lst_biblioteca()

        self.lbl_reproductor_info = Gtk.Label("")
        self.reproductor = Reproductor(self.lbl_reproductor_info)
        self.window = Gtk.Window.__init__(self, title="MP3tador,  v0.3")

        self.set_border_width(20)

        self.color_fuente = "black"
        self.reloj = Reloj()
        self.lblhora = Gtk.Label(label= "")
        self.lbldata = Gtk.Label(label= "")
        self.tabla()
        self._update_id = GObject.timeout_add(1000, self.update_hora_timeout, None)
Example #3
0
 def start_threads(self):
     self.pocmon = Pacman(self)
     self.pocmon.trigger.connect(self.correr)
     self.pocmon.setup(self.picman, self.mapa)
     self.pocmon.start()
     self.MrPatiwi = FantasmaRojo(self)
     self.MrPatiwi.setup(self.f1, self.mapa, self.pocmon, self.myScaledf1, self.puerta)
     self.Marquiwi = FantasmaNaranja(self)
     self.Marquiwi.setup(self.f3, self.mapa, self.pocmon, self.myScaledf3, self.puerta)
     self.Belenciwi = FantasmaNaranja(self)
     self.Belenciwi.setup(self.f4, self.mapa, self.pocmon, self.myScaledf4, self.puerta)
     self.Jaimiwi = FantasmaNaranja(self)
     self.Jaimiwi.setup(self.f2, self.mapa, self.pocmon, self.myScaledf2, self.puerta)
     for f in Fantasma.fantasmas:
         f.trigger.connect(self.correrFantasmas)
         f.trigg.connect(self.Azul)
         f.menosvida.connect(self.PacmanAtrapado)
         f.start()
     self.Reloj = Reloj()
     self.Reloj.trigger.connect(self.actualizarBarra) #ver si es realmente necesario
     self.Reloj.start()
Example #4
0
class Ui_Pocmon(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        self.setupUi(self)
        self.pausa = False

    def setupUi(self, Pocmon):
        self.Pausa = PauseMenu()
        self.SaveAs = SaveAs()
        self.Pausa.conectar(self)
        Pocmon.setObjectName(_fromUtf8("Pocmon"))
        Pocmon.resize(680, 770)
        self.horizontalLayout_2 = QtGui.QHBoxLayout(Pocmon)
        p = self.palette()
        p.setColor(self.backgroundRole(), QtCore.Qt.darkRed)
        self.setPalette(p)
        self.retranslateUi(Pocmon)
        QtCore.QMetaObject.connectSlotsByName(Pocmon)
        self.setgraphics()
        self.barra = QtGui.QLabel(self)
        self.font = QtGui.QFont()
        self.font.setFamily(_fromUtf8("Fixedsys"))
        self.font.setPointSize(14)
        self.font.setBold(True)
        self.font.setWeight(75)
        self.barra.setFont(self.font)
        self.barra.resize(680, 30)
        self.record = str(EncontrarRecord())
        self.barra.setText('  Puntaje: {0:4s} Record: {1:4s} Vidas:{2:2s}  Tiempo Restante: {3:4s}'.format('0', self.record, '3',
                                                                                             '04:00'))
        self.barra.setStyleSheet('QLabel {background-color: #F6F285; color: #3366FF;}')
        self.start_threads()
        self.cont = 0
        self.c = 0
        time.process_time()

    def retranslateUi(self, Pocmon):
        Pocmon.setWindowTitle(_translate("Pocmon", "Poc-Mon", None))

    def setgraphics(self):
        with open(os.getcwd() + '\Laberintos\maze1.txt', 'r') as archivo:
            self.map = archivo.readlines()
        self.mapa = []
        c = 0
        for i in range(len(self.map)):
            lis = []
            for j in range(len(self.map[0])):
                if self.map[i][j] != '0':
                    if j == len(self.map[0]) - 2 or j == 0:
                        if self.map[i][j] != '0':
                            lis.append('8')
                    else:
                        if self.map[i][j] == '5':
                            y = i
                            x = j
                            lis.append('5')
                        elif self.map[i][j] == '4':
                            y1 = i #Posiciones claves para que los fantasmas reingresen a la base
                            x1 = j
                            self.puerta = (x1,y1)
                            lis.append('1')
                        elif self.map[i][j] == '3':
                            y2 = i
                            x2 = j
                            lis.append('3')
                        elif self.map[i][j] == '6':
                            y3 = i
                            x3 = j
                            lis.append('6')
                        elif self.map[i][j] == '9':
                            y4 = i
                            x4 = j
                            lis.append('9')
                        else:
                            if c % 5 == 0:
                                r = random.random()
                                if r < 0.03:
                                    lis.append('7')
                                else:
                                    lis.append('2')
                            else:
                                lis.append('1')

                else:
                    lis.append('0')
                c += 1
            self.mapa.append(lis)
        self.picman = QtGui.QLabel(self)
        self.f1 = QtGui.QLabel(self)
        self.f2 = QtGui.QLabel(self)
        self.f3 = QtGui.QLabel(self)
        self.f4 = QtGui.QLabel(self)
        self.myPixmap = QtGui.QPixmap(os.getcwd() + "/Imágenes/pocmon.png")
        self.myPixmap2 = QtGui.QPixmap(os.getcwd() + "/Imágenes/pocmon2.png")
        self.myPixmapizq = QtGui.QPixmap(os.getcwd() + "/Imágenes/pocmonizq.png")
        self.myPixmap2izq = QtGui.QPixmap(os.getcwd() + "/Imágenes/pocmon2izq.png")
        self.pixf1 = QtGui.QPixmap(os.getcwd() + "/Imágenes/mrpatiwi.png")
        self.pixf2 = QtGui.QPixmap(os.getcwd() + "/Imágenes/jaimiwi.png")
        self.pixf3 = QtGui.QPixmap(os.getcwd() + "/Imágenes/marquiwi.png")
        self.pixf4 = QtGui.QPixmap(os.getcwd() + "/Imágenes/belenciwi.png")
        self.Blue = QtGui.QPixmap(os.getcwd() + "/Imágenes/Blue.png")
        self.Muerto = QtGui.QPixmap(os.getcwd() + "/Imágenes/Muerto.png")
        self.myScaledPixmap = self.myPixmap.scaled(self.picman.size(), QtCore.Qt.KeepAspectRatio)
        self.picman.setPixmap(self.myScaledPixmap)
        self.myScaledf1 = self.pixf1.scaled(self.f1.size(), QtCore.Qt.KeepAspectRatio)
        self.myScaledf2 = self.pixf2.scaled(self.f2.size(), QtCore.Qt.KeepAspectRatio)
        self.myScaledf3 = self.pixf3.scaled(self.f3.size(), QtCore.Qt.KeepAspectRatio)
        self.myScaledf4 = self.pixf4.scaled(self.f4.size(), QtCore.Qt.KeepAspectRatio)
        self.myScaledAzul = self.Blue.scaled(self.f1.size(), QtCore.Qt.KeepAspectRatio)
        self.myScaledMuerto = self.Muerto.scaled(self.f1.size(), QtCore.Qt.KeepAspectRatio)
        self.f1.setPixmap(self.myScaledf1)
        self.f2.setPixmap(self.myScaledf2)
        self.f3.setPixmap(self.myScaledf3)
        self.f4.setPixmap(self.myScaledf4)
        self.picman.move(x * 3, y * 3)
        self.f1.move(x1 * 3, y1 * 3)
        self.f2.move(x2 * 3, y2 * 3)
        self.f3.move(x3 * 3, y3 * 3)
        self.f4.move(x4 * 3, y4 * 3)

    def paintEvent(self, event):
        qp = QtGui.QPainter()
        qp.begin(self)
        self.drawlines(qp)
        qp.end()

    def drawlines(self, qp):
        pen = QtGui.QPen(QtCore.Qt.black, 35, QtCore.Qt.SolidLine)
        qp.setPen(pen)
        for i in range(len(self.mapa) - 1):
            for j in range(len(self.mapa[0]) - 1):
                if self.mapa[i][j] not in ('0', '4', '3', '6', '9'):
                    qp.drawPoint(j * 3, i * 3)
        pen = QtGui.QPen(QtCore.Qt.yellow, 2, QtCore.Qt.SolidLine)
        qp.setPen(pen)
        for i in range(len(self.mapa) - 1):
            for j in range(len(self.mapa[0]) - 1):
                if self.mapa[i][j] not in ('0', '4', '3', '6', '9'):
                    if self.mapa[i][j] == '7':
                        pen = QtGui.QPen(QtCore.Qt.red, 5, QtCore.Qt.SolidLine)
                        qp.setPen(pen)
                        qp.drawPoint(j * 3, i * 3)
                        pen = QtGui.QPen(QtCore.Qt.yellow, 2, QtCore.Qt.SolidLine)
                        qp.setPen(pen)
                    elif self.mapa[i][j] == '2':
                        qp.drawPoint(j * 3, i * 3)

    def start_threads(self):
        self.pocmon = Pacman(self)
        self.pocmon.trigger.connect(self.correr)
        self.pocmon.setup(self.picman, self.mapa)
        self.pocmon.start()
        self.MrPatiwi = FantasmaRojo(self)
        self.MrPatiwi.setup(self.f1, self.mapa, self.pocmon, self.myScaledf1, self.puerta)
        self.Marquiwi = FantasmaNaranja(self)
        self.Marquiwi.setup(self.f3, self.mapa, self.pocmon, self.myScaledf3, self.puerta)
        self.Belenciwi = FantasmaNaranja(self)
        self.Belenciwi.setup(self.f4, self.mapa, self.pocmon, self.myScaledf4, self.puerta)
        self.Jaimiwi = FantasmaNaranja(self)
        self.Jaimiwi.setup(self.f2, self.mapa, self.pocmon, self.myScaledf2, self.puerta)
        for f in Fantasma.fantasmas:
            f.trigger.connect(self.correrFantasmas)
            f.trigg.connect(self.Azul)
            f.menosvida.connect(self.PacmanAtrapado)
            f.start()
        self.Reloj = Reloj()
        self.Reloj.trigger.connect(self.actualizarBarra) #ver si es realmente necesario
        self.Reloj.start()

    def PacmanAtrapado(self):
        self.Reloj.pausa()
        self.pocmon.vidas -= 1
        if self.pocmon.vidas == 0:
            self.GameOver()
        else:
            self.pocmon.estado = True
            for i in Fantasma.fantasmas:
               i.reboot()
            for i in Personaje.personajes:
                i.terminate()
                i.reiniciar_posicion()
            time.sleep(2)
            for i in Personaje.personajes:
                i.start()
            self.Reloj.pausa()

    def GameOver(self, mensaje=None):
        for i in Personaje.personajes:
                i.terminate()
        self.SaveAs.setPuntaje(self.pocmon.puntaje, self.Reloj.reloj, mensaje)
        self.SaveAs.show()

    def keyPressEvent(self, event):
        key = event.key()
        if key != QtCore.Qt.Key_A:
            self.pocmon.direction(key)
        else:
            self.Pausar()

    def Pausar(self):
        if not self.pausa:
            for i in Personaje.personajes:
                i.pausar()
                self.pausa = True
            self.Reloj.pausa()
            self.hide()
            self.Pausa.show()
        else:
            for i in Personaje.personajes:
                i.pausar()
            self.pausa = False
            self.Reloj.pausa()
            self.Pausa.hide()
            self.show()

    def correr(self, pos):
        self.picman.move(pos[0], pos[1])
        if self.pocmon.running == 'Left':
            if self.c % 2 == 0:
                self.picman.setPixmap(self.myPixmapizq.scaled(self.picman.size(), QtCore.Qt.KeepAspectRatio))
            else:
                self.myScaledPixmap2 = self.myPixmap2izq.scaled(self.picman.size(), QtCore.Qt.KeepAspectRatio)
                self.picman.setPixmap(self.myScaledPixmap2)
        elif self.pocmon.running == 'Up' or self.pocmon.running == 'Down':
            if self.pocmon.running == 'Up':
                angle = -90
            else:
                angle = 90
            if self.c % 2 == 0:
                rotated_pixmap = self.myPixmap.transformed(QtGui.QMatrix().rotate(angle),
                                                           QtCore.Qt.SmoothTransformation)
                self.myScaledPixmap = rotated_pixmap.scaled(self.picman.size(), QtCore.Qt.KeepAspectRatio)
                self.picman.setPixmap(self.myScaledPixmap)
            else:
                rotated_pixmap2 = self.myPixmap2.transformed(QtGui.QMatrix().rotate(angle),
                                                             QtCore.Qt.SmoothTransformation)
                self.myScaledPixmap2 = rotated_pixmap2.scaled(self.picman.size(), QtCore.Qt.KeepAspectRatio)
                self.picman.setPixmap(self.myScaledPixmap2)
        else:
            if self.c % 2 == 0:
                self.myScaledPixmap = self.myPixmap.scaled(self.picman.size(), QtCore.Qt.KeepAspectRatio)
                self.picman.setPixmap(self.myScaledPixmap)
            else:
                self.myScaledPixmap2 = self.myPixmap2.scaled(self.picman.size(), QtCore.Qt.KeepAspectRatio)
                self.picman.setPixmap(self.myScaledPixmap2)
        self.c += 1

    def correrFantasmas(self, pos):
        im = pos[2].pic
        im.move(pos[0], pos[1])

    def ComprobarPartida(self):
        if Personaje.Monedas == 525:
            self.Reloj.pausa()
            self.GameOver('Ganaste')


    def Azul(self, fantasma):
        if not fantasma.muerto:
            if not fantasma.estado:
                fantasma.pic.setPixmap(self.myScaledAzul)
            else:
                fantasma.pic.setPixmap(fantasma.pix)
        else:
            fantasma.pic.setPixmap(self.myScaledMuerto)

    def actualizarBarra(self):
        self.ComprobarPartida()
        Puntaje = str(self.pocmon.puntaje)
        vidas = str(self.pocmon.vidas)
        self.barra.setText(
            '  Puntaje: {0:4s} Record: {1:4s} Vidas:{2:2s}  Tiempo Restante: {3:4s}'.format(Puntaje, self.record, vidas,
                                                                                             self.Reloj.reloj))

    def restart(self):
        self.hide()
        self.close()
        subprocess.call("python" + " UI.py", shell=True)

    def __getstate__(self):
        nueva = self.__dict__.copy()
        #nueva.__delitem__('PauseMenu')
        return nueva
Example #5
0
class Principal(Gtk.Window):
    def __init__(self):
        self.lib_dir = "./bibliotecas/"
        mylst = Biblioteca.ObjLstBiblioteca()
        load_alarmas()
        cargar_parametros()
        self.ultimo_minuto_calculado = -1;
        self.lst_biblioteca = mylst.get_lst_biblioteca()

        self.lbl_reproductor_info = Gtk.Label("")
        self.reproductor = Reproductor(self.lbl_reproductor_info)
        self.window = Gtk.Window.__init__(self, title="MP3tador,  v0.3")

        self.set_border_width(20)

        self.color_fuente = "black"
        self.reloj = Reloj()
        self.lblhora = Gtk.Label(label= "")
        self.lbldata = Gtk.Label(label= "")
        self.tabla()
        self._update_id = GObject.timeout_add(1000, self.update_hora_timeout, None)
        #SuenaAlarma(lista_alarmas[0], self)

    def update_hora_timeout(self, kaka):
        self.update_hora()
        if (self.ultimo_minuto_calculado != self.reloj.get_minutos()):
            self.ultimo_minuto_calculado = self.reloj.get_minutos()
            for i in lista_alarmas:
                if (i.get_activa() == True):
                    if (i.get_dias() == True):
                        if ((int(i.get_minutos()) == int(self.reloj.get_minutos())) and (int(i.get_horas()) == int(self.reloj.get_horas()))):
                            SuenaAlarma(i, self)
                    else:
                        if ((self.reloj.get_dia_semana() == 0) and (i.get_lunes() == True)):
                            if ((int(i.get_minutos()) == int(self.reloj.get_minutos())) and (int(i.get_horas()) == int(self.reloj.get_horas()))):
                                SuenaAlarma(i, self)

                        if ((self.reloj.get_dia_semana() == 1) and (i.get_martes() == True)):
                            if ((int(i.get_minutos()) == int(self.reloj.get_minutos())) and (int(i.get_horas()) == int(self.reloj.get_horas()))):
                                SuenaAlarma(i, self)

                        if ((self.reloj.get_dia_semana() == 2) and (i.get_miercoles() == True)):
                            if ((int(i.get_minutos()) == int(self.reloj.get_minutos())) and (int(i.get_horas()) == int(self.reloj.get_horas()))):
                                SuenaAlarma(i, self)

                        if ((self.reloj.get_dia_semana() == 3) and (i.get_jueves() == True)):
                            if ((int(i.get_minutos()) == int(self.reloj.get_minutos())) and (int(i.get_horas()) == int(self.reloj.get_horas()))):
                                SuenaAlarma(i, self)

                        if ((self.reloj.get_dia_semana() == 4) and (i.get_viernes() == True)):
                            if ((int(i.get_minutos()) == int(self.reloj.get_minutos())) and (int(i.get_horas()) == int(self.reloj.get_horas()))):
                                SuenaAlarma(i, self)

                        if ((self.reloj.get_dia_semana() == 5) and (i.get_sabado() == True)):
                            if ((int(i.get_minutos()) == int(self.reloj.get_minutos())) and (int(i.get_horas()) == int(self.reloj.get_horas()))):
                                SuenaAlarma(i, self)

                        if ((self.reloj.get_dia_semana() == 6) and (i.get_domingo() == True)):
                            if ((int(i.get_minutos()) == int(self.reloj.get_minutos())) and (int(i.get_horas()) == int(self.reloj.get_horas()))):
                                SuenaAlarma(i, self)



                        #Dias de la semana
        return True

    def update_hora(self):
        self.lblhora.set_markup(str("<span font='50' foreground='"+self.color_fuente+"'>"+self.reloj._get_time_formated())+"</span>")
        self.lbldata.set_markup(str("<span variant='smallcaps'>" +self.reloj._get_date_formated())+"</span>")


    def tabla(self):
        table = Gtk.Table(8, 5, True)
        self.add(table)
        btn_alarmas = Gtk.Button(label="Alarmas")
        btn_alarmas.connect("clicked", self.on_btn_alarmas_clicked)

        btn_opciones = Gtk.Button(label="Opciones")
        btn_opciones.connect("clicked", self.on_btn_opciones_clicked)

        btn_play = Gtk.Button()
        btn_play.connect("clicked", self.on_btn_play_clicked)
        pb_play = GdkPixbuf.Pixbuf.new_from_file("./Icons/play2.png")
        img_play = Gtk.Image()
        img_play.set_from_pixbuf(pb_play)
        btn_play.set_image(img_play)
        btn_play.set_always_show_image (True)

        btn_stop = Gtk.Button()
        btn_stop.connect("clicked", self.on_btn_stop_clicked)
        pb_stop = GdkPixbuf.Pixbuf.new_from_file("./Icons/stop2.png")
        img_stop = Gtk.Image()
        img_stop.set_from_pixbuf(pb_stop)
        btn_stop.set_image(img_stop)
        btn_stop.set_always_show_image (True)

        btn_pause = Gtk.Button()
        btn_pause.connect("clicked", self.on_btn_pause_clicked)
        pb_pause = GdkPixbuf.Pixbuf.new_from_file("./Icons/pause2.png")
        img_pause = Gtk.Image()
        img_pause.set_from_pixbuf(pb_pause)
        btn_pause.set_image(img_pause)
        btn_pause.set_always_show_image (True)

        btn_next = Gtk.Button()
        btn_next.connect("clicked", self.on_btn_next_clicked)
        pb_next = GdkPixbuf.Pixbuf.new_from_file("./Icons/Next2.png")
        img_next = Gtk.Image()
        img_next.set_from_pixbuf(pb_next)
        btn_next.set_image(img_next)
        btn_next.set_always_show_image (True)

        btn_biblioteca = Gtk.Button(label="Biblioteca")
        btn_biblioteca.connect("clicked", self.on_btn_biblioteca_clicked)


        self.lst_biblioteca.set_active(0)
        self.lst_biblioteca.connect("changed", self.on_lst_biblioteca_changed)
        self.on_lst_biblioteca_changed(self.lst_biblioteca)

        self.update_hora()
        table.attach(self.lbldata, 0, 8, 0, 1)
        table.attach(self.lblhora, 0, 8 ,1, 5)
        table.attach(btn_alarmas, 10, 15, 2, 3)
        table.attach(btn_biblioteca, 10, 15, 4, 5)
        table.attach(btn_opciones, 10, 15, 6, 7)
        table.attach(self.lst_biblioteca, 0,8, 5,6)
        table.attach(btn_play, 0, 2, 6, 9)
        table.attach(btn_pause, 2, 4, 6, 9)
        table.attach(btn_next, 4, 6, 6, 9)
        table.attach(btn_stop, 6, 8, 6, 9)
        table.attach(self.lbl_reproductor_info, 0, 15, 10, 12)

        return self.lblhora

    def on_btn_biblioteca_clicked(self, widget):

        self.biblioteca = Biblioteca.Biblioteca(self)
        self.biblioteca.show_all()
        # self.reproductor.set_biblioteca(self.musica)

    def on_btn_opciones_clicked(self, widget):
        self.menu_opciones = MenuOpciones()

    def on_lst_biblioteca_changed(self, widget):
        lib_file = str(self.lst_biblioteca.get_active_text()) + ".lib"
        if (lib_file != "None.lib"):
            self.reproductor.stop()
            self.reproductor.load_biblioteca(lib_file)

    def reload_biblioteca(self, widget, event=None):
        self.on_lst_biblioteca_changed(self)

    def on_btn_play_clicked(self, widget):
        self.reproductor.play()

    def on_btn_stop_clicked(self, widget):
        self.reproductor.stop()

    def on_btn_pause_clicked(self, widget):
        self.reproductor.pause()

    def on_btn_next_clicked(self, widget):
        self.reproductor.next_song()

    def on_btn_alarmas_clicked(self, widget):
        alarmas = Menu_alarma()
        alarmas.show_all()