From e374112d22a6c5c210c1074d1be01200e2d22d50 Mon Sep 17 00:00:00 2001 From: saraycubillos <62775794+saraycubillos@users.noreply.github.com> Date: Thu, 23 Jul 2020 20:21:35 -0500 Subject: [PATCH 1/7] Add files via upload --- DOCUMENTACION/Juego/mainwindow.cpp | 1878 +++++++++++++++------------- DOCUMENTACION/Juego/mainwindow.h | 49 +- 2 files changed, 1036 insertions(+), 891 deletions(-) diff --git a/DOCUMENTACION/Juego/mainwindow.cpp b/DOCUMENTACION/Juego/mainwindow.cpp index 4e1658c..98255ac 100644 --- a/DOCUMENTACION/Juego/mainwindow.cpp +++ b/DOCUMENTACION/Juego/mainwindow.cpp @@ -7,1186 +7,951 @@ MainWindow::MainWindow(QWidget *parent) { //intro->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/fantasy.mp3")); + niveles(opcion); start=new QPushButton("INICIAR JUEGO", this); -start->setGeometry(QRect( QPoint(310,160), //250x160 +start->setGeometry(QRect( QPoint(310,160), // Valores por defecto 250x160 QSize(200, 50) )); -//200x 50 +//Valores por defecto : 200x 50 connect(start, SIGNAL (clicked()),this, SLOT (botonInicio())); start->setStyleSheet("background-color: gray"); saveData=new QPushButton ("CONTINUAR PARTIDA ",this); -saveData->setGeometry(QRect( QPoint(310,300), //250x160 + + +saveData->setGeometry(QRect( QPoint(310,300), QSize(200, 50) )); connect(saveData, SIGNAL (clicked()),this, SLOT (guardarPartida())); saveData->setStyleSheet("background-color: gray"); bolaFuego=new Objeto(0,0,30, ":/IMAGENES/BOLADEFUEGO.png"); - timer=new QTimer(this); //crea el timer - timer->stop(); //para el timer - connect(timer,SIGNAL(timeout()),this,SLOT(lanzamiento())); - timer->start(10); + +/* +timer->stop(); +connect(timer,SIGNAL(timeout()),this,SLOT(actualizar())); +timer->start(dt);*/ + + + +/*LISTA.append(new Particula(0,0,0,0,50000,200)); +LISTA.append(new Particula(-5000,0,0,0,70,70)); +LISTA.append(new Particula(5000,0,0,0,70,70)); */ //Planetas agregados directamente +// LISTA.append(new Graficar(0,-5000,2,0,70,70)); +//LISTA.append(new Graficar(0,5000,-2,0,70,70)); + + + } + +//-------------------------------------------------KEYPRESSEVENT-------------------------------------------------- + void MainWindow::keyPressEvent(QKeyEvent *evento) { + qDebug()<pos()<x(); + +//-----------------------------------------EVENTO PERSONAJE 1 NIVEL 1------------------------------------------------- + if (opcion==1) { if(evento->key()==Qt::Key_A) { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + coaliciones('A', personaje1); + } - //---------GIRO DEL PERSONAJE------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(180); - personaje1->izquierda(); + else if(evento->key()==Qt::Key_D) + { + coaliciones('D', personaje1); - //---------COALISIONES------- - if(personaje1->collidesWithItem(bolaH)) + } + else if(evento->key()==Qt::Key_W) { - bolaH->izquierda(); - } - if(personaje1->collidesWithItem(enemigo1)) - { - enemigo1->izquierda(); - x = enemigo1->x(); - y = enemigo1->y(); - cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLADEFUEGO.png")); - scene->addItem(cuerpos.back()); + coaliciones('W', personaje1); - timer->start(30); - } - for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - //vidas-=1; - } } - //-------EVALUAR COALISIONES CON MUROS----- - for (int i=0;ikey()==Qt::Key_S) { - if (personaje1->collidesWithItem(muros.at(i))) - { - personaje1->derecha(); - } + coaliciones('S', personaje1); } - //-------EVALUAR COALISIONES CON PIEDRAS----- - - for (int i=0;icollidesWithItem(piedras.at(i))) - { - - personaje1->derecha(); - } - } - - //-------CAPTURAR LLAVES----- - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); - - - //llaves+=1; +// qDebug()<pos()<x(); - } +//-------------------------------------------------EVENTO PERSONAJE 2 NIVEL 1------------------------------------------------------------ +if(evento->key()==Qt::Key_I) +{ - //------------PUERTA-------------- - if (personaje1->collidesWithItem(puerta)) - { + coaliciones('I', personaje2); - personaje1->derecha(); - //remover escena - } +} +if(evento->key()==Qt::Key_J) +{ + coaliciones('J', personaje2); - } +} +if(evento->key()==Qt::Key_L) +{ - else if(evento->key()==Qt::Key_D) - { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + coaliciones('L', personaje2); - //---------GIRO DEL PERSONAJE------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(0); - personaje1->derecha(); +} +if(evento->key()==Qt::Key_K) - //---------COALISIONES------- - if(personaje1->collidesWithItem(bolaH)) +{ - { - bolaH->derecha(); - } - if(personaje1->collidesWithItem(enemigo1)) + coaliciones('K', personaje2); - { - x = enemigo1->x(); - y = enemigo1->y(); - enemigo1->derecha(); - //bolaFuego->setPosx(personaje1->pos()); - cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLADEFUEGO.png")); - scene->addItem(cuerpos.back()); +} - timer->start(30); - } +//------------------------------------------------CAMBIO DE NIVEL 1 A 2------------------------------------------------- - for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - //vidas-=1; - } - } - //-------EVALUAR COALISIONES CON MUROS----- - for (int i=0;icollidesWithItem(muros.at(i))) - { + if (((personaje1->x()==250 or personaje2->x()==250) and (personaje1->y()==390 or personaje2->y()==390 )) ) + { + opcion=2; + niveles(opcion); - personaje1->izquierda(); - } - } - //-------EVALUAR COALISIONES CON PIEDRAS----- + } - for (int i=0;icollidesWithItem(piedras.at(i))) - { +} - personaje1->derecha(); - } - } +//--------------------------------------------------EVENTO PERSONAJE 1 NIVEL 2------------------------------------------------- - //-------CAPTURAR LLAVES----- - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); +if (opcion==2) +{ + if(evento->key()==Qt::Key_A) + { + coaliciones('A', personaje1); + } + else if(evento->key()==Qt::Key_D) + { - //llaves+=1; + coaliciones('D', personaje1); - } + } + else if(evento->key()==Qt::Key_W) + { - //------------PUERTA-------------- - if (personaje1->collidesWithItem(puerta)) - { - personaje1->izquierda(); - //remover escena - } + coaliciones('W', personaje1); + } + else if(evento->key()==Qt::Key_S) + { + coaliciones('S', personaje1); } - else if(evento->key()==Qt::Key_W) - { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - //---------GIRO DE PERSONAJE------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(270); - personaje1->subir(); +// qDebug()<pos()<x(); +//-------------------------------------------EVENTO PERSONAJE 2 NIVEL 2------------------------------------------------------------ +if(evento->key()==Qt::Key_I) +{ - //---------COALISIONES------- - if(personaje1->collidesWithItem(bolaH)) - { - bolaH->subir(); - } - if(personaje1->collidesWithItem(enemigo1)) + coaliciones('I', personaje2); - { - enemigo1->subir(); +} +if(evento->key()==Qt::Key_J) +{ + coaliciones('J', personaje2); - x = enemigo1->x(); - y = enemigo1->y(); - cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLADEFUEGO.png")); - scene->addItem(cuerpos.back()); +} +if(evento->key()==Qt::Key_L) +{ - timer->start(30); - } - for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - //vidas-=1; - } - } - //-------EVALUAR COALISIONES CON MUROS----- - for (int i=0;icollidesWithItem(muros.at(i))) - { + coaliciones('L', personaje2); +} +if(evento->key()==Qt::Key_K) - personaje1->bajar(); - } - } - //-------EVALUAR COALISIONES CON PIEDRAS----- - for (int i=0;icollidesWithItem(piedras.at(i))) - { - personaje1->derecha(); - } - } - //-------CAPTURAR LLAVES----- - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); +//------------------------------------------------CAMBIO DE NIVEL 2 A 3------------------------------------------------- - //llaves+=1; + if ((personaje1->x()==250 and personaje1->y()==390) ) + { - } + niveles(3); - //------------PUERTA-------------- - if (personaje1->collidesWithItem(puerta)) - { - personaje1->bajar(); - //remover escena - } + } - } - else if(evento->key()==Qt::Key_S) - { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); +} +//-----------------------------------------------EVENTO PERSONAJE 1 NIVEL 3------------------------------------------------- - //---------GIRO DE PERSONAJE------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(90); - personaje1->bajar(); +if (opcion==3) +{ + if(evento->key()==Qt::Key_A) + { + coaliciones('A', personaje1); + } - //---------COALISIONES------- - if(personaje1->collidesWithItem(bolaH)) - { - bolaH->bajar(); - } - if(personaje1->collidesWithItem(enemigo1)) + else if(evento->key()==Qt::Key_D) + { + coaliciones('D', personaje1); - { + } + else if(evento->key()==Qt::Key_W) + { - x = enemigo1->x(); - y = enemigo1->y(); - enemigo1->bajar(); - cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLADEFUEGO.png")); - scene->addItem(cuerpos.back()); + coaliciones('W', personaje1); - timer->start(30); - } - for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - //vidas-=1; - } - } + } - //-------EVALUAR COALISIONES CON MUROS----- + else if(evento->key()==Qt::Key_S) + { - for (int i=0;icollidesWithItem(muros.at(i))) - { + coaliciones('S', personaje1); + } - personaje1->subir(); - } - } - //-------EVALUAR COALISIONES CON PIEDRAS----- - for (int i=0;icollidesWithItem(piedras.at(i))) - { - personaje1->derecha(); - } - } - //-------CAPTURAR LLAVES----- - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); +//---------------------------------------------EVENTO PERSONAJE 2 NIVEL 3------------------------------------------------------------ - //llaves+=1; +if(evento->key()==Qt::Key_I) +{ - } + coaliciones('I', personaje2); - //------------PUERTA-------------- - if (personaje1->collidesWithItem(puerta)) - { - personaje1->subir(); - //remover escena - } +} +if(evento->key()==Qt::Key_J) +{ + coaliciones('J', personaje2); +} +if(evento->key()==Qt::Key_L) +{ + coaliciones('L', personaje2); +} +if(evento->key()==Qt::Key_K) - } +{ -// qDebug()<pos()<x(); + coaliciones('K', personaje2); +} - if ((personaje1->x()==250 and personaje1->y()==390) ) - { - opcion=2; - niveles(opcion); +} - } } -if (opcion==2) + +void MainWindow::coaliciones(char letra , Personaje *personaje) { - if(evento->key()==Qt::Key_A) + if (personaje==personaje1) { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - //---------GIRO DEL PERSONAJE------- + if (letra=='A') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + //---------------------------GIRO DEL PERSONAJE1 (A)------------------------------ + personaje1->setTransformOriginPoint(0,0); personaje1->setRotation(180); personaje1->izquierda(); - //---------COALISIONES------- + //------------------------------COALISIONES1 (A) ---------------------------- + if(personaje1->collidesWithItem(bolaH)) { - bolaH->izquierda(); + bolaH->izquierda(); } if(personaje1->collidesWithItem(enemigo1)) { - enemigo1->izquierda(); - x = enemigo1->x(); - y = enemigo1->y(); - cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLADEFUEGO.png")); - scene->addItem(cuerpos.back()); + resorte('A', personaje1); + x = enemigo1->x(); + y = enemigo1->y(); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); - timer->start(30); + timer->start(30); } - for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - //vidas-=1; - } + if (personaje1->collidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + //vidas-=1; + } } - //-------EVALUAR COALISIONES CON MUROS----- + */ + //------------------------EVALUAR COALISIONES CON MUROS 1(A)------------------ + for (int i=0;icollidesWithItem(muros.at(i))) - { + if (personaje1->collidesWithItem(muros.at(i))) + { - personaje1->derecha(); - } + personaje1->derecha(); + } } - //-------EVALUAR COALISIONES CON PIEDRAS----- + //--------------------EVALUAR COALISIONES CON PIEDRAS 1(A)-------------------- for (int i=0;icollidesWithItem(piedras.at(i))) - { + { + if (personaje1->collidesWithItem(piedras.at(i))) + { - personaje1->derecha(); - } - } + personaje1->derecha(); + } + } - //-------CAPTURAR LLAVES----- + //--------------------------CAPTURAR LLAVES 1(A)------------------------------- if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); + { + //key->play(); + scene->removeItem(llave); - //llaves+=1; + //llaves+=1; - } + } - //------------PUERTA-------------- + //--------------------------PUERTA 1(A)------------------------------------------- if (personaje1->collidesWithItem(puerta)) - { - - personaje1->derecha(); - //remover escena - } - + { + personaje1->derecha(); + //remover escena } - else if(evento->key()==Qt::Key_D) - { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - - //---------GIRO DEL PERSONAJE------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(0); - personaje1->derecha(); - //---------COALISIONES------- - if(personaje1->collidesWithItem(bolaH)) - { - bolaH->derecha(); - } - if(personaje1->collidesWithItem(enemigo1)) - { - x = enemigo1->x(); - y = enemigo1->y(); - enemigo1->derecha(); - //bolaFuego->setPosx(personaje1->pos()); - cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLADEFUEGO.png")); - scene->addItem(cuerpos.back()); - timer->start(30); - } - for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - //vidas-=1; - } - } - //-------EVALUAR COALISIONES CON MUROS----- - for (int i=0;icollidesWithItem(muros.at(i))) - { + } + if (letra=='D') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + //--------------------------GIRO DEL PERSONAJE 1(D)--------------- + personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(0); + personaje1->derecha(); + //---------------------------COALISIONES 1(D)---------------------------- - personaje1->izquierda(); - } - } - //-------EVALUAR COALISIONES CON PIEDRAS----- + if(personaje1->collidesWithItem(bolaH)) - for (int i=0;icollidesWithItem(piedras.at(i))) - { + { + bolaH->derecha(); + } + if(personaje1->collidesWithItem(enemigo1)) - personaje1->derecha(); - } - } + { + x = enemigo1->x(); + y = enemigo1->y(); + resorte('D', personaje1); + //bolaFuego->setPosx(personaje1->pos()); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } - //-------CAPTURAR LLAVES----- - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); + /*for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + //vidas-=1; + } + }*/ + //----------------------EVALUAR COALISIONES CON MUROS 1(D)------------------ + for (int i=0;icollidesWithItem(muros.at(i))) + { - //llaves+=1; - } + personaje1->izquierda(); + } + } + //----------------------EVALUAR COALISIONES CON PIEDRAS 1(D)---------------------- - //------------PUERTA-------------- - if (personaje1->collidesWithItem(puerta)) - { - personaje1->izquierda(); - //remover escena - } + for (int i=0;icollidesWithItem(piedras.at(i))) + { + + personaje1->izquierda(); + } + } + + //----------------------------CAPTURAR LLAVES 1(D)---------------------------------- + if (personaje1->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + //llaves+=1; } - else if(evento->key()==Qt::Key_W) - { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + //--------------------------PUERTA 1(D)------------------------------ + if (personaje1->collidesWithItem(puerta)) + { + personaje1->izquierda(); + //remover escena + } + } + if (letra=='W') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - //---------GIRO DE PERSONAJE------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(270); - personaje1->subir(); + //-------------------------GIRO DE PERSONAJE 1(W)----------------------- + personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(270); + personaje1->subir(); - //---------COALISIONES------- - if(personaje1->collidesWithItem(bolaH)) - { - bolaH->subir(); - } - if(personaje1->collidesWithItem(enemigo1)) - { - enemigo1->subir(); + //----------------------------COALISIONES 1(W)-------------------------------- + if(personaje1->collidesWithItem(bolaH)) + { + bolaH->subir(); + } + if(personaje1->collidesWithItem(enemigo1)) - x = enemigo1->x(); - y = enemigo1->y(); - cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - scene->addItem(cuerpos.back()); + { + resorte('W', personaje1); - timer->start(30); - } - for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - //vidas-=1; - } - } - //-------EVALUAR COALISIONES CON MUROS----- - for (int i=0;icollidesWithItem(muros.at(i))) - { + x = enemigo1->x(); + y = enemigo1->y(); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); - personaje1->bajar(); - } - } - //-------EVALUAR COALISIONES CON PIEDRAS----- + timer->start(30); + } + /*for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + //vidas-=1; + } + }*/ + //----------------EVALUAR COALISIONES CON MUROS 1(W))----------------------- + for (int i=0;icollidesWithItem(muros.at(i))) + { - for (int i=0;icollidesWithItem(piedras.at(i))) - { - personaje1->derecha(); - } - } + personaje1->bajar(); + } + } + //-------------------EVALUAR COALISIONES CON PIEDRAS 1(W)--------------------- - //-------CAPTURAR LLAVES----- - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); + for (int i=0;icollidesWithItem(piedras.at(i))) + { - //llaves+=1; + personaje1->bajar(); + } + } - } + //-----------------------------CAPTURAR LLAVES 1(W)---------------------------- + if (personaje1->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); - //------------PUERTA-------------- - if (personaje1->collidesWithItem(puerta)) - { - personaje1->bajar(); - //remover escena - } + //llaves+=1; + } + //-----------------------------------PUERTA 1(W)------------------------------- + if (personaje1->collidesWithItem(puerta)) + { + personaje1->bajar(); + //remover escena } - else if(evento->key()==Qt::Key_S) - { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - //---------GIRO DE PERSONAJE------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(90); - personaje1->bajar(); + } + if (letra=='S') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - //---------COALISIONES------- - if(personaje1->collidesWithItem(bolaH)) - { - bolaH->bajar(); - } - if(personaje1->collidesWithItem(enemigo1)) + //---------------------------GIRO DE PERSONAJE 1(S)--------------------------- + personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(90); + personaje1->bajar(); - { + //------------------------------COALISIONES 1(S)----------------------------- + if(personaje1->collidesWithItem(bolaH)) + { + bolaH->bajar(); + } + if(personaje1->collidesWithItem(enemigo1)) - x = enemigo1->x(); - y = enemigo1->y(); - enemigo1->bajar(); - cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLADEFUEGO.png")); - scene->addItem(cuerpos.back()); - timer->start(30); - } - for (int i=0;ix(); + y = enemigo1->y(); + resorte('S', personaje1); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } + /*for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + //vidas-=1; + } + } + */ + //-----------------------EVALUAR COALISIONES CON MUROS 1(S)---------------- + + for (int i=0;icollidesWithItem(muros.at(i))) { - if (personaje1->collidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - //vidas-=1; - } - } - //-------EVALUAR COALISIONES CON MUROS----- + personaje1->subir(); + } + } + //----------------------EVALUAR COALISIONES CON PIEDRAS 1(S)--------------- - for (int i=0;icollidesWithItem(muros.at(i))) + if (personaje1->collidesWithItem(piedras.at(i))) { personaje1->subir(); } } - //-------EVALUAR COALISIONES CON PIEDRAS----- - for (int i=0;icollidesWithItem(piedras.at(i))) - { + //--------------------------CAPTURAR LLAVES 1(S)------------------------- + if (personaje1->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); - personaje1->derecha(); - } - } + //llaves+=1; - //-------CAPTURAR LLAVES----- - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); + } - //llaves+=1; + //-------------------------PUERTA 1(S)----------------------------------- + if (personaje1->collidesWithItem(puerta)) + { + personaje1->subir(); + //remover escena } - //------------PUERTA-------------- - if (personaje1->collidesWithItem(puerta)) - { - personaje1->subir(); - //remover escena - } + } - } + } + if (personaje==personaje2) + { - if ((personaje1->x()==250 and personaje1->y()==390) ) - { + if (letra=='I') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + //-------------------GIRO DE PERSONAJE 2(I)------------------- + personaje2->setTransformOriginPoint(0,0); + personaje2->setRotation(270); + personaje2->subir(); - niveles(3); - } + //--------------------------COALISIONES 2(I)------------------------ -} -if (opcion==3) -{ + if(personaje2->collidesWithItem(bolaH)) + { + bolaH->subir(); + } + if(personaje2->collidesWithItem(enemigo1)) - if(evento->key()==Qt::Key_A) { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + resorte('I', personaje2); - //---------GIRO DEL PERSONAJE------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(180); - personaje1->izquierda(); + x = enemigo1->x(); + y = enemigo1->y(); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); - //---------COALISIONES------- - if(personaje1->collidesWithItem(bolaH)) - { - bolaH->izquierda(); + timer->start(30); } - if(personaje1->collidesWithItem(enemigo1)) - + /*for (int i=0;iizquierda(); - x = enemigo1->x(); - y = enemigo1->y(); - cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLADEFUEGO.png")); - scene->addItem(cuerpos.back()); - - timer->start(30); - } - for (int i=0;icollidesWithItem(cuerpos.at(i))) { - if (personaje1->collidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - //vidas-=1; - } + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + //vidas-=1; } - //-------EVALUAR COALISIONES CON MUROS----- + }*/ + //-----------------------------EVALUAR COALISIONES CON MUROS 2(I)------------------ + for (int i=0;icollidesWithItem(muros.at(i))) - { - - personaje1->izquierda(); - } - } + if (personaje2->collidesWithItem(muros.at(i))) + { - //-------EVALUAR COALISIONES CON PIEDRAS----- + personaje2->bajar(); + } + } + //-------------------------------EVALUAR COALISIONES CON PIEDRAS 2(I)-------------- for (int i=0;icollidesWithItem(piedras.at(i))) - { - - personaje1->derecha(); - } - } + { + if (personaje2->collidesWithItem(piedras.at(i))) + { - //-------CAPTURAR LLAVES----- - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); + personaje2->bajar(); + } + } + //------------------------------------CAPTURAR LLAVES 2(I)-------------------- - //llaves+=1; + if (personaje2->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); - } + //llaves+=1; - //------------PUERTA-------------- - if (personaje1->collidesWithItem(puerta)) - { + } - personaje1->derecha(); - //remover escena - } + //------------------------------------PUERTA 2(I)---------------------------------- + if (personaje2->collidesWithItem(puerta)) + { + personaje2->bajar(); + //remover escena + } } - else if(evento->key()==Qt::Key_D) + if (letra=='J') { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); //---------GIRO DEL PERSONAJE------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(0); - personaje1->derecha(); + personaje2->setTransformOriginPoint(0,0); + personaje2->setRotation(180); + personaje2->izquierda(); + - //---------COALISIONES------- - if(personaje1->collidesWithItem(bolaH)) + //------------------------COALISIONES 2(J)---------------------------------- + if(personaje2->collidesWithItem(bolaH)) { - bolaH->derecha(); + bolaH->izquierda(); } - if(personaje1->collidesWithItem(enemigo1)) + if(personaje2->collidesWithItem(enemigo1)) { - x = enemigo1->x(); - y = enemigo1->y(); - enemigo1->derecha(); - //bolaFuego->setPosx(personaje1->pos()); - cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLADEFUEGO.png")); - scene->addItem(cuerpos.back()); + resorte('J', personaje2); + x = enemigo1->x(); + y = enemigo1->y(); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); - timer->start(30); + timer->start(30); } - - for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - //vidas-=1; - } + if (personaje2->collidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + //vidas-=1; } - //-------EVALUAR COALISIONES CON MUROS----- + }*/ + //-----------------------EVALUAR COALISIONES CON MUROS 2(J)--------------------- for (int i=0;icollidesWithItem(muros.at(i))) - { + if (personaje2->collidesWithItem(muros.at(i))) + { + personaje2->derecha(); + } + } - personaje1->izquierda(); - } - } - //-------EVALUAR COALISIONES CON PIEDRAS----- + //-------------------------EVALUAR COALISIONES CON PIEDRAS 2(J)-------------- for (int i=0;icollidesWithItem(piedras.at(i))) - { - - personaje1->derecha(); - } - } + { + if (personaje2->collidesWithItem(piedras.at(i))) + { - //-------CAPTURAR LLAVES----- - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); + personaje2->derecha(); + } + } + //----------------------------CAPTURAR LLAVES 2(J)----------------------- - //llaves+=1; + if (personaje2->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); - } - //------------PUERTA-------------- - if (personaje1->collidesWithItem(puerta)) - { - personaje1->izquierda(); - //remover escena - } + //llaves+=1; + } + //----------------------------------PUERTA 2(J)------------------------------- - } - else if(evento->key()==Qt::Key_W) + if (personaje2->collidesWithItem(puerta)) { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - - //---------GIRO DE PERSONAJE------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(270); - personaje1->subir(); - - - //---------COALISIONES------- - if(personaje1->collidesWithItem(bolaH)) - { - bolaH->subir(); + personaje2->derecha(); + //remover escena } - if(personaje1->collidesWithItem(enemigo1)) - { - enemigo1->subir(); - x = enemigo1->x(); - y = enemigo1->y(); - cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLADEFUEGO.png")); - scene->addItem(cuerpos.back()); - timer->start(30); - } - for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - //vidas-=1; - } - } - //-------EVALUAR COALISIONES CON MUROS----- - for (int i=0;icollidesWithItem(muros.at(i))) - { - personaje1->derecha(); - } - } - //-------EVALUAR COALISIONES CON PIEDRAS----- - for (int i=0;icollidesWithItem(piedras.at(i))) - { - personaje1->derecha(); - } - } + } - //-------CAPTURAR LLAVES----- - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); - //llaves+=1; + if (letra=='L') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - } + //---------GIRO DEL PERSONAJE------- + personaje2->setTransformOriginPoint(0,0); + personaje2->setRotation(0); + personaje2->derecha(); - //------------PUERTA-------------- - if (personaje1->collidesWithItem(puerta)) - { - personaje1->bajar(); - //remover escena - } + //-------------------------------COALISIONES 2(L) -------------------------------- + if(personaje2->collidesWithItem(bolaH)) + { + bolaH->derecha(); + } + if(personaje2->collidesWithItem(enemigo1)) + { + x = enemigo1->x(); + y = enemigo1->y(); + resorte('L', personaje2); + //bolaFuego->setPosx(personaje1->pos()); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); } - else if(evento->key()==Qt::Key_S) - { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + /* + for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + //vidas-=1; + } + }*/ + //------------------------EVALUAR COALISIONES CON MUROS 2(L)-------------------------- + for (int i=0;icollidesWithItem(muros.at(i))) + { - //---------GIRO DE PERSONAJE------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(90); - personaje1->bajar(); + personaje2->izquierda(); + } + } + //---------------------EVALUAR COALISIONES CON PIEDRAS 2(L)---------------------------- - //---------COALISIONES------- - if(personaje1->collidesWithItem(bolaH)) - { - bolaH->bajar(); - } - if(personaje1->collidesWithItem(enemigo1)) + for (int i=0;icollidesWithItem(piedras.at(i))) + { + personaje2->izquierda(); + } + } - { + //------------------------------CAPTURAR LLAVES 2(L)-------------------------------- - x = enemigo1->x(); - y = enemigo1->y(); - enemigo1->bajar(); - cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLADEFUEGO.png")); - scene->addItem(cuerpos.back()); + if (personaje2->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); - timer->start(30); - } - for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - //vidas-=1; - } - } - - //-------EVALUAR COALISIONES CON MUROS----- - - for (int i=0;icollidesWithItem(muros.at(i))) - { - - personaje1->subir(); - } - } - //-------EVALUAR COALISIONES CON PIEDRAS----- - - for (int i=0;icollidesWithItem(piedras.at(i))) - { - - personaje1->derecha(); - } - } - - //-------CAPTURAR LLAVES----- - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); - - //llaves+=1; - - } - - //------------PUERTA-------------- - if (personaje1->collidesWithItem(puerta)) - { - personaje1->subir(); - //remover escena - } - - - - - - } - -// qDebug()<pos()<x(); - - - if ((personaje1->x()==250 and personaje1->y()==390) ) - { - - - - //niveles(3); - - } - -} -} - - - - -MainWindow::~MainWindow() -{ - delete ui; -} + //llaves+=1; + } -void MainWindow::mover() -{ - for (QList :: iterator it=cuerpos.begin(); it!=cuerpos.end(); it++) + //-------------------------------------PUERTA 2(L)----------------------------- + if (personaje2->collidesWithItem(puerta)) { - (*it)->CalcularVelocidad(); - (*it)->ActualizarPosicion(); - - + personaje2->izquierda(); + //remover escena } - for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - //vidas-=1; - } } -} - -void MainWindow::botonInicio() -{ - opcion=1; - niveles(opcion); -} + if (letra=='K') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); -void MainWindow::guardarPartida() -{ - QFile archivo("PLANETAS.txt"); - if(archivo.open(QIODevice::Append | QIODevice::Text)){ - QTextStream datosArchivo(&archivo); + //---------------------------------GIRO DE PERSONAJE 2(K)---------------------- + personaje2->setTransformOriginPoint(0,0); + personaje2->setRotation(90); + personaje2->bajar(); - //datosArchivo << text<< endl; - } - archivo.close(); -} + //----------------------------------COALISIONES 2(K)-------------------------------- -void MainWindow:: lanzamiento () -{ /*int xinicial,xfinal,yinicial,yfinal; - xinicial=enemigo1->getPosx(); - xfinal=personaje1->getPosx(); - yinicial=enemigo1->getPosy(); - yfinal=personaje1->getPosy(); - while ((xinicial!=xfinal) or (yinicial!=yfinal)) - { + if(personaje2->collidesWithItem(bolaH)) + { + bolaH->bajar(); + } + if(personaje2->collidesWithItem(enemigo1)) - if (xinicialx(); + y = enemigo1->y(); + resorte('K', personaje2); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); - } + timer->start(30); + } + /*for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + //vidas-=1; + } + } + */ + //--------------------------EVALUAR COALISIONES CON MUROS 2(K)-------------------------- - if (yinicial>yfinal) - { - yinicial--; + for (int i=0;icollidesWithItem(muros.at(i))) + { - } + personaje2->subir(); + } + } + //-----------------------------EVALUAR COALISIONES CON PIEDRAS 2(K)---------------------- + for (int i=0;icollidesWithItem(piedras.at(i))) + { - path++; - } - //cout<<" PATH: "<<"( "<subir(); + } + } - else - if(xinicial>xfinal) + //-----------------------------CAPTURAR LLAVES 2(K)------------------------------------ + if (personaje2->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); - { + //llaves+=1; - xinicial--; - if(yinicialyfinal) - { - yinicial--; + //------------------------------PUERTA 2(K)------------------------------------------ - } + if (personaje2->collidesWithItem(puerta)) + { + personaje2->subir(); + //remover escena + } - path++; - } - if(path%10==0) - {if (i==1) - { - bolaFuego->setPos(xinicial,yinicial); - scene->addItem(bolaFuego); - } - if(i==100) - { - bolaFuego->setPos(xinicial,yinicial); - scene->addItem(bolaFuego); - i=0; - } - i++; - } } + } - - -*/ } -void MainWindow::lanzarfuego() -{ -/*if (opcion==1){ - x = enemigo1->x(); - y = enemigo1->y(); - cuerpos.push_back(new Particula (0,x, y,100,30,":/IMAGENES/BOLADEFUEGO.png")); - scene->addItem(cuerpos.back()); +//------------------------------------------------------NIVELES-------------------------------------------------- - timer->start(30); -}*/ +void MainWindow::botonInicio() +{ + opcion=1; + niveles(opcion); } - void MainWindow:: niveles(int opcion) { if (opcion==0) @@ -1196,11 +961,20 @@ void MainWindow:: niveles(int opcion) scene = new QGraphicsScene; ui->graphicsView->setScene(scene); + /*QMovie *movie= new QMovie (":/IMAGENES/MENU.gif"); + label->setMovie(movie); + movie->start(); + */ + /* QMovie *movie= new QMovie (":/IMAGENES/MENU.gif"); + label = new QLabel(this); + label->setMovie(movie); + movie->start();*/ + scene->setBackgroundBrush(QPixmap(":/IMAGENES/MAINMENU.png")); scene->setSceneRect(0,0,790,550); intro=new QMediaPlayer (); - intro->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/action.mp3")); + intro->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/fantasy.mp3")); //intro->play(); @@ -1222,11 +996,14 @@ void MainWindow:: niveles(int opcion) connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); cronometro->start(1000); - QTimer *cronometro2 = new QTimer(this); - connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); - cronometro2->start(1000); - + /* QTimer *cronometro2 = new QTimer(this); + connect(cronometro2, SIGNAL(timeout()),this,SLOT(magnetismo())); + cronometro2->start(1000);*/ + /* parabolico= new QTimer; + parabolico->stop(); + connect(parabolico,SIGNAL(timeout()),this,SLOT(Mover())); + parabolico->start(40);*/ //CREANDO LA ESCENA ui->setupUi(this); scene = new QGraphicsScene; @@ -1236,11 +1013,36 @@ void MainWindow:: niveles(int opcion) - personaje1=new Personaje(495,410,30,2, ":/IMAGENES/PERSONAJE1.png"); - scene->addItem(personaje1); + //x,y ,r,friccion,a,v,ang,path + personaje1=new Personaje(495,410,30,1,10, ":/IMAGENES/PERSONAJE1.png"); + scene->addItem(personaje1); + + personaje2=new Personaje(0,0,45,1,10, ":/IMAGENES/PERSONAJE2.png"); + scene->addItem(personaje2); + + enemigo1= new Personaje (-105,310,60,1,5,":/IMAGENES/ENEMIGO.png"); //antes -105, 310 + scene->addItem(enemigo1); + + timerEnem= new QTimer; + timerEnem->stop(); + connect(timerEnem, SIGNAL(timeout()), this , SLOT (moverEnemigo())); + timerEnem->start(40); + + rigidez=20; + + //particula1=new Particula( -105,310,0,0,50000,200, ":/IMAGENES/BOLADEMETAL.png "); + //particula2=new Particula(-5000,0,0,0,70,70 ,":/IMAGENES/BOLA DE FUEGO.png "); + + + + + + /* disparo=new QTimer; + disparo->stop(); + connect(disparo, SIGNAL(timeout()), this , SLOT (lanzamiento)); + disparo->start(1000);*/ + - enemigo1= new Personaje (0,0,60,2,":/IMAGENES/ENEMIGO.png"); - scene->addItem(enemigo1); @@ -1270,16 +1072,22 @@ void MainWindow:: niveles(int opcion) QTimer *cronometro = new QTimer(this); connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); cronometro->start(1000); - + /* parabolico= new QTimer; + parabolico->stop(); + connect(parabolico,SIGNAL(timeout()),this,SLOT(Mover())); + parabolico->start(40); QTimer *cronometro2 = new QTimer(this); connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); - cronometro2->start(1000); - timer->start(); - personaje1=new Personaje(495,410,30,1, ":/IMAGENES/PERSONAJE1.png"); + cronometro2->start(1000);*/ + timer->start(); //x,y ,r,friccion,a,v,ang,path + personaje1=new Personaje(495,410,30,1.5,0, ":/IMAGENES/PERSONAJE1.png"); scene->addItem(personaje1); - enemigo1= new Personaje (-135,415,60,1,":/IMAGENES/ENEMIGO.png"); - scene->addItem(enemigo1); + enemigo1= new Personaje (-135,415,60,1.5,0, ":/IMAGENES/ENEMIGO.png"); + scene->addItem(enemigo1); + + + rigidez=40; @@ -1307,21 +1115,25 @@ void MainWindow:: niveles(int opcion) QTimer *cronometro = new QTimer(this); connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); cronometro->start(1000); - + /* parabolico= new QTimer; + parabolico->stop(); + connect(parabolico,SIGNAL(timeout()),this,SLOT(Mover())); + parabolico->start(40); QTimer *cronometro2 = new QTimer(this); connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); - cronometro2->start(1000); - timer->start(); - personaje1=new Personaje(495,410,30,0.5, ":/IMAGENES/PERSONAJE1.png"); + cronometro2->start(1000);*/ + timer->start(); //x,y ,r,friccion,a,v,ang,path + personaje1=new Personaje(495,410,30,1.2, 1, ":/IMAGENES/PERSONAJE1.png"); scene->addItem(personaje1); - enemigo1= new Personaje (395,210,60,0.5,":/IMAGENES/SERPIENTE1 (1).png"); + enemigo1= new Personaje (395,210,60,1.5,1,":/IMAGENES/SERPIENTE1(1).png"); scene->addItem(enemigo1); - totem= new Personaje (0,0,60 ,0.5, ":/IMAGENES/TOTEM ARENA.png"); + totem= new Personaje (0,0,60 ,1,1.5, ":/IMAGENES/TOTEMARENA.png"); scene->addItem(totem); timer->start(); + rigidez=80; items(); @@ -1329,39 +1141,6 @@ void MainWindow:: niveles(int opcion) } -void MainWindow::clean() -{ - scene->removeItem(enemigo1); - delete (enemigo1); - scene->removeItem(personaje1); - delete (personaje1); - - - for (int i=0;iremoveItem(cuerpos.at(i)); - delete (cuerpos.at (i)); - cuerpos.removeOne(cuerpos.at(i)); - - - - } - for (int i=0;iremoveItem(piedras.at(i)); - delete (piedras.at (i)); - piedras.removeOne(piedras.at(i)); - - } - - - - scene->removeItem(puerta); - delete (puerta); -} - - void MainWindow::items() { @@ -1411,5 +1190,328 @@ void MainWindow::items() } +void MainWindow::clean() +{ + scene->removeItem(enemigo1); + delete (enemigo1); + scene->removeItem(personaje1); + delete (personaje1); + + + /*for (int i=0;iremoveItem(cuerpos.at(i)); + delete (cuerpos.at (i)); + cuerpos.removeOne(cuerpos.at(i)); + + }*/ + for (int i=0;iremoveItem(piedras.at(i)); + delete (piedras.at (i)); + piedras.removeOne(piedras.at(i)); + + } + + + + scene->removeItem(puerta); + delete (puerta); +} + +void MainWindow::guardarPartida() +{ + QFile archivo("PLANETAS.txt"); + if(archivo.open(QIODevice::Append | QIODevice::Text)){ + QTextStream datosArchivo(&archivo); + + + //datosArchivo << text<< endl; + + } + archivo.close(); +} + + +//--------------------------------------------------FISICAS-------------------------------------------------- + + +void MainWindow::CoeficienteRestitucion() +{ + +} + +void MainWindow::aceleracion(int) +{ + +} +void MainWindow:: lanzamiento () +{ + + /* int xinicial=0; + int xfinal=personaje1->x(); + int yinicial=0; + int yfinal=personaje1->y(); + + while ((xinicial!=xfinal) or (yinicial!=yfinal)) + { + + if (xinicialyfinal) + { + yinicial--; + + } + + path++; + } + //cout<<" PATH: "<<"( "<xfinal) + + { + + xinicial--; + if(yinicialyfinal) + { + yinicial--; + + } + + + path++; + } + if(path%10==0) + {if (i==1) + { + bolaFuego->setPos(xinicial,yinicial); + scene->addItem(bolaFuego); + timer->start(30); + + } + + if(i==100) + { + bolaFuego->setPos(xinicial,yinicial); + scene->addItem(bolaFuego); + i=0; + timer->start(30); + } + + i++; + +} + } +*/ + + +} + + +void MainWindow::lanzarfuego() +{if (opcion==1){ + x = enemigo1->x(); + y = enemigo1->y(); + cuerpos.push_back(new Particula (0,x, y,100,30,":/IMAGENES/BOLADEFUEGO.png")); + scene->addItem(cuerpos.back()); + timer->start(30); +} + +} +void MainWindow::mover() +{ + for (QList :: iterator it=cuerpos.begin(); it!=cuerpos.end(); it++) + { + (*it)->CalcularVelocidad(); + (*it)->ActualizarPosicion(); + + + } + for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + //vidas-=1; + } + + } + for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + //vidas-=1; + } + + } +} + +void MainWindow::resorte(char letra , Personaje *personaje) +{ + if (personaje==personaje1) + { + + if (letra=='A') + {personaje1-> setPos(personaje1->x()+5*rigidez,personaje1->y()); + } + if (letra=='D') + {personaje1-> setPos(personaje1->x()-5*rigidez,personaje1->y()); + } + if (letra=='W') + {personaje1->setPos(personaje1->x(),personaje1->y()+5*rigidez); + } + if(letra=='S') + {personaje1->setPos(personaje1->x(),personaje1->y()-5*rigidez); + } + } + + if(personaje==personaje2) + {if(letra=='J') + {personaje2-> setPos(personaje2->x()+5*rigidez,personaje2->y()); + } + if(letra=='L') + {personaje2-> setPos(personaje2->x()-5*rigidez,personaje2->y()); + } + if(letra=='I') + {personaje2->setPos(personaje2->x(),personaje2->y()+5*rigidez); + } + if(letra=='K') + {personaje2->setPos(personaje2->x(),personaje2->y()-5*rigidez); + } + } +} + +void MainWindow::magnetismo() +{ + /*if (opcion==1) + {float f, dx, dy,r; + dx=enemigo1->x()-personaje1->x(); + dy=enemigo1->x()-personaje1->x(); + r=pow(dx,2)+pow(dy,2); + f=(M*M)/(K*pow(r,2)); + x = enemigo1->x()*f; + y = enemigo1->y()*f; + bolaFuego->setPos(x,y); + scene->addItem(bolaFuego); + timer->start(30); + }*/ +} + +void MainWindow::Mover() +{/* + for(QList::iterator it=cuerpos.begin(); it!=cuerpos.end();it++) + { + (*it)->CalcularVelicidad(); + (*it)->ActualizarPosicion(); + } + double ang,x,y,v,a; + ang= enemigo1->angulo; + x= enemigo1->posx; + y= enemigo1->posy; + v= enemigo1->velocidad; + a= (ang/180)*3.1416; + cuerpos.push_back(new particula(rad, x, y, v)); + scene->addItem(cuerpos.back()); + //cuerpo= new particula(rad, x, y, v); + //Scene->addItem(cuerpo); + timer->start(30);*/ + +} + +void MainWindow::moverEnemigo( ) +{ +/* + if(ban==false) + {enemigo1->setX(enemigo1->x()+2); + if(enemigo1->x()<100) + {enemigo1->setX(enemigo1->x()+2*enemigo1->aceleracion+2);} + else if (enemigo1->x()<300) + {enemigo1->setX(enemigo1->x()+2*enemigo1->aceleracion);} + else if (enemigo1->x()<500) + {enemigo1->setX(enemigo1->x()+2*enemigo1->aceleracion+1);} + else if(enemigo1->x()>514) + {ban=true; + } + } + if(ban==true) + {enemigo1->setX(enemigo1->x()-2); + if(enemigo1->x()<100) + {enemigo1->setX(enemigo1->x()-2*enemigo1->aceleracion+2);} + else if (enemigo1->x()<300) + {enemigo1->setX(enemigo1->x()-2*enemigo1->aceleracion);} + else if (enemigo1->x()<500) + {enemigo1->setX(enemigo1->x()-2*enemigo1->aceleracion+1);} + if(enemigo1->x()<-116) + {ban=false; + } + } + +*/ +} + + + +//-------------------------------------------------DESTRUCTOR--------------------------------------------------------------- + + +MainWindow::~MainWindow() +{ + delete ui; + +} + + + +void MainWindow::actualizar() +{ + + + /*for (int i=0; i Acacelx(*(particula2)); + + // LISTA.at(i)-> Acacely(*(LISTA.at(j) )); + } + } + } + for(int i=0;iActualizar(); + particula1->Actualizar(particula1); + particula1->Actualizar(particula2); + + + }*/ + //actualiza cada dato + + + +//actualiza cada dato +} + diff --git a/DOCUMENTACION/Juego/mainwindow.h b/DOCUMENTACION/Juego/mainwindow.h index dde3d63..e289712 100644 --- a/DOCUMENTACION/Juego/mainwindow.h +++ b/DOCUMENTACION/Juego/mainwindow.h @@ -17,6 +17,9 @@ #include #include #include +#include + +#define K 0.00000001 QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; @@ -34,15 +37,26 @@ class MainWindow : public QMainWindow //QList muros; QList muros; QList piedras; + QList cuerpos; private slots: //SLOTS DE LA PARTÍCULA + + + /*double masa; + double posx; + double posy; + double radio; + double vx; + double vy;*/ + void mover(); + void actualizar(); - void lanzamiento (int xi, int xf, int yi, int yf); + void lanzamiento (); void lanzarfuego(); @@ -50,6 +64,18 @@ private slots: void botonInicio(); + void moverEnemigo(); + + void CoeficienteRestitucion(); + + void coaliciones (char , Personaje *personaje ); + + void magnetismo(); + + void Mover(); + + void resorte(char letter,Personaje *personaje); + private: Ui::MainWindow *ui; @@ -61,27 +87,40 @@ private slots: //PARTÍCULA + QTimer *timerEnem; QTimer *timer; - Particula *cuerpo; + QTimer *Timer; + QTimer *disparo; + QTimer *parabolico; + QLabel *label; + /*Particula *cuerpo; QListcuerpos; + QListLISTA;*/ //OBJETOS //Personaje *personaje1; Personaje *enemigo1; Personaje *totem; Personaje *personaje1; + Personaje *personaje2; Personaje *lanzador; Sprite *dragon; Objeto *puerta; Objeto *bolaH; - Objeto *bolaFuego; Objeto *llave; + QObject *personaje; + //particula *cuerpo; double x; double y; int opcion=0; int nivel=0; + int i=0; + int rigidez=0; + //____ prueba + /*Particula *particula1; + Particula *particula2;*/ // Sprite *personaje1; void keyPressEvent(QKeyEvent * evento); @@ -90,9 +129,13 @@ private slots: void niveles(int); + void aceleracion(int); + void clean (); + int path=0; + bool ban=false; QPushButton *start; QPushButton *saveData; From fa27410bc853970c753971ad29662c8568048c32 Mon Sep 17 00:00:00 2001 From: saraycubillos <62775794+saraycubillos@users.noreply.github.com> Date: Sun, 26 Jul 2020 12:51:15 -0500 Subject: [PATCH 2/7] Le agrego la clase vidas y llaves al juego Lanzar fuego y movimiento del enemigo con timer --- llaves.cpp | 26 + llaves.h | 21 + mainwindow.cpp | 1564 ++++++++++++++++++++++++++++++++++++++++++++++++ mainwindow.h | 150 +++++ vidas.cpp | 26 + vidas.h | 23 + 6 files changed, 1810 insertions(+) create mode 100644 llaves.cpp create mode 100644 llaves.h create mode 100644 mainwindow.cpp create mode 100644 mainwindow.h create mode 100644 vidas.cpp create mode 100644 vidas.h diff --git a/llaves.cpp b/llaves.cpp new file mode 100644 index 0000000..ee98b11 --- /dev/null +++ b/llaves.cpp @@ -0,0 +1,26 @@ +#include "llaves.h" + +#include + +llaves::llaves(QGraphicsItem *parent): QGraphicsTextItem(parent) +{ + //inicializar las llaves en 0 + key = 0; + + //ESCRIBIR EL TEXTO + setPlainText(QString("Llaves: ")+QString::number(key)); + setDefaultTextColor(Qt::black); + setFont(QFont("times",16)); + +} + +void llaves::increase() +{ + key++; + setPlainText(QString("Llaves: ")+QString::number(key)); +} + +int llaves::getkey() +{ + return key; +} diff --git a/llaves.h b/llaves.h new file mode 100644 index 0000000..e54e5c3 --- /dev/null +++ b/llaves.h @@ -0,0 +1,21 @@ +#ifndef LLAVES_H +#define LLAVES_H + +#include + + +class llaves: public QGraphicsTextItem +{ + +public: + + llaves(QGraphicsItem * parent=0); + + void increase(); + int getkey(); +private: + + int key; +}; + +#endif // LLAVES_H diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..f3bc001 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,1564 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + //intro->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/fantasy.mp3")); + + +niveles(opcion); + +//-----------------------------BOTÓN USUARIO--------------------------- + +/*save=new QLineEdit("USUARIO", this); + +save->setGeometry(QRect( QPoint(310,10), // Valores por defecto 250x160 +QSize(200, 50) )); +//Valores por defecto : 200x 50 + +connect(save, SIGNAL (clicked()),this, SLOT (guardardatos())); +save->setStyleSheet("background-color: gray");*/ + +start=new QPushButton("INICIAR JUEGO", this); + +start->setGeometry(QRect( QPoint(310,160), // Valores por defecto 250x160 +QSize(200, 50) )); +//Valores por defecto : 200x 50 + +connect(start, SIGNAL (clicked()),this, SLOT (botonInicio())); +start->setStyleSheet("background-color: gray"); + +saveData=new QPushButton ("CONTINUAR PARTIDA ",this); + + +saveData->setGeometry(QRect( QPoint(310,300), +QSize(200, 50) )); + +connect(saveData, SIGNAL (clicked()),this, SLOT (guardarPartida())); +saveData->setStyleSheet("background-color: gray"); + +bolaFuego=new Objeto(0,0,30, ":/IMAGENES/BOLADEFUEGO.png"); + +/* +timer->stop(); +connect(timer,SIGNAL(timeout()),this,SLOT(actualizar())); +timer->start(dt);*/ + + + +/*LISTA.append(new Particula(0,0,0,0,50000,200)); +LISTA.append(new Particula(-5000,0,0,0,70,70)); +LISTA.append(new Particula(5000,0,0,0,70,70)); */ //Planetas agregados directamente +// LISTA.append(new Graficar(0,-5000,2,0,70,70)); +//LISTA.append(new Graficar(0,5000,-2,0,70,70)); + + + +} + + +//-------------------------------------------------KEYPRESSEVENT-------------------------------------------------- + +void MainWindow::keyPressEvent(QKeyEvent *evento) +{ + + qDebug()<pos()<x(); + +//-----------------------------------------EVENTO PERSONAJE 1 NIVEL 1------------------------------------------------- + +if (opcion==1) +{ + if(evento->key()==Qt::Key_A) + { + coaliciones('A', personaje1); + } + + else if(evento->key()==Qt::Key_D) + { + + coaliciones('D', personaje1); + + } + else if(evento->key()==Qt::Key_W) + { + + coaliciones('W', personaje1); + + } + + else if(evento->key()==Qt::Key_S) + { + + coaliciones('S', personaje1); + } + + +// qDebug()<pos()<x(); + +//-------------------------------------------------EVENTO PERSONAJE 2 NIVEL 1------------------------------------------------------------ +if(evento->key()==Qt::Key_I) +{ + + coaliciones('I', personaje2); + +} +if(evento->key()==Qt::Key_J) +{ + coaliciones('J', personaje2); + + +} +if(evento->key()==Qt::Key_L) +{ + + coaliciones('L', personaje2); + +} +if(evento->key()==Qt::Key_K) + +{ + + coaliciones('K', personaje2); + +} + +//------------------------------------------------CAMBIO DE NIVEL 1 A 2------------------------------------------------- + + if (((personaje1->x()==250 or personaje2->x()==250) and (personaje1->y()==390 or personaje2->y()==390 )) ) + { + + + opcion=2; + niveles(opcion); + + } + +} + +//--------------------------------------------------EVENTO PERSONAJE 1 NIVEL 2------------------------------------------------- + +if (opcion==2) +{ + if(evento->key()==Qt::Key_A) + { + coaliciones('A', personaje1); + } + + else if(evento->key()==Qt::Key_D) + { + + coaliciones('D', personaje1); + + } + else if(evento->key()==Qt::Key_W) + { + + coaliciones('W', personaje1); + + } + + else if(evento->key()==Qt::Key_S) + { + + coaliciones('S', personaje1); + } + + +// qDebug()<pos()<x(); + +//-------------------------------------------EVENTO PERSONAJE 2 NIVEL 2------------------------------------------------------------ +if(evento->key()==Qt::Key_I) +{ + + coaliciones('I', personaje2); + +} +if(evento->key()==Qt::Key_J) +{ + coaliciones('J', personaje2); + + +} +if(evento->key()==Qt::Key_L) +{ + + coaliciones('L', personaje2); + +} +if(evento->key()==Qt::Key_K) + + + + +//------------------------------------------------CAMBIO DE NIVEL 2 A 3------------------------------------------------- + + if ((personaje1->x()==250 and personaje1->y()==390) ) + { + + niveles(3); + + } + + +} + +//-----------------------------------------------EVENTO PERSONAJE 1 NIVEL 3------------------------------------------------- + +if (opcion==3) + +{ + if(evento->key()==Qt::Key_A) + { + coaliciones('A', personaje1); + } + + else if(evento->key()==Qt::Key_D) + { + + coaliciones('D', personaje1); + + } + else if(evento->key()==Qt::Key_W) + { + + coaliciones('W', personaje1); + + } + + else if(evento->key()==Qt::Key_S) + { + + coaliciones('S', personaje1); + } + + + + +//---------------------------------------------EVENTO PERSONAJE 2 NIVEL 3------------------------------------------------------------ + +if(evento->key()==Qt::Key_I) +{ + + coaliciones('I', personaje2); + +} +if(evento->key()==Qt::Key_J) +{ + coaliciones('J', personaje2); + + +} +if(evento->key()==Qt::Key_L) +{ + + coaliciones('L', personaje2); + +} +if(evento->key()==Qt::Key_K) + +{ + + coaliciones('K', personaje2); + +} + + + +} + + +} + +void MainWindow::coaliciones(char letra , Personaje *personaje) +{ + if (personaje==personaje1) + { + + if (letra=='A') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + //---------------------------GIRO DEL PERSONAJE1 (A)------------------------------ + + personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(180); + personaje1->izquierda(); + + + //------------------------------COALISIONES1 (A) ---------------------------- + + if(personaje1->collidesWithItem(bolaH)) + { + bolaH->izquierda(); + } + if(personaje1->collidesWithItem(enemigo1)) + + { + resorte('A', personaje1); + x = enemigo1->x(); + y = enemigo1->y(); + vida->decrease(); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } + /*for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + } + } + */ + //------------------------EVALUAR COALISIONES CON MUROS 1(A)------------------ + + for (int i=0;icollidesWithItem(muros.at(i))) + { + + personaje1->derecha(); + } + } + + + //--------------------EVALUAR COALISIONES CON PIEDRAS 1(A)-------------------- + + for (int i=0;icollidesWithItem(piedras.at(i))) + { + + personaje1->derecha(); + } + } + + //--------------------------CAPTURAR LLAVES 1(A)------------------------------- + if(llave->isVisible()) + { + if (personaje1->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } + //--------------------------PUERTA 1(A)------------------------------------------- + if (personaje1->collidesWithItem(puerta)) + { + + personaje1->derecha(); + //remover escena + } + + + + + + + } + if (letra=='D') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + //--------------------------GIRO DEL PERSONAJE 1(D)--------------- + personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(0); + personaje1->derecha(); + + //---------------------------COALISIONES 1(D)---------------------------- + + if(personaje1->collidesWithItem(bolaH)) + + { + bolaH->derecha(); + } + if(personaje1->collidesWithItem(enemigo1)) + + { + x = enemigo1->x(); + y = enemigo1->y(); + resorte('D', personaje1); + vida->decrease(); + //bolaFuego->setPosx(personaje1->pos()); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } + + /*for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + } + }*/ + //----------------------EVALUAR COALISIONES CON MUROS 1(D)------------------ + for (int i=0;icollidesWithItem(muros.at(i))) + { + + + + personaje1->izquierda(); + } + } + //----------------------EVALUAR COALISIONES CON PIEDRAS 1(D)---------------------- + + for (int i=0;icollidesWithItem(piedras.at(i))) + { + + personaje1->izquierda(); + } + } + + //----------------------------CAPTURAR LLAVES 1(D)---------------------------------- + if (llave->isVisible()) + {if (personaje1->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + } + } + //--------------------------PUERTA 1(D)------------------------------ + if (personaje1->collidesWithItem(puerta)) + { + personaje1->izquierda(); + //remover escena + } + } + if (letra=='W') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + + //-------------------------GIRO DE PERSONAJE 1(W)----------------------- + personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(270); + personaje1->subir(); + + + //----------------------------COALISIONES 1(W)-------------------------------- + + if(personaje1->collidesWithItem(bolaH)) + { + bolaH->subir(); + } + if(personaje1->collidesWithItem(enemigo1)) + + { + resorte('W', personaje1); + + + x = enemigo1->x(); + y = enemigo1->y(); + vida->decrease(); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } + /*for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + } + }*/ + //----------------EVALUAR COALISIONES CON MUROS 1(W))----------------------- + for (int i=0;icollidesWithItem(muros.at(i))) + { + + + personaje1->bajar(); + } + } + //-------------------EVALUAR COALISIONES CON PIEDRAS 1(W)--------------------- + + for (int i=0;icollidesWithItem(piedras.at(i))) + { + + personaje1->bajar(); + } + } + + //-----------------------------CAPTURAR LLAVES 1(W)---------------------------- + if(llave->isVisible()) + { + if (personaje1->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } + //-----------------------------------PUERTA 1(W)------------------------------- + if (personaje1->collidesWithItem(puerta)) + { + personaje1->bajar(); + //remover escena + } + + + } + if (letra=='S') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + + //---------------------------GIRO DE PERSONAJE 1(S)--------------------------- + personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(90); + personaje1->bajar(); + + + //------------------------------COALISIONES 1(S)----------------------------- + if(personaje1->collidesWithItem(bolaH)) + { + bolaH->bajar(); + } + if(personaje1->collidesWithItem(enemigo1)) + + + { + + x = enemigo1->x(); + y = enemigo1->y(); + vida->decrease(); + resorte('S', personaje1); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } + /*for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + } + } + */ + //-----------------------EVALUAR COALISIONES CON MUROS 1(S)---------------- + + for (int i=0;icollidesWithItem(muros.at(i))) + { + + personaje1->subir(); + } + } + //----------------------EVALUAR COALISIONES CON PIEDRAS 1(S)--------------- + + for (int i=0;icollidesWithItem(piedras.at(i))) + { + + personaje1->subir(); + } + } + + //--------------------------CAPTURAR LLAVES 1(S)------------------------- + if(llave->isVisible()) + {if (personaje1->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } + + //-------------------------PUERTA 1(S)----------------------------------- + + if (personaje1->collidesWithItem(puerta)) + { + personaje1->subir(); + //remover escena + } + + + + + + } + + + + } + + if (personaje==personaje2) + { + + if (letra=='I') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + + //-------------------GIRO DE PERSONAJE 2(I)------------------- + personaje2->setTransformOriginPoint(0,0); + personaje2->setRotation(270); + personaje2->subir(); + + + //--------------------------COALISIONES 2(I)------------------------ + + if(personaje2->collidesWithItem(bolaH)) + { + bolaH->subir(); + } + if(personaje2->collidesWithItem(enemigo1)) + + { + resorte('I', personaje2); + + + x = enemigo1->x(); + y = enemigo1->y(); + vida->decrease(); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } + /*for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + } + }*/ + //-----------------------------EVALUAR COALISIONES CON MUROS 2(I)------------------ + + for (int i=0;icollidesWithItem(muros.at(i))) + { + + + personaje2->bajar(); + } + } + //-------------------------------EVALUAR COALISIONES CON PIEDRAS 2(I)-------------- + + for (int i=0;icollidesWithItem(piedras.at(i))) + { + + personaje2->bajar(); + } + } + + //------------------------------------CAPTURAR LLAVES 2(I)-------------------- + if(llave->isVisible()) + {if (personaje2->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } + //------------------------------------PUERTA 2(I)---------------------------------- + if (personaje2->collidesWithItem(puerta)) + { + personaje2->bajar(); + //remover escena + } + + + } + + if (letra=='J') + { + + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + //---------GIRO DEL PERSONAJE------- + personaje2->setTransformOriginPoint(0,0); + personaje2->setRotation(180); + personaje2->izquierda(); + + + //------------------------COALISIONES 2(J)---------------------------------- + + if(personaje2->collidesWithItem(bolaH)) + { + bolaH->izquierda(); + } + if(personaje2->collidesWithItem(enemigo1)) + + { + resorte('J', personaje2); + x = enemigo1->x(); + y = enemigo1->y(); + vida->decrease(); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } + /*for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + } + }*/ + //-----------------------EVALUAR COALISIONES CON MUROS 2(J)--------------------- + for (int i=0;icollidesWithItem(muros.at(i))) + { + + personaje2->derecha(); + } + } + + + //-------------------------EVALUAR COALISIONES CON PIEDRAS 2(J)-------------- + + for (int i=0;icollidesWithItem(piedras.at(i))) + { + + personaje2->derecha(); + } + } + + //----------------------------CAPTURAR LLAVES 2(J)----------------------- + if(llave->isVisible()) + {if (personaje2->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } + //----------------------------------PUERTA 2(J)------------------------------- + + if (personaje2->collidesWithItem(puerta)) + { + + personaje2->derecha(); + //remover escena + } + + + + + + + + + } + + + if (letra=='L') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + //---------GIRO DEL PERSONAJE------- + personaje2->setTransformOriginPoint(0,0); + personaje2->setRotation(0); + personaje2->derecha(); + + //-------------------------------COALISIONES 2(L) -------------------------------- + if(personaje2->collidesWithItem(bolaH)) + + { + bolaH->derecha(); + } + if(personaje2->collidesWithItem(enemigo1)) + + { + x = enemigo1->x(); + y = enemigo1->y(); + resorte('L', personaje2); + vida->decrease(); + //bolaFuego->setPosx(personaje1->pos()); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } + /* + for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + } + }*/ + //------------------------EVALUAR COALISIONES CON MUROS 2(L)-------------------------- + for (int i=0;icollidesWithItem(muros.at(i))) + { + + + + personaje2->izquierda(); + } + } + //---------------------EVALUAR COALISIONES CON PIEDRAS 2(L)---------------------------- + + for (int i=0;icollidesWithItem(piedras.at(i))) + { + + personaje2->izquierda(); + } + } + + //------------------------------CAPTURAR LLAVES 2(L)-------------------------------- + if(llave->isVisible()) + {if (personaje2->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } + //-------------------------------------PUERTA 2(L)----------------------------- + if (personaje2->collidesWithItem(puerta)) + { + personaje2->izquierda(); + //remover escena + } + } + + + if (letra=='K') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + + //---------------------------------GIRO DE PERSONAJE 2(K)---------------------- + personaje2->setTransformOriginPoint(0,0); + personaje2->setRotation(90); + personaje2->bajar(); + + + //----------------------------------COALISIONES 2(K)-------------------------------- + + if(personaje2->collidesWithItem(bolaH)) + { + bolaH->bajar(); + } + if(personaje2->collidesWithItem(enemigo1)) + + + { + + x = enemigo1->x(); + y = enemigo1->y(); + vida->decrease(); + resorte('K', personaje2); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } + /*for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + } + } + */ + //--------------------------EVALUAR COALISIONES CON MUROS 2(K)-------------------------- + + for (int i=0;icollidesWithItem(muros.at(i))) + { + + personaje2->subir(); + } + } + //-----------------------------EVALUAR COALISIONES CON PIEDRAS 2(K)---------------------- + for (int i=0;icollidesWithItem(piedras.at(i))) + { + + personaje2->subir(); + } + } + + //-----------------------------CAPTURAR LLAVES 2(K)------------------------------------ + if(llave->isVisible()) + {if (personaje2->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } + //------------------------------PUERTA 2(K)------------------------------------------ + + if (personaje2->collidesWithItem(puerta)) + { + personaje2->subir(); + //remover escena + } + + + + + + } + } + +} + + + + + +//------------------------------------------------------NIVELES-------------------------------------------------- + + +void MainWindow::botonInicio() +{ + opcion=1; + niveles(opcion); +} + +void MainWindow:: niveles(int opcion) +{ + if (opcion==0) + { + + ui->setupUi(this); + scene = new QGraphicsScene; + ui->graphicsView->setScene(scene); + + /*QMovie *movie= new QMovie (":/IMAGENES/MENU.gif"); + label->setMovie(movie); + movie->start(); + */ + /* QMovie *movie= new QMovie (":/IMAGENES/MENU.gif"); + label = new QLabel(this); + label->setMovie(movie); + movie->start();*/ + + scene->setBackgroundBrush(QPixmap(":/IMAGENES/MAINMENU.png")); + scene->setSceneRect(0,0,790,550); + + intro=new QMediaPlayer (); + intro->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/fantasy.mp3")); + + + //intro->play(); + + + + } + if (opcion==1) + { + + + //intro->stop(); + key=new QMediaPlayer (); + key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + + timer= new QTimer; + connect(timer,SIGNAL(timeout()), this, SLOT (mover())); + QTimer *cronometro = new QTimer(this); + connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); + cronometro->start(10000); + + /* QTimer *cronometro2 = new QTimer(this); + connect(cronometro2, SIGNAL(timeout()),this,SLOT(magnetismo())); + cronometro2->start(1000);*/ + + /* parabolico= new QTimer; + parabolico->stop(); + connect(parabolico,SIGNAL(timeout()),this,SLOT(Mover())); + parabolico->start(40);*/ + //CREANDO LA ESCENA + ui->setupUi(this); + scene = new QGraphicsScene; + ui->graphicsView->setScene(scene); + scene->setBackgroundBrush(QPixmap(":/IMAGENES/PisoPiedra.jpg")); + scene->setSceneRect(0,0,400,400); + + + + //x,y ,r,friccion,a,v,ang,path + personaje1=new Personaje(495,410,30,1, ":/IMAGENES/PERSONAJE1.png"); + scene->addItem(personaje1); + + personaje2=new Personaje(0,0,45,1, ":/IMAGENES/PERSONAJE2.png"); + scene->addItem(personaje2); + + enemigo1= new Personaje (-105,310 + ,60,1,":/IMAGENES/ENEMIGO.png"); //antes -105, 310 + scene->addItem(enemigo1); + + timerEnem= new QTimer; + timerEnem->stop(); + connect(timerEnem, SIGNAL(timeout()), this , SLOT (moverEnemigo())); + timerEnem->start(9000); + + rigidez=10; + aceleracion=150; + + vida=new vidas(); + vida->setPos(120,35); + scene->addItem(vida); + keys=new llaves(); + keys->setPos(270,35); + scene->addItem(keys); + //particula1=new Particula( -105,310,0,0,50000,200, ":/IMAGENES/BOLADEMETAL.png "); + //particula2=new Particula(-5000,0,0,0,70,70 ,":/IMAGENES/BOLA DE FUEGO.png "); + + + + + + /* disparo=new QTimer; + disparo->stop(); + connect(disparo, SIGNAL(timeout()), this , SLOT (lanzamiento)); + disparo->start(1000);*/ + + + + + + + + + + items(); + + + + } + if (opcion==2) + { + + timer->stop(); + clean(); + //CREANDO LA ESCENA + ui->setupUi(this); + scene = new QGraphicsScene; + ui->graphicsView->setScene(scene); + scene->setBackgroundBrush(QPixmap(":/IMAGENES/black_stone.jpg")); + scene->setSceneRect(0,0,400,400); + + timer= new QTimer; + connect(timer,SIGNAL(timeout()), this, SLOT (mover())); + QTimer *cronometro = new QTimer(this); + connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); + cronometro->start(10000); + /* parabolico= new QTimer; + parabolico->stop(); + connect(parabolico,SIGNAL(timeout()),this,SLOT(Mover())); + parabolico->start(40); + QTimer *cronometro2 = new QTimer(this); + connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); + cronometro2->start(1000);*/ + timer->start(); //x,y ,r,friccion,a,v,ang,path + personaje1=new Personaje(495,410,30,1.5,":/IMAGENES/PERSONAJE1.png"); + scene->addItem(personaje1); + + enemigo1= new Personaje (-135,415,60,1.5,":/IMAGENES/ENEMIGO.png"); + scene->addItem(enemigo1); + + + rigidez=11; + aceleracion=160; + + + + + + + items(); + + + } + if (opcion==3) + { + timer->stop(); + clean(); + //CREANDO LA ESCENA + ui->setupUi(this); + scene = new QGraphicsScene; + ui->graphicsView->setScene(scene); + scene->setBackgroundBrush(QPixmap(":/IMAGENES/ARENA.jpg")); + scene->setSceneRect(0,0,400,400); + + timer= new QTimer; + connect(timer,SIGNAL(timeout()), this, SLOT (mover())); + QTimer *cronometro = new QTimer(this); + connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); + cronometro->start(10000); + /* parabolico= new QTimer; + parabolico->stop(); + connect(parabolico,SIGNAL(timeout()),this,SLOT(Mover())); + parabolico->start(40); + QTimer *cronometro2 = new QTimer(this); + connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); + cronometro2->start(1000);*/ + timer->start(); //x,y ,r,friccion,a,v,ang,path + personaje1=new Personaje(495,410,30,1.2, ":/IMAGENES/PERSONAJE1.png"); + scene->addItem(personaje1); + + enemigo1= new Personaje (395,210,60,1.5,":/IMAGENES/SERPIENTE1(1).png"); + scene->addItem(enemigo1); + + totem= new Personaje (0,0,60 ,1, ":/IMAGENES/TOTEMARENA.png"); + scene->addItem(totem); + timer->start(); + + rigidez=12; + aceleracion=170; + items(); + + } + +} + +void MainWindow::items() +{ + + + llave= new Objeto (415,360,30,":/IMAGENES/llave1.png"); + scene->addItem(llave); + + bolaH= new Objeto (75,160, 30,":/IMAGENES/BOLADEMETAL.png"); + scene->addItem(bolaH); + + puerta=new Objeto(465,25, 80,":/IMAGENES/Door1.png" ); + scene->addItem(puerta); + + + muros.push_back(new Pared (200,-450,800,100, ":/IMAGENES/BLOQUE.jpg")); + scene->addItem(muros.back()); + + muros.push_back(new Pared (200,150,800,100, ":/IMAGENES/BLOQUE.jpg")); + scene->addItem(muros.back()); + + muros.push_back(new Pared (250,100,100,800, ":/IMAGENES/BLOQUE.jpg")); + scene->addItem(muros.back()); + + muros.push_back(new Pared (-550,100,100,800, ":/IMAGENES/BLOQUE.jpg")); + scene->addItem(muros.back()); + + + + piedras.push_back(new Objeto(135,110,40,":/IMAGENES/rocas2.png")); + scene->addItem(piedras.back()); + piedras.push_back(new Objeto(280,220,40,":/IMAGENES/rocas2.png")); + scene->addItem(piedras.back()); + piedras.push_back(new Objeto(275,115,40,":/IMAGENES/rocas2.png")); + scene->addItem(piedras.back()); + piedras.push_back(new Objeto(140,220,40,":/IMAGENES/rocas2.png")); + scene->addItem(piedras.back()); + piedras.push_back(new Objeto(135,170,40,":/IMAGENES/rocas2.png")); + scene->addItem(piedras.back()); + piedras.push_back(new Objeto(205,110,40,":/IMAGENES/rocas2.png")); + scene->addItem(piedras.back()); + piedras.push_back(new Objeto(275,160,40,":/IMAGENES/rocas2.png")); + scene->addItem(piedras.back()); + + dragon=new Sprite (); + dragon->setPos(110,345); + scene->addItem(dragon); + +} + +void MainWindow::clean() +{ + scene->removeItem(enemigo1); + delete (enemigo1); + scene->removeItem(personaje1); + delete (personaje1); + + + /*for (int i=0;iremoveItem(cuerpos.at(i)); + delete (cuerpos.at (i)); + cuerpos.removeOne(cuerpos.at(i)); + + + + }*/ + for (int i=0;iremoveItem(piedras.at(i)); + delete (piedras.at (i)); + piedras.removeOne(piedras.at(i)); + + } + + + + scene->removeItem(puerta); + delete (puerta); +} + +void MainWindow::guardarPartida() +{ + QFile archivo("PLANETAS.txt"); + if(archivo.open(QIODevice::Append | QIODevice::Text)){ + QTextStream datosArchivo(&archivo); + + + //datosArchivo << text<< endl; + + } + archivo.close(); +} + + +//--------------------------------------------------FISICAS-------------------------------------------------- + + +void MainWindow::CoeficienteRestitucion() +{ + +} + +void MainWindow:: lanzamiento () +{ + + /* int xinicial=0; + int xfinal=personaje1->x(); + int yinicial=0; + int yfinal=personaje1->y(); + + while ((xinicial!=xfinal) or (yinicial!=yfinal)) + { + + if (xinicialyfinal) + { + yinicial--; + + } + + path++; + } + //cout<<" PATH: "<<"( "<xfinal) + + { + + xinicial--; + if(yinicialyfinal) + { + yinicial--; + + } + + + path++; + } + if(path%10==0) + {if (i==1) + { + bolaFuego->setPos(xinicial,yinicial); + scene->addItem(bolaFuego); + timer->start(30); + + } + + if(i==100) + { + bolaFuego->setPos(xinicial,yinicial); + scene->addItem(bolaFuego); + i=0; + timer->start(30); + } + + i++; + +} + } +*/ + + +} + + +void MainWindow::lanzarfuego() +{if (opcion==1) + { + x = enemigo1->x(); + y = enemigo1->y(); //(an,posxx,posyy,velocidad,r,path) + cuerpos.push_back(new Particula (0,x, y,100,30,":/IMAGENES/BOLADEFUEGO.png")); + scene->addItem(cuerpos.back()); + timer->start(30); + } + if (opcion==2) + { + x = enemigo1->x(); + y = enemigo1->y(); //(an,posxx,posyy,velocidad,r,path) + cuerpos.push_back(new Particula (0,x, y,200,30,":/IMAGENES/BOLADEFUEGO.png")); + scene->addItem(cuerpos.back()); + timer->start(30); + } + if (opcion==3) + { + x = enemigo1->x(); + y = enemigo1->y(); //(an,posxx,posyy,velocidad,r,path) + cuerpos.push_back(new Particula (0,x, y,300,30,":/IMAGENES/BOLADEFUEGO.png")); + scene->addItem(cuerpos.back()); + timer->start(30); + } + +} +void MainWindow::mover() +{ + for (QList :: iterator it=cuerpos.begin(); it!=cuerpos.end(); it++) + { + (*it)->CalcularVelocidad(); + (*it)->ActualizarPosicion(); + + + } + for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + vida->decrease(); + } + + } + for (int i=0;icollidesWithItem(cuerpos.at(i))) + { + scene->removeItem(cuerpos.at(i)); + cuerpos.removeOne(cuerpos.at(i)); + vida->decrease(); + } + + } +} + +void MainWindow::resorte(char letra , Personaje *personaje) +{ + if (personaje==personaje1) + { + + if (letra=='A') + {personaje1-> setPos(personaje1->x()+5*rigidez,personaje1->y()); + } + if (letra=='D') + {personaje1-> setPos(personaje1->x()-5*rigidez,personaje1->y()); + } + if (letra=='W') + {personaje1->setPos(personaje1->x(),personaje1->y()+5*rigidez); + } + if(letra=='S') + {personaje1->setPos(personaje1->x(),personaje1->y()-5*rigidez); + } + } + + if(personaje==personaje2) + {if(letra=='J') + {personaje2-> setPos(personaje2->x()+5*rigidez,personaje2->y()); + } + if(letra=='L') + {personaje2-> setPos(personaje2->x()-5*rigidez,personaje2->y()); + } + if(letra=='I') + {personaje2->setPos(personaje2->x(),personaje2->y()+5*rigidez); + } + if(letra=='K') + {personaje2->setPos(personaje2->x(),personaje2->y()-5*rigidez); + } + } +} + +void MainWindow::magnetismo() +{ + /*if (opcion==1) + {float f, dx, dy,r; + dx=enemigo1->x()-personaje1->x(); + dy=enemigo1->x()-personaje1->x(); + r=pow(dx,2)+pow(dy,2); + f=(M*M)/(K*pow(r,2)); + x = enemigo1->x()*f; + y = enemigo1->y()*f; + bolaFuego->setPos(x,y); + scene->addItem(bolaFuego); + timer->start(30); + }*/ +} + +/*void MainWindow::guardardatos(QString usuario) +{ + QString text; + + text=usuario+" "+'\n' ; + + QFile archivo("USUARIO.txt"); + + + if(archivo.open(QIODevice::Append | QIODevice::Text)){ + QTextStream datosArchivo(&archivo); + + + datosArchivo << text<< endl; + + } + archivo.close(); +} +*/ + +void MainWindow::Mover() +{/* + for(QList::iterator it=cuerpos.begin(); it!=cuerpos.end();it++) + { + (*it)->CalcularVelicidad(); + (*it)->ActualizarPosicion(); + } + double ang,x,y,v,a; + ang= enemigo1->angulo; + x= enemigo1->posx; + y= enemigo1->posy; + v= enemigo1->velocidad; + a= (ang/180)*3.1416; + cuerpos.push_back(new particula(rad, x, y, v)); + scene->addItem(cuerpos.back()); + //cuerpo= new particula(rad, x, y, v); + //Scene->addItem(cuerpo); + timer->start(30);*/ + +} + +void MainWindow::moverEnemigo( ) +{ + if(ban==false) + {enemigo1->setX(enemigo1->x()+2*aceleracion); + if(enemigo1->x()>=514) + {ban=true; + } + } + if(ban==true) + {enemigo1->setX(enemigo1->x()-2*aceleracion); + if(enemigo1->x()<=-96) + {ban=false; + } + } +} + + + +//-------------------------------------------------DESTRUCTOR--------------------------------------------------------------- + + +MainWindow::~MainWindow() +{ + delete ui; + +} + + + +void MainWindow::actualizar() +{ + + + /*for (int i=0; i Acacelx(*(particula2)); + + // LISTA.at(i)-> Acacely(*(LISTA.at(j) )); + } + } + } + for(int i=0;iActualizar(); + particula1->Actualizar(particula1); + particula1->Actualizar(particula2); + + + }*/ + //actualiza cada dato + + + +//actualiza cada dato +} + diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..fa113ce --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,150 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define K 0.00000001 +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + + //QList muros; + QList muros; + QList piedras; + QList cuerpos; + +private slots: + + + //SLOTS DE LA PARTÍCULA + + + /*double masa; + double posx; + double posy; + double radio; + double vx; + double vy;*/ + + void mover(); + + void actualizar(); + + void lanzamiento (); + + void lanzarfuego(); + + void guardarPartida(); + + void botonInicio(); + + void moverEnemigo(); + + void CoeficienteRestitucion(); + + void coaliciones (char , Personaje *personaje ); + + void magnetismo(); + + void Mover(); + + void resorte(char letter,Personaje *personaje); + + //void guardardatos(QString usuario); + +private: + + Ui::MainWindow *ui; + QGraphicsScene *scene; + + //SONIDOS + QMediaPlayer *key; + QMediaPlayer *intro; + + + //PARTÍCULA + QTimer *timerEnem; + QTimer *timer; + QTimer *Timer; + QTimer *disparo; + QTimer *parabolico; + QLabel *label; + /*Particula *cuerpo; + QListcuerpos; + QListLISTA;*/ + + //OBJETOS + //Personaje *personaje1; + Personaje *enemigo1; + Personaje *totem; + Personaje *personaje1; + Personaje *personaje2; + Personaje *lanzador; + Sprite *dragon; + Objeto *puerta; + Objeto *bolaH; + Objeto *bolaFuego; + Objeto *llave; + QObject *personaje; + vidas *vida; + llaves *keys; + + //particula *cuerpo; + double x; + double y; + int opcion=0; + int nivel=0; + int i=0; + int rigidez=0; + int aceleracion; + //____ prueba + /*Particula *particula1; + Particula *particula2;*/ + // Sprite *personaje1; + + void keyPressEvent(QKeyEvent * evento); + + void items(); + + void niveles(int); + + void clean (); + + int path=0; + + bool ban=false; + +QPushButton *start; +QPushButton *saveData; +//QLineEdit *save; +}; +#endif // MAINWINDOW_H diff --git a/vidas.cpp b/vidas.cpp new file mode 100644 index 0000000..297bb80 --- /dev/null +++ b/vidas.cpp @@ -0,0 +1,26 @@ +#include "vidas.h" + +#include + +vidas::vidas(QGraphicsItem *parent): QGraphicsTextItem(parent) +{ + //inicializar las vidas en 3 + life = 3; + + //ESCRIBIR EL TEXTO + setPlainText(QString("Vidas: ")+QString::number(life)); + setDefaultTextColor(Qt::red); + setFont(QFont("times",16)); + +} + +void vidas::decrease() +{ + life--; + setPlainText(QString("Vidas: ")+QString::number(life)); +} + +int vidas::getlife() +{ + return life; +} diff --git a/vidas.h b/vidas.h new file mode 100644 index 0000000..26b5746 --- /dev/null +++ b/vidas.h @@ -0,0 +1,23 @@ +#ifndef VIDAS_H +#define VIDAS_H + +#include + + +class vidas: public QGraphicsTextItem +{ + +public: + + vidas(QGraphicsItem * parent=0); + + void decrease(); + int getlife(); + +private: + + int life; + +}; + +#endif // VIDAS_H From 6dd664cbe8107787b6c1dac584b2c82073f42115 Mon Sep 17 00:00:00 2001 From: saraycubillos <62775794+saraycubillos@users.noreply.github.com> Date: Sun, 26 Jul 2020 14:58:50 -0500 Subject: [PATCH 3/7] =?UTF-8?q?Se=20le=20quit=C3=B3=20aceleraci=C3=B3n=20a?= =?UTF-8?q?l=20personaje?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- personaje.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ personaje.h | 41 ++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 personaje.cpp create mode 100644 personaje.h diff --git a/personaje.cpp b/personaje.cpp new file mode 100644 index 0000000..e934b5c --- /dev/null +++ b/personaje.cpp @@ -0,0 +1,94 @@ +#include "personaje.h" + +Personaje::Personaje() +{ + +} + +Personaje::Personaje(int x, int y, int r, float f, QString path) +{ + radio=r; + posx = x; + posy = y; + ruta=path; + friccion=f; + setPos(posx,posy); +} + +int Personaje::getR() +{ + return radio; +} + +void Personaje::setR(int r) +{ + radio = r; +} + +int Personaje::getPosx() +{ + return posx; +} + +void Personaje::setPosx(int px) +{ + posx=px; +} + +int Personaje::getPosy() +{ + return posy; +} + +void Personaje::setPosy(int py) +{ + posy = py; +} + +void Personaje::subir() +{setPos(x(),y()-5*friccion*M*G); +} + +void Personaje::bajar() +{ + setPos(x(),y()+5*friccion*M*G); +} + +void Personaje::derecha() +{ + setPos(x()+5*friccion*M*G,y()); +} + +void Personaje::izquierda() +{ + + setPos(x()-5*friccion*M*G,y()); + +} + +/*void Personaje::setFriccion( int f ) +{ + friccion=f; +} +int Personaje::getFriccion() +{ + return friccion; +}*/ + +QRectF Personaje::boundingRect() const +{ + return QRectF(-radio,-radio,2*radio,2*radio); +} + +void Personaje::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + /*QPixmap personaje; + personaje.load(ruta); + painter->drawPixmap(boundingRect(),personaje,personaje.rect());*/ + + + QPixmap *personaje=new QPixmap(ruta); + *personaje=personaje->transformed(QTransform().scale(-1,1)); + painter->drawPixmap(boundingRect(),*personaje,personaje->rect()); + +} diff --git a/personaje.h b/personaje.h new file mode 100644 index 0000000..d9c3348 --- /dev/null +++ b/personaje.h @@ -0,0 +1,41 @@ +#ifndef PERSONAJE_H +#define PERSONAJE_H +#include +#include + +#include +#define M 5 +#define G 1 + +class Personaje : public QGraphicsItem +{ +public: + int radio; + int posx, posy; + QString ruta; + float friccion; + +public: + + Personaje(); + Personaje ( int x, int y , int r, float friccion , QString path); + int getR(); + void setR(int radio); + int getPosx(); + void setPosx(int px); + int getPosy(); + void setPosy(int py); + void subir(); + void bajar(); + void derecha(); + void izquierda(); + float getaceleracion(); + void setaceleracion(int radio); + //void setFriccion(int f); + //int getFriccion( ); + QRectF boundingRect() const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr); + +}; + +#endif // PERSONAJE_H From 1e631d81065985fad88a7f5c7c7b46d6c10709b1 Mon Sep 17 00:00:00 2001 From: saraycubillos <62775794+saraycubillos@users.noreply.github.com> Date: Mon, 27 Jul 2020 20:44:55 -0500 Subject: [PATCH 4/7] Junto las ramas --- mainwindow.cpp | 1988 ++++++++++++++++++++++++++++++++---------------- mainwindow.h | 47 +- 2 files changed, 1363 insertions(+), 672 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index f3bc001..d29853d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -10,16 +10,7 @@ MainWindow::MainWindow(QWidget *parent) niveles(opcion); -//-----------------------------BOTÓN USUARIO--------------------------- - -/*save=new QLineEdit("USUARIO", this); - -save->setGeometry(QRect( QPoint(310,10), // Valores por defecto 250x160 -QSize(200, 50) )); -//Valores por defecto : 200x 50 - -connect(save, SIGNAL (clicked()),this, SLOT (guardardatos())); -save->setStyleSheet("background-color: gray");*/ +//-----------------------------BOTÓN START--------------------------- start=new QPushButton("INICIAR JUEGO", this); @@ -30,16 +21,28 @@ QSize(200, 50) )); connect(start, SIGNAL (clicked()),this, SLOT (botonInicio())); start->setStyleSheet("background-color: gray"); -saveData=new QPushButton ("CONTINUAR PARTIDA ",this); +//-----------------------------BOTÓN CONTINUAR PARTIDA------------------ + +continuarPartida=new QPushButton ("CONTINUAR PARTIDA ",this); + +continuarPartida->setGeometry(QRect( QPoint(310,300), +QSize(200, 50) )); + +connect(continuarPartida, SIGNAL (clicked()),this, SLOT (continuar())); +continuarPartida->setStyleSheet("background-color: gray"); + +//-----------------------------BOTÓN GUARDAR JUEGO ------------------ -saveData->setGeometry(QRect( QPoint(310,300), +guardar=new QPushButton ("GUARDAR PARTIDA",this); + +guardar->setGeometry(QRect( QPoint(0,0), QSize(200, 50) )); -connect(saveData, SIGNAL (clicked()),this, SLOT (guardarPartida())); -saveData->setStyleSheet("background-color: gray"); +connect(guardar, SIGNAL (clicked()),this, SLOT (continuar())); +guardar ->setStyleSheet("background-color: red"); -bolaFuego=new Objeto(0,0,30, ":/IMAGENES/BOLADEFUEGO.png"); +bolaFuego=new Objeto(0,0,30, ":/IMAGENES/BOLA DE FUEGO.png"); /* timer->stop(); @@ -80,8 +83,8 @@ if (opcion==1) coaliciones('D', personaje1); - } - else if(evento->key()==Qt::Key_W) + } + else if(evento->key()==Qt::Key_W) { coaliciones('W', personaje1); @@ -117,27 +120,22 @@ if(evento->key()==Qt::Key_L) } if(evento->key()==Qt::Key_K) - { coaliciones('K', personaje2); } - +teletransportacion(); //------------------------------------------------CAMBIO DE NIVEL 1 A 2------------------------------------------------- - if (((personaje1->x()==250 or personaje2->x()==250) and (personaje1->y()==390 or personaje2->y()==390 )) ) +/*if (evento->key()==Qt::Key_2) + //if (((personaje1->x()==200 )and (personaje1->y()==60 )) ) { - - - opcion=2; - niveles(opcion); - - } + }*/ } -//--------------------------------------------------EVENTO PERSONAJE 1 NIVEL 2------------------------------------------------- +//-----------------------------------------------EVENTO PERSONAJE 1 NIVEL 2------------------------------------------------- if (opcion==2) { @@ -188,18 +186,18 @@ if(evento->key()==Qt::Key_L) } if(evento->key()==Qt::Key_K) - - - - +{ + coaliciones('K', personaje2); +} +teletransportacion(); //------------------------------------------------CAMBIO DE NIVEL 2 A 3------------------------------------------------- - if ((personaje1->x()==250 and personaje1->y()==390) ) +/*if (evento->key()==Qt::Key_3) { - - niveles(3); - - } + clean(); + opcion=3; + niveles(opcion); + }*/ } @@ -207,7 +205,6 @@ if(evento->key()==Qt::Key_K) //-----------------------------------------------EVENTO PERSONAJE 1 NIVEL 3------------------------------------------------- if (opcion==3) - { if(evento->key()==Qt::Key_A) { @@ -234,8 +231,6 @@ if (opcion==3) } - - //---------------------------------------------EVENTO PERSONAJE 2 NIVEL 3------------------------------------------------------------ if(evento->key()==Qt::Key_I) @@ -257,325 +252,623 @@ if(evento->key()==Qt::Key_L) } if(evento->key()==Qt::Key_K) - { coaliciones('K', personaje2); } +teletransportacion(); } +//-----------------------------------------------EVENTO PERSONAJE 1 NIVEL 4------------------------------------------------- +if (opcion==4) +{ + if(evento->key()==Qt::Key_A) + { + coaliciones('A', personaje1); + } -} + else if(evento->key()==Qt::Key_D) + { -void MainWindow::coaliciones(char letra , Personaje *personaje) -{ - if (personaje==personaje1) - { + coaliciones('D', personaje1); - if (letra=='A') - { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + } + else if(evento->key()==Qt::Key_W) + { - //---------------------------GIRO DEL PERSONAJE1 (A)------------------------------ + coaliciones('W', personaje1); - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(180); - personaje1->izquierda(); + } + else if(evento->key()==Qt::Key_S) + { - //------------------------------COALISIONES1 (A) ---------------------------- + coaliciones('S', personaje1); + } - if(personaje1->collidesWithItem(bolaH)) - { - bolaH->izquierda(); - } - if(personaje1->collidesWithItem(enemigo1)) + //---------------------------------------------EVENTO PERSONAJE 2 NIVEL 4------------------------------------------------------------ + if(evento->key()==Qt::Key_I) { - resorte('A', personaje1); - x = enemigo1->x(); - y = enemigo1->y(); - vida->decrease(); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); - timer->start(30); + coaliciones('I', personaje2); + } - /*for (int i=0;ikey()==Qt::Key_J) { - if (personaje1->collidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - } - } - */ - //------------------------EVALUAR COALISIONES CON MUROS 1(A)------------------ + coaliciones('J', personaje2); - for (int i=0;icollidesWithItem(muros.at(i))) - { - personaje1->derecha(); } - } - - - //--------------------EVALUAR COALISIONES CON PIEDRAS 1(A)-------------------- - - for (int i=0;icollidesWithItem(piedras.at(i))) + if(evento->key()==Qt::Key_L) { - personaje1->derecha(); - } - } - - //--------------------------CAPTURAR LLAVES 1(A)------------------------------- - if(llave->isVisible()) - { - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); - keys->increase(); - llave->hide(); - //delete (llave); + coaliciones('L', personaje2); } - } - //--------------------------PUERTA 1(A)------------------------------------------- - if (personaje1->collidesWithItem(puerta)) + if(evento->key()==Qt::Key_K) { - personaje1->derecha(); - //remover escena + coaliciones('K', personaje2); + } + teletransportacion(); + /*if (evento->key()==Qt::Key_5) + { + clean(); + opcion=5; + niveles(5); + }*/ +} +//-----------------------------------------------EVENTO PERSONAJE 1 NIVEL 5------------------------------------------------- +if (opcion==5) +{ + if(evento->key()==Qt::Key_A) + { + coaliciones('A', personaje1); + } + else if(evento->key()==Qt::Key_D) + { + coaliciones('D', personaje1); + } + else if(evento->key()==Qt::Key_W) + { - } - if (letra=='D') - { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + coaliciones('W', personaje1); - //--------------------------GIRO DEL PERSONAJE 1(D)--------------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(0); - personaje1->derecha(); + } - //---------------------------COALISIONES 1(D)---------------------------- + else if(evento->key()==Qt::Key_S) + { - if(personaje1->collidesWithItem(bolaH)) + coaliciones('S', personaje1); + } - { - bolaH->derecha(); - } - if(personaje1->collidesWithItem(enemigo1)) - { - x = enemigo1->x(); - y = enemigo1->y(); - resorte('D', personaje1); - vida->decrease(); - //bolaFuego->setPosx(personaje1->pos()); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); + //---------------------------------------------EVENTO PERSONAJE 2 NIVEL 5------------------------------------------------------------ - timer->start(30); - } + if(evento->key()==Qt::Key_I) + { - /*for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - } - }*/ - //----------------------EVALUAR COALISIONES CON MUROS 1(D)------------------ - for (int i=0;icollidesWithItem(muros.at(i))) - { + coaliciones('I', personaje2); + } + if(evento->key()==Qt::Key_J) + { + coaliciones('J', personaje2); - personaje1->izquierda(); - } - } - //----------------------EVALUAR COALISIONES CON PIEDRAS 1(D)---------------------- + } + if(evento->key()==Qt::Key_L) + { - for (int i=0;icollidesWithItem(piedras.at(i))) - { + coaliciones('L', personaje2); - personaje1->izquierda(); - } - } + } + if(evento->key()==Qt::Key_K) + { - //----------------------------CAPTURAR LLAVES 1(D)---------------------------------- - if (llave->isVisible()) - {if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); - keys->increase(); - llave->hide(); - //delete (llave); - } - } - //--------------------------PUERTA 1(D)------------------------------ - if (personaje1->collidesWithItem(puerta)) - { - personaje1->izquierda(); - //remover escena - } - } - if (letra=='W') - { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + coaliciones('K', personaje2); + } - //-------------------------GIRO DE PERSONAJE 1(W)----------------------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(270); - personaje1->subir(); +teletransportacion(); + /*if (evento->key()==Qt::Key_6) + { + clean(); + opcion=6; + niveles(6); + }*/ +} +//-----------------------------------------------EVENTO PERSONAJE 1 NIVEL 6------------------------------------------------- - //----------------------------COALISIONES 1(W)-------------------------------- +if (opcion==6) +{ - if(personaje1->collidesWithItem(bolaH)) + + if(evento->key()==Qt::Key_A) { - bolaH->subir(); + coaliciones('A', personaje1); } - if(personaje1->collidesWithItem(enemigo1)) + else if(evento->key()==Qt::Key_D) { - resorte('W', personaje1); - - x = enemigo1->x(); - y = enemigo1->y(); - vida->decrease(); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); + coaliciones('D', personaje1); - timer->start(30); - } - /*for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); } - }*/ - //----------------EVALUAR COALISIONES CON MUROS 1(W))----------------------- - for (int i=0;icollidesWithItem(muros.at(i))) + else if(evento->key()==Qt::Key_W) { + coaliciones('W', personaje1); - personaje1->bajar(); } - } - //-------------------EVALUAR COALISIONES CON PIEDRAS 1(W)--------------------- - for (int i=0;icollidesWithItem(piedras.at(i))) + else if(evento->key()==Qt::Key_S) { - personaje1->bajar(); - } + coaliciones('S', personaje1); } - //-----------------------------CAPTURAR LLAVES 1(W)---------------------------- - if(llave->isVisible()) - { - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); - keys->increase(); - llave->hide(); - //delete (llave); - } - } - //-----------------------------------PUERTA 1(W)------------------------------- - if (personaje1->collidesWithItem(puerta)) - { - personaje1->bajar(); - //remover escena - } +//---------------------------------------------EVENTO PERSONAJE 2 NIVEL 6------------------------------------------------------------ +if(evento->key()==Qt::Key_I) +{ - } - if (letra=='S') - { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + coaliciones('I', personaje2); +} +if(evento->key()==Qt::Key_J) +{ + coaliciones('J', personaje2); - //---------------------------GIRO DE PERSONAJE 1(S)--------------------------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(90); - personaje1->bajar(); +} +if(evento->key()==Qt::Key_L) +{ - //------------------------------COALISIONES 1(S)----------------------------- - if(personaje1->collidesWithItem(bolaH)) - { - bolaH->bajar(); - } - if(personaje1->collidesWithItem(enemigo1)) + coaliciones('L', personaje2); +} +if(evento->key()==Qt::Key_K) +{ - { + coaliciones('K', personaje2); - x = enemigo1->x(); - y = enemigo1->y(); - vida->decrease(); - resorte('S', personaje1); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); +} +teletransportacion(); +/*if (evento->key()==Qt::Key_7) + { + clean(); + opcion=7; + niveles(opcion); + }*/ + } - timer->start(30); - } - /*for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - } - } - */ - //-----------------------EVALUAR COALISIONES CON MUROS 1(S)---------------- +if (opcion==7) +{ - for (int i=0;icollidesWithItem(muros.at(i))) - { - personaje1->subir(); - } + + if(evento->key()==Qt::Key_A) + { + coaliciones('A', personaje1); + } + + else if(evento->key()==Qt::Key_D) + { + + coaliciones('D', personaje1); + + } + else if(evento->key()==Qt::Key_W) + { + + coaliciones('W', personaje1); + + } + + else if(evento->key()==Qt::Key_S) + { + + coaliciones('S', personaje1); + } + + + //---------------------------------------------EVENTO PERSONAJE 2 NIVEL 6------------------------------------------------------------ + + if(evento->key()==Qt::Key_I) + { + + coaliciones('I', personaje2); + + } + if(evento->key()==Qt::Key_J) + { + coaliciones('J', personaje2); + + + } + if(evento->key()==Qt::Key_L) + { + + coaliciones('L', personaje2); + + } + if(evento->key()==Qt::Key_K) + { + + coaliciones('K', personaje2); + + } + +teletransportacion(); + +} + +if(evento->key()==Qt::Key_0) +{ + guardarPartida(); +} + +if(evento->key()==Qt::Key_1) +{ + clean(); + opcion=1; + niveles (opcion); +} +if(evento->key()==Qt::Key_2) +{ + clean(); + opcion=2; + niveles (opcion); +} +if(evento->key()==Qt::Key_3) +{ + clean(); + opcion=3; + niveles (opcion); +} +if(evento->key()==Qt::Key_4) +{ + clean(); + opcion=4; + niveles (opcion); +} +if(evento->key()==Qt::Key_5) +{ + clean(); + opcion=5; + niveles (opcion); +} +if(evento->key()==Qt::Key_6) +{ + clean(); + opcion=6; + niveles (opcion); +} +if(evento->key()==Qt::Key_7) +{ + clean(); + opcion=7; + niveles (opcion); +} +} + +void MainWindow::coaliciones(char letra , Personaje *personaje) +{ + + + + if (personaje==personaje1) + { + + + + if (letra=='A') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + //---------------------------GIRO DEL PERSONAJE1 (A)------------------------------ + + personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(180); + personaje1->izquierda(); + + + //------------------------------COALISIONES1 (A) ---------------------------- + + if(personaje1->collidesWithItem(bolaH)) + { + bolaH->izquierda(); + } + if(personaje1->collidesWithItem(enemigo1)) + + { + resorte('A', personaje1); + x = enemigo1->x(); + y = enemigo1->y(); + vida->decrease(); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } + //------------------------EVALUAR COALISIONES CON MUROS 1(A)------------------ + + for (int i=0;iisVisible()) + { + if (personaje1->collidesWithItem(muros.at(i))) + { + + personaje1->derecha(); + } + } + } + + + + //--------------------EVALUAR COALISIONES CON PIEDRAS 1(A)-------------------- + + for (int i=0;iisVisible()) + { + if (personaje1->collidesWithItem(piedras.at(i))) + { + + personaje1->derecha(); + } + } + } + + //--------------------------CAPTURAR LLAVES 1(A)------------------------------- + if(llave->isVisible()) + { + if (personaje1->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } + + //--------------------------PUERTA 1(A)------------------------------------------- + /*if (personaje1->collidesWithItem(puerta)) + { + + personaje1->derecha(); + //remover escena + } + + + + + + */ + } + if (letra=='D') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + //--------------------------GIRO DEL PERSONAJE 1(D)--------------- + personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(0); + personaje1->derecha(); + + //---------------------------COALISIONES 1(D)---------------------------- + + if(personaje1->collidesWithItem(bolaH)) + + { + bolaH->derecha(); + } + if(personaje1->collidesWithItem(enemigo1)) + + { + resorte('D', personaje1); + x = enemigo1->x(); + y = enemigo1->y(); + vida->decrease(); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } + //----------------------EVALUAR COALISIONES CON MUROS 1(D)------------------ + for (int i=0;iisVisible()) + { + if (personaje1->collidesWithItem(muros.at(i))) + { + + + + personaje1->izquierda(); + } + } + } + //----------------------EVALUAR COALISIONES CON PIEDRAS 1(D)---------------------- + + for (int i=0;iisVisible()) + { + if (personaje1->collidesWithItem(piedras.at(i))) + { + + personaje1->izquierda(); + } + } + } + + //----------------------------CAPTURAR LLAVES 1(D)---------------------------------- + if(llave->isVisible()) + { + if (personaje1->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } + + //--------------------------PUERTA 1(D)------------------------------ + /*if (personaje1->collidesWithItem(puerta)) + { + personaje1->izquierda(); + //remover escena + } + */ + } + if (letra=='W') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + + //-------------------------GIRO DE PERSONAJE 1(W)----------------------- + personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(270); + personaje1->subir(); + + + //----------------------------COALISIONES 1(W)-------------------------------- + + if(personaje1->collidesWithItem(bolaH)) + { + bolaH->subir(); + } + if(personaje1->collidesWithItem(enemigo1)) + { + resorte('W', personaje1); + + + x = enemigo1->x(); + y = enemigo1->y(); + vida->decrease(); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } + //----------------EVALUAR COALISIONES CON MUROS 1(W))----------------------- + for (int i=0;iisVisible()) + { + if (personaje1->collidesWithItem(muros.at(i))) + { + + + personaje1->bajar(); + } + } + } + //-------------------EVALUAR COALISIONES CON PIEDRAS 1(W)--------------------- + + for (int i=0;iisVisible()) + { + if (personaje1->collidesWithItem(piedras.at(i))) + { + + personaje1->bajar(); + } + } + } + + //-----------------------------CAPTURAR LLAVES 1(W)---------------------------- + if(llave->isVisible()) + { + if (personaje1->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } + + //-----------------------------------PUERTA 1(W)------------------------------- + /*if (personaje1->collidesWithItem(puerta)) + { + personaje1->bajar(); + //remover escena + } + + */ + } + if (letra=='S') + { + //lanzamiento(-40,personaje1->x(),70,personaje1->y()); + + + //---------------------------GIRO DE PERSONAJE 1(S)--------------------------- + personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(90); + personaje1->bajar(); + + + //------------------------------COALISIONES 1(S)----------------------------- + if(personaje1->collidesWithItem(bolaH)) + { + bolaH->bajar(); + } + if(personaje1->collidesWithItem(enemigo1)) + + + { + + x = enemigo1->x(); + y = enemigo1->y(); + vida->decrease(); + resorte('S', personaje1); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); + + timer->start(30); + } + //-----------------------EVALUAR COALISIONES CON MUROS 1(S)---------------- + + for (int i=0;iisVisible()) + { + if (personaje1->collidesWithItem(muros.at(i))) + { + + personaje1->subir(); + } + } } //----------------------EVALUAR COALISIONES CON PIEDRAS 1(S)--------------- for (int i=0;iisVisible()) { if (personaje1->collidesWithItem(piedras.at(i))) { @@ -583,38 +876,39 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) personaje1->subir(); } } + } //--------------------------CAPTURAR LLAVES 1(S)------------------------- if(llave->isVisible()) - {if (personaje1->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); - keys->increase(); - llave->hide(); - //delete (llave); + {if (personaje1->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); - } - } + } + } //-------------------------PUERTA 1(S)----------------------------------- - + /* if (personaje1->collidesWithItem(puerta)) { personaje1->subir(); //remover escena } + */ + } } - } - if (personaje==personaje2) { @@ -635,28 +929,21 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { bolaH->subir(); } + if(personaje2->collidesWithItem(enemigo1)) - { - resorte('I', personaje2); + { + resorte('I', personaje2); - x = enemigo1->x(); - y = enemigo1->y(); - vida->decrease(); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); + x = enemigo1->x(); + y = enemigo1->y(); + vida->decrease(); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); - timer->start(30); - } - /*for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - } - }*/ + timer->start(30); + } //-----------------------------EVALUAR COALISIONES CON MUROS 2(I)------------------ for (int i=0;iisVisible()) - {if (personaje2->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); - keys->increase(); - llave->hide(); - //delete (llave); + {if (personaje2->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } - } - } //------------------------------------PUERTA 2(I)---------------------------------- - if (personaje2->collidesWithItem(puerta)) + /*if (personaje2->collidesWithItem(puerta)) { personaje2->bajar(); //remover escena } - + */ } @@ -718,26 +1007,19 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { bolaH->izquierda(); } + if(personaje2->collidesWithItem(enemigo1)) - { - resorte('J', personaje2); - x = enemigo1->x(); - y = enemigo1->y(); - vida->decrease(); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); + { + resorte('J', personaje2); + x = enemigo1->x(); + y = enemigo1->y(); + vida->decrease(); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); - timer->start(30); - } - /*for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - } - }*/ + timer->start(30); + } //-----------------------EVALUAR COALISIONES CON MUROS 2(J)--------------------- for (int i=0;iisVisible()) - {if (personaje2->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); - keys->increase(); - llave->hide(); - //delete (llave); + {if (personaje2->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } - } - } //----------------------------------PUERTA 2(J)------------------------------- - if (personaje2->collidesWithItem(puerta)) + /*if (personaje2->collidesWithItem(puerta)) { personaje2->derecha(); //remover escena } - + */ @@ -806,28 +1090,20 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { bolaH->derecha(); } + if(personaje2->collidesWithItem(enemigo1)) - { - x = enemigo1->x(); - y = enemigo1->y(); - resorte('L', personaje2); - vida->decrease(); - //bolaFuego->setPosx(personaje1->pos()); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); + { + x = enemigo1->x(); + y = enemigo1->y(); + resorte('L', personaje2); + vida->decrease(); + //bolaFuego->setPosx(personaje1->pos()); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); - timer->start(30); - } - /* - for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - } - }*/ + timer->start(30); + } //------------------------EVALUAR COALISIONES CON MUROS 2(L)-------------------------- for (int i=0;iisVisible()) - {if (personaje2->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); - keys->increase(); - llave->hide(); - //delete (llave); + {if (personaje2->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } - } - } //-------------------------------------PUERTA 2(L)----------------------------- - if (personaje2->collidesWithItem(puerta)) + /*if (personaje2->collidesWithItem(puerta)) { personaje2->izquierda(); //remover escena } + */ } @@ -888,29 +1167,21 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { bolaH->bajar(); } + if(personaje2->collidesWithItem(enemigo1)) - { + { - x = enemigo1->x(); - y = enemigo1->y(); - vida->decrease(); - resorte('K', personaje2); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); + x = enemigo1->x(); + y = enemigo1->y(); + vida->decrease(); + resorte('K', personaje2); + //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); + //scene->addItem(cuerpos.back()); - timer->start(30); - } - /*for (int i=0;icollidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - } - } - */ + timer->start(30); + } //--------------------------EVALUAR COALISIONES CON MUROS 2(K)-------------------------- for (int i=0;iisVisible()) - {if (personaje2->collidesWithItem(llave)) - { - //key->play(); - scene->removeItem(llave); - keys->increase(); - llave->hide(); - //delete (llave); + {if (personaje2->collidesWithItem(llave)) + { + //key->play(); + scene->removeItem(llave); + keys->increase(); + llave->hide(); + //delete (llave); + + } + } - } - } //------------------------------PUERTA 2(K)------------------------------------------ - if (personaje2->collidesWithItem(puerta)) + /*if (personaje2->collidesWithItem(puerta)) { personaje2->subir(); //remover escena } - + */ @@ -964,6 +1236,9 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) + + + //------------------------------------------------------NIVELES-------------------------------------------------- @@ -972,7 +1247,43 @@ void MainWindow::botonInicio() opcion=1; niveles(opcion); } +void MainWindow::continuar() +{ + + QString l; + QFile archivo("PARTIDA.txt"); + QTextStream datosArchivo(&archivo); + if (!archivo.exists()) + { + qDebug()<<" EL ARCHIVO SELECCIONADO NO EXISTE "; + + } + if(archivo.open(QIODevice::ReadOnly | QIODevice::Text)) + { + if (!archivo.isOpen()) + { + qDebug()<<" EL ARCHIVO NO SE HA PODIDO ABRIR "; + + } + l=archivo.readAll(); + qDebug()<setMovie(movie); movie->start();*/ - scene->setBackgroundBrush(QPixmap(":/IMAGENES/MAINMENU.png")); + scene->setBackgroundBrush(QPixmap(":/I/I/MAINMENU.png")); scene->setSceneRect(0,0,790,550); - intro=new QMediaPlayer (); - intro->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/fantasy.mp3")); + //intro=new QMediaPlayer (); + //intro->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/fantasy.mp3")); //intro->play(); @@ -1007,230 +1318,533 @@ void MainWindow:: niveles(int opcion) { + + //intro->stop(); + //key=new QMediaPlayer (); + //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + + timer= new QTimer; + connect(timer,SIGNAL(timeout()), this, SLOT (mover())); + QTimer *cronometro = new QTimer(this); + connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); + cronometro->start(10000); + /*QTimer *cronometro2 = new QTimer(this); + connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); + cronometro2->start(1000);*/ + + + //CREANDO LA ESCENA + ui->setupUi(this); + scene = new QGraphicsScene; + ui->graphicsView->setScene(scene); + //scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + scene->setSceneRect(0,0,400,400); + + personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + scene->addItem(personaje1); + + personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + scene->addItem(personaje2); + + llave= new Objeto (470,35,30,":/I/I/llave1.png"); + scene->addItem(llave); + + enemigo1= new Personaje (-105,310,60,1,":/I/I/ENEMIGO.png"); //antes -105, 310 + scene->addItem(enemigo1); + + timerEnem= new QTimer; + timerEnem->stop(); + connect(timerEnem, SIGNAL(timeout()), this , SLOT (moverEnemigo())); + timerEnem->start(9000); + + rigidez=10; + aceleracion=150; + + vida=new vidas(); + vida->setPos(120,35); + scene->addItem(vida); + keys=new llaves(); + keys->setPos(270,35); + scene->addItem(keys); + + items(); + + teletransportacion(); + + + } + if (opcion==2) + { + + + + //intro->stop(); + //key=new QMediaPlayer (); + //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + + timer= new QTimer; + connect(timer,SIGNAL(timeout()), this, SLOT (mover())); + QTimer *cronometro = new QTimer(this); + connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); + cronometro->start(1000); + + QTimer *cronometro2 = new QTimer(this); + connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); + cronometro2->start(1000); + + + //CREANDO LA ESCENA + ui->setupUi(this); + scene = new QGraphicsScene; + ui->graphicsView->setScene(scene); + scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + scene->setSceneRect(0,0,400,400); + + personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + scene->addItem(personaje1); + + personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + scene->addItem(personaje2); + + llave= new Objeto (470,35,30,":/I/I/llave1.png"); + scene->addItem(llave); + + enemigo1= new Personaje (-135,415,60,1.5,":/I/I/ENEMIGO.png"); + scene->addItem(enemigo1); + + + rigidez=11; + aceleracion=160; + + items(); + + teletransportacion(); + + } + if (opcion==3) + { + + + + + //intro->stop(); + //key=new QMediaPlayer (); + //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + + timer= new QTimer; + connect(timer,SIGNAL(timeout()), this, SLOT (mover())); + QTimer *cronometro = new QTimer(this); + connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); + cronometro->start(1000); + + /*QTimer *cronometro2 = new QTimer(this); + connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); + cronometro2->start(1000);*/ + + + //CREANDO LA ESCENA + ui->setupUi(this); + scene = new QGraphicsScene; + ui->graphicsView->setScene(scene); + scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + scene->setSceneRect(0,0,400,400); + + personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + scene->addItem(personaje1); + + personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + scene->addItem(personaje2); + + llave= new Objeto (470,35,30,":/I/I/llave1.png"); + scene->addItem(llave); + + enemigo1= new Personaje (395,210,60,1.5,":/I/I/SERPIENTE1(1).png"); + scene->addItem(enemigo1); + + totem= new Personaje (0,0,60 ,1, ":/I/I/TOTEMARENA.png"); + scene->addItem(totem); + timer->start(); + + rigidez=12; + aceleracion=170; + + items(); + + teletransportacion(); + + + + } + if (opcion==4) + { + //intro->stop(); + //key=new QMediaPlayer (); + //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + + timer= new QTimer; + connect(timer,SIGNAL(timeout()), this, SLOT (mover())); + QTimer *cronometro = new QTimer(this); + connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); + cronometro->start(1000); + + QTimer *cronometro2 = new QTimer(this); + connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); + cronometro2->start(1000); + + //CREANDO LA ESCENA + ui->setupUi(this); + scene = new QGraphicsScene; + ui->graphicsView->setScene(scene); + scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + scene->setSceneRect(0,0,400,400); + + personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + scene->addItem(personaje1); + + personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + scene->addItem(personaje2); + + llave= new Objeto (470,35,30,":/I/I/llave1.png"); + scene->addItem(llave); + + items(); + + teletransportacion(); + + } + if (opcion==5) + { + + //intro->stop(); + //key=new QMediaPlayer (); + //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + + timer= new QTimer; + connect(timer,SIGNAL(timeout()), this, SLOT (mover())); + QTimer *cronometro = new QTimer(this); + connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); + cronometro->start(1000); + + QTimer *cronometro2 = new QTimer(this); + connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); + cronometro2->start(1000); + + //CREANDO LA ESCENA + ui->setupUi(this); + scene = new QGraphicsScene; + ui->graphicsView->setScene(scene); + scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + scene->setSceneRect(0,0,400,400); + + personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + scene->addItem(personaje1); + + personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + scene->addItem(personaje2); + + llave= new Objeto (470,35,30,":/I/I/llave1.png"); + scene->addItem(llave); + + items(); + + teletransportacion(); + + + } + if (opcion==6) + { + //intro->stop(); + //key=new QMediaPlayer (); + //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + + timer= new QTimer; + connect(timer,SIGNAL(timeout()), this, SLOT (mover())); + QTimer *cronometro = new QTimer(this); + connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); + cronometro->start(1000); + + QTimer *cronometro2 = new QTimer(this); + connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); + cronometro2->start(1000); + + //CREANDO LA ESCENA + ui->setupUi(this); + scene = new QGraphicsScene; + ui->graphicsView->setScene(scene); + scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + scene->setSceneRect(0,0,400,400); + + personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + scene->addItem(personaje1); + + personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + scene->addItem(personaje2); + + llave= new Objeto (470,35,30,":/I/I/llave1.png"); + scene->addItem(llave); + + items(); + + teletransportacion(); + + } + if (opcion==7) + { //intro->stop(); - key=new QMediaPlayer (); - key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + //key=new QMediaPlayer (); + //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); timer= new QTimer; connect(timer,SIGNAL(timeout()), this, SLOT (mover())); QTimer *cronometro = new QTimer(this); connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); - cronometro->start(10000); + cronometro->start(1000); - /* QTimer *cronometro2 = new QTimer(this); - connect(cronometro2, SIGNAL(timeout()),this,SLOT(magnetismo())); - cronometro2->start(1000);*/ + QTimer *cronometro2 = new QTimer(this); + connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); + cronometro2->start(1000); - /* parabolico= new QTimer; - parabolico->stop(); - connect(parabolico,SIGNAL(timeout()),this,SLOT(Mover())); - parabolico->start(40);*/ //CREANDO LA ESCENA ui->setupUi(this); scene = new QGraphicsScene; ui->graphicsView->setScene(scene); - scene->setBackgroundBrush(QPixmap(":/IMAGENES/PisoPiedra.jpg")); + scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); + personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + scene->addItem(personaje1); + personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + scene->addItem(personaje2); - //x,y ,r,friccion,a,v,ang,path - personaje1=new Personaje(495,410,30,1, ":/IMAGENES/PERSONAJE1.png"); - scene->addItem(personaje1); + llave= new Objeto (470,35,30,":/I/I/llave1.png"); + scene->addItem(llave); - personaje2=new Personaje(0,0,45,1, ":/IMAGENES/PERSONAJE2.png"); - scene->addItem(personaje2); + items(); - enemigo1= new Personaje (-105,310 - ,60,1,":/IMAGENES/ENEMIGO.png"); //antes -105, 310 - scene->addItem(enemigo1); + teletransportacion(); - timerEnem= new QTimer; - timerEnem->stop(); - connect(timerEnem, SIGNAL(timeout()), this , SLOT (moverEnemigo())); - timerEnem->start(9000); + } +} - rigidez=10; - aceleracion=150; +void MainWindow::items() +{ - vida=new vidas(); - vida->setPos(120,35); - scene->addItem(vida); - keys=new llaves(); - keys->setPos(270,35); - scene->addItem(keys); - //particula1=new Particula( -105,310,0,0,50000,200, ":/IMAGENES/BOLADEMETAL.png "); - //particula2=new Particula(-5000,0,0,0,70,70 ,":/IMAGENES/BOLA DE FUEGO.png "); + /* llave= new Objeto (470,35,30,":/IMAGENES/llave1.png"); + scene->addItem(llave);*/ + bolaH= new Objeto (75,160, 30,":/I/I/BOLADEMETAL.png"); + scene->addItem(bolaH); - /* disparo=new QTimer; - disparo->stop(); - connect(disparo, SIGNAL(timeout()), this , SLOT (lanzamiento)); - disparo->start(1000);*/ + muros.push_back(new Pared (200,-450,800,100, "")); + scene->addItem(muros.back()); + muros.push_back(new Pared (200,150,800,100, "")); + scene->addItem(muros.back()); + muros.push_back(new Pared (250,100,100,800, "")); + scene->addItem(muros.back()); + muros.push_back(new Pared (-550,100,100,800, "")); + scene->addItem(muros.back()); + if (opcion==1) + { + piedras.push_back(new Objeto(-120,305,40,":/I/I/P1.png")); + scene->addItem(piedras.back()); + piedras.push_back(new Objeto(-30,275,40,":/I/I/P1.png")); + scene->addItem(piedras.back()); + piedras.push_back(new Objeto(-10,180,40,":/I/I/P1.png")); + scene->addItem(piedras.back()); + piedras.push_back(new Objeto(-50,105,40,":/I/I/P1.png")); + scene->addItem(piedras.back()); + piedras.push_back(new Objeto(-120,85,40,":/I/I/P1.png")); + scene->addItem(piedras.back()); - items(); + muros.push_back(new Pared (-350,50,50,800, ":/I/I/rocas2.png")); //muro vertical + scene->addItem(muros.back()); + muros.push_back(new Pared (-120,50,20,50, ":/I/I/BLOQUE.jpg")); //abajo derecha conexion nivel 1 + scene->addItem(muros.back()); + muros.push_back(new Pared (-200,50,20,50, ":/I/I/BLOQUE.jpg")); //abajo izqu conexion nivel 1 + scene->addItem(muros.back()); + muros.push_back(new Pared (-500,-10,50,30, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 4 ancho alto + scene->addItem(muros.back()); } + if (opcion==2) { - timer->stop(); - clean(); - //CREANDO LA ESCENA - ui->setupUi(this); - scene = new QGraphicsScene; - ui->graphicsView->setScene(scene); - scene->setBackgroundBrush(QPixmap(":/IMAGENES/black_stone.jpg")); - scene->setSceneRect(0,0,400,400); - timer= new QTimer; - connect(timer,SIGNAL(timeout()), this, SLOT (mover())); - QTimer *cronometro = new QTimer(this); - connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); - cronometro->start(10000); - /* parabolico= new QTimer; - parabolico->stop(); - connect(parabolico,SIGNAL(timeout()),this,SLOT(Mover())); - parabolico->start(40); - QTimer *cronometro2 = new QTimer(this); - connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); - cronometro2->start(1000);*/ - timer->start(); //x,y ,r,friccion,a,v,ang,path - personaje1=new Personaje(495,410,30,1.5,":/IMAGENES/PERSONAJE1.png"); - scene->addItem(personaje1); + muros.push_back(new Pared (-120,50,20,50, ":/I/I/BLOQUE.jpg")); //arriba conex nivel 7 + scene->addItem(muros.back()); - enemigo1= new Personaje (-135,415,60,1.5,":/IMAGENES/ENEMIGO.png"); - scene->addItem(enemigo1); + muros.push_back(new Pared (-200,50,20,50, ":/I/I/BLOQUE.jpg")); //arriba izq conex nivel 7 + scene->addItem(muros.back()); + muros.push_back(new Pared (90,-400,20,50, ":/I/I/BLOQUE.jpg")); //abajo izqu //-200 + scene->addItem(muros.back()); - rigidez=11; - aceleracion=160; + muros.push_back(new Pared (-500,-150,50,20, ":/I/I/BLOQUE.jpg")); //derecha arriba + scene->addItem(muros.back()); + + muros.push_back(new Pared (-500,-230,50,20, ":/I/I/BLOQUE.jpg")); //derecha abajo + scene->addItem(muros.back()); + } + if (opcion==3) + { + muros.push_back(new Pared (150,-160,50,30, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 5 arriba ancho alto + scene->addItem(muros.back()); + muros.push_back(new Pared (150,-250,50,30, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 5 abajo ancho alto + scene->addItem(muros.back()); + muros.push_back(new Pared (-420,-400,30,50, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 4 izqu abajo ancho alto + scene->addItem(muros.back()); + muros.push_back(new Pared (-520,-400,30,50, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 4 derecha abajo ancho alto + scene->addItem(muros.back()); + muros.push_back(new Pared (-50,-150,200,50, ":/I/I/BLOQUE.jpg")); //muro centro arriba + scene->addItem(muros.back()); - items(); + muros.push_back(new Pared (-50,-150,50,300, ":/I/I/BLOQUE.jpg")); //muro centro izquierda + scene->addItem(muros.back()); + muros.push_back(new Pared (-250,-150,50,150, ":/I/I/BLOQUE.jpg")); //muro centro derecha + scene->addItem(muros.back()); } - if (opcion==3) + + if (opcion==4) { - timer->stop(); - clean(); - //CREANDO LA ESCENA - ui->setupUi(this); - scene = new QGraphicsScene; - ui->graphicsView->setScene(scene); - scene->setBackgroundBrush(QPixmap(":/IMAGENES/ARENA.jpg")); - scene->setSceneRect(0,0,400,400); + //_------ muros extra + muros.push_back(new Pared (-100,-300,50,200, ":/I/I/BLOQUE.jpg")); //VERTICAL ABAJO + scene->addItem(muros.back()); - timer= new QTimer; - connect(timer,SIGNAL(timeout()), this, SLOT (mover())); - QTimer *cronometro = new QTimer(this); - connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); - cronometro->start(10000); - /* parabolico= new QTimer; - parabolico->stop(); - connect(parabolico,SIGNAL(timeout()),this,SLOT(Mover())); - parabolico->start(40); - QTimer *cronometro2 = new QTimer(this); - connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); - cronometro2->start(1000);*/ - timer->start(); //x,y ,r,friccion,a,v,ang,path - personaje1=new Personaje(495,410,30,1.2, ":/IMAGENES/PERSONAJE1.png"); - scene->addItem(personaje1); + //muros.push_back(new Pared (150,-300,300,50, ":/IMAGENES/BLOQUE.jpg")); //HORIZONTAL ABAJO + //scene->addItem(muros.back()); - enemigo1= new Personaje (395,210,60,1.5,":/IMAGENES/SERPIENTE1(1).png"); - scene->addItem(enemigo1); - totem= new Personaje (0,0,60 ,1, ":/IMAGENES/TOTEMARENA.png"); - scene->addItem(totem); - timer->start(); + //muros puertas - rigidez=12; - aceleracion=170; - items(); + muros.push_back(new Pared (150,-10,50,30, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 1 ancho alto + scene->addItem(muros.back()); + + muros.push_back(new Pared (-220,50,30,50, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 3 + scene->addItem(muros.back()); } -} + if (opcion==5) + { -void MainWindow::items() -{ + /* muros.push_back(new Pared (0,200,50,400, ":/IMAGENES/BLOQUE.jpg")); //centro derecha conexion nivel 7 + scene->addItem(muros.back()); + muros.push_back(new Pared (-320,200,50,400, ":/IMAGENES/BLOQUE.jpg")); //centro izquierda conexion nivel 7 + scene->addItem(muros.back());*/ + muros.push_back(new Pared (-120,-400,20,50, ":/I/I/BLOQUE.jpg")); //abajo derecha conexion nivel 1 + scene->addItem(muros.back()); - llave= new Objeto (415,360,30,":/IMAGENES/llave1.png"); - scene->addItem(llave); + muros.push_back(new Pared (-200,-400,20,50, ":/I/I/BLOQUE.jpg")); //abajo izqu conexion nivel 1 + scene->addItem(muros.back()); - bolaH= new Objeto (75,160, 30,":/IMAGENES/BOLADEMETAL.png"); - scene->addItem(bolaH); + muros.push_back(new Pared (150,-160,50,30, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 2 arriba ancho alto conex n 2 + scene->addItem(muros.back()); - puerta=new Objeto(465,25, 80,":/IMAGENES/Door1.png" ); - scene->addItem(puerta); + muros.push_back(new Pared (150,-250,50,30, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 3 abajo ancho alto conex nivel 2 + scene->addItem(muros.back()); + muros.push_back(new Pared (-500,-150,50,20, ":/I/I/BLOQUE.jpg")); //derecha arriba conex nivel 3 + scene->addItem(muros.back()); - muros.push_back(new Pared (200,-450,800,100, ":/IMAGENES/BLOQUE.jpg")); - scene->addItem(muros.back()); + muros.push_back(new Pared (-500,-230,50,20, ":/I/I/BLOQUE.jpg")); //derecha abajo conex nivel 3 + scene->addItem(muros.back()); - muros.push_back(new Pared (200,150,800,100, ":/IMAGENES/BLOQUE.jpg")); - scene->addItem(muros.back()); - muros.push_back(new Pared (250,100,100,800, ":/IMAGENES/BLOQUE.jpg")); - scene->addItem(muros.back()); - muros.push_back(new Pared (-550,100,100,800, ":/IMAGENES/BLOQUE.jpg")); - scene->addItem(muros.back()); + //muros.push_back(new Pared (0,200,50,800, ":/IMAGENES/BLOQUE.jpg")); + //scene->addItem(muros.back()); + + } + + if (opcion==6) + { + muros.push_back(new Pared (30,200,50,400, ":/I/I/BLOQUE.jpg")); //centro derecha conexion nivel 7 + scene->addItem(muros.back()); + + muros.push_back(new Pared (-370,200,50,400, ":/I/I/BLOQUE.jpg")); //centro izquierda conexion nivel 7 + scene->addItem(muros.back()); + + muros.push_back(new Pared (-170,-200,50,400, ":/I/BLOQUE.jpg")); //centro izquierda conexion nivel 7 + scene->addItem(muros.back()); + + muros.push_back(new Pared (-500,-200,50,20, ":/I/I/BLOQUE.jpg")); //derecha arriba conex nivel 1 + scene->addItem(muros.back()); + + muros.push_back(new Pared (-500,-280,50,20, ":/I/I/BLOQUE.jpg")); //derecha abajo conex nivel 1 + scene->addItem(muros.back()); + + + muros.push_back(new Pared (85,50,30,50, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 2 + scene->addItem(muros.back()); + + boton=new Objeto(255,420,40,""); + } + + if (opcion==7) + { + muros.push_back(new Pared (200,-200,800,50, ":/I/I/rocas2.png")); //muro centro + scene->addItem(muros.back()); + + muros.push_back(new Pared (85,-400,30,50, ":/I/I/BLOQUE.jpg")); //puerta abajo conexion nivel 2 + scene->addItem(muros.back()); + + muros.push_back(new Pared (150,-0,50,30, ":/I/I/BLOQUE.jpg")); //puerta final + scene->addItem(muros.back()); + muros.push_back(new Pared (150,-90,50,30, ":/I/I/BLOQUE.jpg")); //Puerta final + scene->addItem(muros.back()); - piedras.push_back(new Objeto(135,110,40,":/IMAGENES/rocas2.png")); - scene->addItem(piedras.back()); - piedras.push_back(new Objeto(280,220,40,":/IMAGENES/rocas2.png")); - scene->addItem(piedras.back()); - piedras.push_back(new Objeto(275,115,40,":/IMAGENES/rocas2.png")); - scene->addItem(piedras.back()); - piedras.push_back(new Objeto(140,220,40,":/IMAGENES/rocas2.png")); - scene->addItem(piedras.back()); - piedras.push_back(new Objeto(135,170,40,":/IMAGENES/rocas2.png")); - scene->addItem(piedras.back()); - piedras.push_back(new Objeto(205,110,40,":/IMAGENES/rocas2.png")); - scene->addItem(piedras.back()); - piedras.push_back(new Objeto(275,160,40,":/IMAGENES/rocas2.png")); - scene->addItem(piedras.back()); + muros.push_back(new Pared (-500,-10,50,20, ":/I/I/BLOQUE.jpg")); //puerta segunda parte derecha (arriba) + scene->addItem(muros.back()); - dragon=new Sprite (); - dragon->setPos(110,345); - scene->addItem(dragon); + muros.push_back(new Pared (-500,-90,50,20, ":/I/I/BLOQUE.jpg")); //puerta segunda parte derecha (abajo) + scene->addItem(muros.back()); + muros.push_back(new Pared (-500,-310,50,20, ":/I/I/BLOQUE.jpg")); //puerta primera parte derecha (arriba) + scene->addItem(muros.back()); + + muros.push_back(new Pared (-500,-390,50,20, ":/I/I/BLOQUE.jpg")); //puerta primera parte derecha (abajo) + scene->addItem(muros.back()); + } } void MainWindow::clean() { - scene->removeItem(enemigo1); + /*scene->removeItem(enemigo1); delete (enemigo1); scene->removeItem(personaje1); delete (personaje1); - /*for (int i=0;ihide(); scene->removeItem(cuerpos.at(i)); + delete (cuerpos.at (i)); cuerpos.removeOne(cuerpos.at(i)); @@ -1239,26 +1853,200 @@ void MainWindow::clean() }*/ for (int i=0;iremoveItem(piedras.at(i)); - delete (piedras.at (i)); - piedras.removeOne(piedras.at(i)); + // scene->removeItem(piedras.at(i)); + piedras.at(i)->hide(); + //delete (piedras.at (i)); + // piedras.removeOne(piedras.at(i)); + + + } + + for (int i=0;ihide(); + //scene->removeItem(muros.at(i)); + + //delete (muros.at (i)); + //muros.removeOne(muros.at(i)); } + /*scene->removeItem(puerta); + delete (puerta);*/ + +} + +void MainWindow::teletransportacion() +{ + if (opcion==1) + { + if (personaje1->x()==170 and personaje1->y()==-20) //puerta arriba //conexion nivel 5 + { + clean(); + opcion=5; + niveles(opcion); + personaje1->setPos(170,345); + } + + if (personaje1->x()==520 and personaje1->y()==-20) //puerta arriba //conexion nivel 4 + { + clean(); + opcion=4; + niveles(opcion); + personaje1->setPos(-80,-20); + } + + } + if (opcion==2) + { + + if (personaje1->x()==170 and personaje1->y()==-20) //puerta arriba //conexion nivel 7 + { + clean(); + opcion=7; + niveles(opcion); + } + if (personaje1->x()==520 and personaje1->y()==200) //puerta izquierda //conexion nivel 5 + { + clean(); + opcion=5; + niveles(opcion); + personaje1->setPos(-65,215); + } + if (personaje1->x()==-120 and personaje1->y()==420) //puerta abajo //conexion nivel 1 + { + clean(); + opcion=6; + niveles(opcion); + personaje1->setPos(-120,25); + } + /*if (personaje1->x()==520 and personaje1->y()==200) //puerta derecha //conexion nivel 3 + { + clean(); + opcion=3; + niveles(opcion); + }*/ + } + if (opcion==3) + { + + if (personaje1->x()==-115 and personaje1->y()==220) //puerta izquierda //conexion nivel 5 + { + clean(); + opcion=5; + niveles(opcion); + personaje1->setPos(455,205); + } + if (personaje1->x()==485 and personaje1->y()==420) //puerta izquierda //conexion nivel 4 + { + clean(); + opcion=4; + niveles(opcion); + personaje1->setPos(280,20); + } + + } + + if (opcion==4) + { + + if (personaje1->x()==-115 and personaje1->y()==-20) //puerta izquierda //conexion nivel 1 + { + clean(); + opcion=1; + niveles(opcion); + personaje1->setPos(515,-20); + + } + if (personaje1->x()==280 and personaje1->y()==-20) //puerta arriba //conexion nivel 3 + { + clean(); + opcion=3; + niveles(opcion); + personaje1->setPos(475,360); + + } + + } + + if (opcion==5) + { + + if (personaje1->x()==170 and personaje1->y()==415) //puerta abajo//conexion nivel 1 + { + clean(); + opcion=1; + niveles(opcion); + personaje1->setPos(155,45); + + } + if (personaje1->x()==520 and personaje1->y()==200) //puerta derecha//conexion nivel 3 + { + clean(); + opcion=3; + niveles(opcion); + personaje1->setPos(-70,220); + + } + if (personaje1->x()==-120 and personaje1->y()==220) //puerta izquierda //conexion nivel 2 + { + clean(); + opcion=2; + niveles(opcion); + personaje1->setPos(460,205); + + } + + + } + if (opcion==6) + { + + if (personaje1->x()==515 and personaje1->y()==250) //puerta derecha conex nivel 1 + { + clean(); + opcion=1; + niveles(opcion); + //personaje1->setPos(515,-20); + + } + if (personaje1->x()==-120 and personaje1->y()==-15) //puerta arriba //conexion nivel 2 + { + clean(); + opcion=2; + niveles(opcion); + personaje1->setPos(-115,355); + + } + } + if (opcion==7) + { + if (personaje1->x()==520 and personaje1->y()==360) //puerta derecha conex nivel 1 + { + + clean(); + personaje1->setPos(520,60); + + } - scene->removeItem(puerta); - delete (puerta); + } + } + void MainWindow::guardarPartida() { - QFile archivo("PLANETAS.txt"); + QString level, R; + + + level=QString::number(opcion); + QFile archivo("PARTIDA.txt"); if(archivo.open(QIODevice::Append | QIODevice::Text)){ QTextStream datosArchivo(&archivo); - //datosArchivo << text<< endl; + datosArchivo << level<< endl; } archivo.close(); @@ -1268,11 +2056,6 @@ void MainWindow::guardarPartida() //--------------------------------------------------FISICAS-------------------------------------------------- -void MainWindow::CoeficienteRestitucion() -{ - -} - void MainWindow:: lanzamiento () { @@ -1280,49 +2063,34 @@ void MainWindow:: lanzamiento () int xfinal=personaje1->x(); int yinicial=0; int yfinal=personaje1->y(); - while ((xinicial!=xfinal) or (yinicial!=yfinal)) { - if (xinicialyfinal) { yinicial--; - } - path++; } //cout<<" PATH: "<<"( "<xfinal) - { - xinicial--; if(yinicialyfinal) { yinicial--; - } - - path++; } if(path%10==0) @@ -1331,9 +2099,7 @@ void MainWindow:: lanzamiento () bolaFuego->setPos(xinicial,yinicial); scene->addItem(bolaFuego); timer->start(30); - } - if(i==100) { bolaFuego->setPos(xinicial,yinicial); @@ -1341,9 +2107,7 @@ void MainWindow:: lanzamiento () i=0; timer->start(30); } - i++; - } } */ @@ -1353,19 +2117,20 @@ void MainWindow:: lanzamiento () void MainWindow::lanzarfuego() -{if (opcion==1) - { +{ if (opcion==1) + { x = enemigo1->x(); - y = enemigo1->y(); //(an,posxx,posyy,velocidad,r,path) - cuerpos.push_back(new Particula (0,x, y,100,30,":/IMAGENES/BOLADEFUEGO.png")); + y = enemigo1->y(); + qDebug() << "Mainwindow: lanzar juego"<addItem(cuerpos.back()); timer->start(30); - } + } if (opcion==2) { x = enemigo1->x(); y = enemigo1->y(); //(an,posxx,posyy,velocidad,r,path) - cuerpos.push_back(new Particula (0,x, y,200,30,":/IMAGENES/BOLADEFUEGO.png")); + cuerpos.push_back(new Particula (0,x, y,200,30,":/I/I/BOLADEFUEGO.png")); scene->addItem(cuerpos.back()); timer->start(30); } @@ -1373,14 +2138,15 @@ void MainWindow::lanzarfuego() { x = enemigo1->x(); y = enemigo1->y(); //(an,posxx,posyy,velocidad,r,path) - cuerpos.push_back(new Particula (0,x, y,300,30,":/IMAGENES/BOLADEFUEGO.png")); + cuerpos.push_back(new Particula (0,x, y,300,30,":/I/I/BOLADEFUEGO.png")); scene->addItem(cuerpos.back()); timer->start(30); } } + void MainWindow::mover() -{ +{ qDebug() << "Mainwindow: mover"< :: iterator it=cuerpos.begin(); it!=cuerpos.end(); it++) { (*it)->CalcularVelocidad(); @@ -1445,63 +2211,6 @@ void MainWindow::resorte(char letra , Personaje *personaje) } } -void MainWindow::magnetismo() -{ - /*if (opcion==1) - {float f, dx, dy,r; - dx=enemigo1->x()-personaje1->x(); - dy=enemigo1->x()-personaje1->x(); - r=pow(dx,2)+pow(dy,2); - f=(M*M)/(K*pow(r,2)); - x = enemigo1->x()*f; - y = enemigo1->y()*f; - bolaFuego->setPos(x,y); - scene->addItem(bolaFuego); - timer->start(30); - }*/ -} - -/*void MainWindow::guardardatos(QString usuario) -{ - QString text; - - text=usuario+" "+'\n' ; - - QFile archivo("USUARIO.txt"); - - - if(archivo.open(QIODevice::Append | QIODevice::Text)){ - QTextStream datosArchivo(&archivo); - - - datosArchivo << text<< endl; - - } - archivo.close(); -} -*/ - -void MainWindow::Mover() -{/* - for(QList::iterator it=cuerpos.begin(); it!=cuerpos.end();it++) - { - (*it)->CalcularVelicidad(); - (*it)->ActualizarPosicion(); - } - double ang,x,y,v,a; - ang= enemigo1->angulo; - x= enemigo1->posx; - y= enemigo1->posy; - v= enemigo1->velocidad; - a= (ang/180)*3.1416; - cuerpos.push_back(new particula(rad, x, y, v)); - scene->addItem(cuerpos.back()); - //cuerpo= new particula(rad, x, y, v); - //Scene->addItem(cuerpo); - timer->start(30);*/ - -} - void MainWindow::moverEnemigo( ) { if(ban==false) @@ -1518,8 +2227,6 @@ void MainWindow::moverEnemigo( ) } } - - //-------------------------------------------------DESTRUCTOR--------------------------------------------------------------- @@ -1532,33 +2239,24 @@ MainWindow::~MainWindow() void MainWindow::actualizar() -{ - +{/* - /*for (int i=0; i Acacelx(*(particula2)); + //LISTA.at(i) ->Acacelx(*LISTA.at(j)); - // LISTA.at(i)-> Acacely(*(LISTA.at(j) )); + + // LISTA.at(i) ->Acacely(*LISTA.at(j)); } } } for(int i=0;iActualizar(); - particula1->Actualizar(particula1); - particula1->Actualizar(particula2); - - + LISTA.at(i)->Actualizar(); }*/ - //actualiza cada dato - - -//actualiza cada dato } - diff --git a/mainwindow.h b/mainwindow.h index fa113ce..9174bf7 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -3,11 +3,11 @@ #include #include -#include +//#include #include #include #include -#include +//#include #include #include #include @@ -17,12 +17,9 @@ #include #include #include -#include #include #include #include - -#define K 0.00000001 QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; @@ -63,32 +60,24 @@ private slots: void lanzarfuego(); - void guardarPartida(); + void continuar(); void botonInicio(); void moverEnemigo(); - void CoeficienteRestitucion(); - void coaliciones (char , Personaje *personaje ); - void magnetismo(); - - void Mover(); - void resorte(char letter,Personaje *personaje); - //void guardardatos(QString usuario); - private: Ui::MainWindow *ui; QGraphicsScene *scene; //SONIDOS - QMediaPlayer *key; - QMediaPlayer *intro; + //QMediaPlayer *key; + //QMediaPlayer *intro; //PARTÍCULA @@ -96,11 +85,9 @@ private slots: QTimer *timer; QTimer *Timer; QTimer *disparo; - QTimer *parabolico; QLabel *label; - /*Particula *cuerpo; - QListcuerpos; - QListLISTA;*/ + Particula *cuerpo; + //QListLISTA; //OBJETOS //Personaje *personaje1; @@ -109,16 +96,14 @@ private slots: Personaje *personaje1; Personaje *personaje2; Personaje *lanzador; - Sprite *dragon; Objeto *puerta; Objeto *bolaH; Objeto *bolaFuego; Objeto *llave; QObject *personaje; + Objeto *boton; vidas *vida; llaves *keys; - - //particula *cuerpo; double x; double y; int opcion=0; @@ -126,9 +111,10 @@ private slots: int i=0; int rigidez=0; int aceleracion; + //____ prueba - /*Particula *particula1; - Particula *particula2;*/ + Particula *particula1; + Particula *particula2; // Sprite *personaje1; void keyPressEvent(QKeyEvent * evento); @@ -137,14 +123,21 @@ private slots: void niveles(int); + void guardarPartida(); + void clean (); + void teletransportacion(); + int path=0; bool ban=false; + bool visible; + QPushButton *start; -QPushButton *saveData; -//QLineEdit *save; +QPushButton *continuarPartida; +QPushButton *guardar; +QFile archivo; }; #endif // MAINWINDOW_H From b244fb6e80d526f05c15c3fb061c80b5110947be Mon Sep 17 00:00:00 2001 From: saraycubillos <62775794+saraycubillos@users.noreply.github.com> Date: Tue, 28 Jul 2020 15:56:19 -0500 Subject: [PATCH 5/7] =?UTF-8?q?Creo=20un=20=C3=BAnico=20timer=20para=20las?= =?UTF-8?q?=20funciones?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mainwindow.cpp | 417 +++++++------------------------------------------ mainwindow.h | 45 ++---- particula.cpp | 67 ++++++++ particula.h | 43 +++++ personaje.cpp | 20 +-- personaje.h | 7 +- 6 files changed, 186 insertions(+), 413 deletions(-) create mode 100644 particula.cpp create mode 100644 particula.h diff --git a/mainwindow.cpp b/mainwindow.cpp index d29853d..a581d5a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -597,13 +597,7 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { resorte('A', personaje1); - x = enemigo1->x(); - y = enemigo1->y(); vida->decrease(); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); - - timer->start(30); } //------------------------EVALUAR COALISIONES CON MUROS 1(A)------------------ @@ -644,24 +638,9 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) scene->removeItem(llave); keys->increase(); llave->hide(); - //delete (llave); - } } - //--------------------------PUERTA 1(A)------------------------------------------- - /*if (personaje1->collidesWithItem(puerta)) - { - - personaje1->derecha(); - //remover escena - } - - - - - - */ } if (letra=='D') { @@ -686,10 +665,6 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) x = enemigo1->x(); y = enemigo1->y(); vida->decrease(); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); - - timer->start(30); } //----------------------EVALUAR COALISIONES CON MUROS 1(D)------------------ for (int i=0;iremoveItem(llave); keys->increase(); llave->hide(); - //delete (llave); - } } - - //--------------------------PUERTA 1(D)------------------------------ - /*if (personaje1->collidesWithItem(puerta)) - { - personaje1->izquierda(); - //remover escena - } - */ } if (letra=='W') { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - - //-------------------------GIRO DE PERSONAJE 1(W)----------------------- personaje1->setTransformOriginPoint(0,0); personaje1->setRotation(270); @@ -761,15 +723,7 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) if(personaje1->collidesWithItem(enemigo1)) { resorte('W', personaje1); - - - x = enemigo1->x(); - y = enemigo1->y(); vida->decrease(); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); - - timer->start(30); } //----------------EVALUAR COALISIONES CON MUROS 1(W))----------------------- for (int i=0;icollidesWithItem(muros.at(i))) { - - personaje1->bajar(); } } @@ -807,25 +759,11 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) scene->removeItem(llave); keys->increase(); llave->hide(); - //delete (llave); - } } - - //-----------------------------------PUERTA 1(W)------------------------------- - /*if (personaje1->collidesWithItem(puerta)) - { - personaje1->bajar(); - //remover escena - } - - */ } if (letra=='S') { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - - //---------------------------GIRO DE PERSONAJE 1(S)--------------------------- personaje1->setTransformOriginPoint(0,0); personaje1->setRotation(90); @@ -838,18 +776,8 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) bolaH->bajar(); } if(personaje1->collidesWithItem(enemigo1)) - - - { - - x = enemigo1->x(); - y = enemigo1->y(); - vida->decrease(); - resorte('S', personaje1); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); - - timer->start(30); + {vida->decrease(); + resorte('S', personaje1); } //-----------------------EVALUAR COALISIONES CON MUROS 1(S)---------------- @@ -886,22 +814,8 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) scene->removeItem(llave); keys->increase(); llave->hide(); - //delete (llave); - } } - - //-------------------------PUERTA 1(S)----------------------------------- - /* - if (personaje1->collidesWithItem(puerta)) - { - personaje1->subir(); - //remover escena - } - */ - - - } @@ -914,9 +828,6 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) if (letra=='I') { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - - //-------------------GIRO DE PERSONAJE 2(I)------------------- personaje2->setTransformOriginPoint(0,0); personaje2->setRotation(270); @@ -934,15 +845,7 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { resorte('I', personaje2); - - - x = enemigo1->x(); - y = enemigo1->y(); vida->decrease(); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); - - timer->start(30); } //-----------------------------EVALUAR COALISIONES CON MUROS 2(I)------------------ @@ -950,8 +853,6 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { if (personaje2->collidesWithItem(muros.at(i))) { - - personaje2->bajar(); } } @@ -975,26 +876,12 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) scene->removeItem(llave); keys->increase(); llave->hide(); - //delete (llave); - } } - - //------------------------------------PUERTA 2(I)---------------------------------- - /*if (personaje2->collidesWithItem(puerta)) - { - personaje2->bajar(); - //remover escena - } - */ - } if (letra=='J') { - - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - //---------GIRO DEL PERSONAJE------- personaje2->setTransformOriginPoint(0,0); personaje2->setRotation(180); @@ -1012,12 +899,7 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { resorte('J', personaje2); - x = enemigo1->x(); - y = enemigo1->y(); vida->decrease(); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); - timer->start(30); } //-----------------------EVALUAR COALISIONES CON MUROS 2(J)--------------------- @@ -1025,19 +907,15 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { if (personaje2->collidesWithItem(muros.at(i))) { - personaje2->derecha(); } } - - //-------------------------EVALUAR COALISIONES CON PIEDRAS 2(J)-------------- for (int i=0;icollidesWithItem(piedras.at(i))) { - personaje2->derecha(); } } @@ -1051,34 +929,13 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) scene->removeItem(llave); keys->increase(); llave->hide(); - //delete (llave); - } } - - //----------------------------------PUERTA 2(J)------------------------------- - - /*if (personaje2->collidesWithItem(puerta)) - { - - personaje2->derecha(); - //remover escena - } - */ - - - - - - - } if (letra=='L') { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - //---------GIRO DEL PERSONAJE------- personaje2->setTransformOriginPoint(0,0); personaje2->setRotation(0); @@ -1092,26 +949,15 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) } if(personaje2->collidesWithItem(enemigo1)) - { - x = enemigo1->x(); - y = enemigo1->y(); resorte('L', personaje2); vida->decrease(); - //bolaFuego->setPosx(personaje1->pos()); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); - - timer->start(30); } //------------------------EVALUAR COALISIONES CON MUROS 2(L)-------------------------- for (int i=0;icollidesWithItem(muros.at(i))) { - - - personaje2->izquierda(); } } @@ -1121,11 +967,9 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { if (personaje2->collidesWithItem(piedras.at(i))) { - personaje2->izquierda(); } } - //------------------------------CAPTURAR LLAVES 2(L)-------------------------------- if(llave->isVisible()) @@ -1135,26 +979,11 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) scene->removeItem(llave); keys->increase(); llave->hide(); - //delete (llave); - } } - - //-------------------------------------PUERTA 2(L)----------------------------- - /*if (personaje2->collidesWithItem(puerta)) - { - personaje2->izquierda(); - //remover escena } - */ - } - - if (letra=='K') { - //lanzamiento(-40,personaje1->x(),70,personaje1->y()); - - //---------------------------------GIRO DE PERSONAJE 2(K)---------------------- personaje2->setTransformOriginPoint(0,0); personaje2->setRotation(90); @@ -1169,26 +998,15 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) } if(personaje2->collidesWithItem(enemigo1)) - - - { - - x = enemigo1->x(); - y = enemigo1->y(); - vida->decrease(); - resorte('K', personaje2); - //cuerpos.push_back(new Particula (0, x, y ,100,10,":/IMAGENES/BOLA DE FUEGO.png")); - //scene->addItem(cuerpos.back()); - - timer->start(30); - } + {vida->decrease(); + resorte('K', personaje2); + } //--------------------------EVALUAR COALISIONES CON MUROS 2(K)-------------------------- for (int i=0;icollidesWithItem(muros.at(i))) { - personaje2->subir(); } } @@ -1197,7 +1015,6 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { if (personaje2->collidesWithItem(piedras.at(i))) { - personaje2->subir(); } } @@ -1210,23 +1027,9 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) scene->removeItem(llave); keys->increase(); llave->hide(); - //delete (llave); } } - - //------------------------------PUERTA 2(K)------------------------------------------ - - /*if (personaje2->collidesWithItem(puerta)) - { - personaje2->subir(); - //remover escena - } - */ - - - - } } @@ -1315,50 +1118,40 @@ void MainWindow:: niveles(int opcion) } if (opcion==1) - { - - - - //intro->stop(); + { //intro->stop(); //key=new QMediaPlayer (); //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + //TIMER timer= new QTimer; - connect(timer,SIGNAL(timeout()), this, SLOT (mover())); - QTimer *cronometro = new QTimer(this); - connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); - cronometro->start(10000); - /*QTimer *cronometro2 = new QTimer(this); - connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); - cronometro2->start(1000);*/ + connect(timer,SIGNAL(timeout()), this, SLOT (actualizar())); + timer->start(240); //CREANDO LA ESCENA ui->setupUi(this); scene = new QGraphicsScene; ui->graphicsView->setScene(scene); - //scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); - personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); scene->addItem(personaje1); - personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + personaje2=new Personaje(0,0,45, ":/I/I/PERSONAJE2.png"); scene->addItem(personaje2); llave= new Objeto (470,35,30,":/I/I/llave1.png"); scene->addItem(llave); - enemigo1= new Personaje (-105,310,60,1,":/I/I/ENEMIGO.png"); //antes -105, 310 - scene->addItem(enemigo1); + dragon= new Objeto (305, 310,60,":/I/I/dragon.png"); + scene->addItem(dragon); - timerEnem= new QTimer; - timerEnem->stop(); - connect(timerEnem, SIGNAL(timeout()), this , SLOT (moverEnemigo())); - timerEnem->start(9000); + enemigo1= new Personaje (475,110,60,":/I/I/ENEMIGO.png"); + scene->addItem(enemigo1); rigidez=10; - aceleracion=150; + friccion=30; vida=new vidas(); vida->setPos(120,35); @@ -1400,21 +1193,21 @@ void MainWindow:: niveles(int opcion) scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); - personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); scene->addItem(personaje1); - personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + personaje2=new Personaje(0,0,45, ":/I/I/PERSONAJE2.png"); scene->addItem(personaje2); llave= new Objeto (470,35,30,":/I/I/llave1.png"); scene->addItem(llave); - enemigo1= new Personaje (-135,415,60,1.5,":/I/I/ENEMIGO.png"); + enemigo1= new Personaje (-135,415,60,":/I/I/ENEMIGO.png"); scene->addItem(enemigo1); rigidez=11; - aceleracion=160; + friccion=160; items(); @@ -1449,24 +1242,24 @@ void MainWindow:: niveles(int opcion) scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); - personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); scene->addItem(personaje1); - personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + personaje2=new Personaje(0,0,45, ":/I/I/PERSONAJE2.png"); scene->addItem(personaje2); llave= new Objeto (470,35,30,":/I/I/llave1.png"); scene->addItem(llave); - enemigo1= new Personaje (395,210,60,1.5,":/I/I/SERPIENTE1(1).png"); + enemigo1= new Personaje (395,210,60,":/I/I/SERPIENTE1(1).png"); scene->addItem(enemigo1); - totem= new Personaje (0,0,60 ,1, ":/I/I/TOTEMARENA.png"); + totem= new Personaje (0,0,60 , ":/I/I/TOTEMARENA.png"); scene->addItem(totem); timer->start(); rigidez=12; - aceleracion=170; + friccion=170; items(); @@ -1498,10 +1291,10 @@ void MainWindow:: niveles(int opcion) scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); - personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); scene->addItem(personaje1); - personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + personaje2=new Personaje(0,0,45, ":/I/I/PERSONAJE2.png"); scene->addItem(personaje2); llave= new Objeto (470,35,30,":/I/I/llave1.png"); @@ -1536,10 +1329,10 @@ void MainWindow:: niveles(int opcion) scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); - personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); scene->addItem(personaje1); - personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + personaje2=new Personaje(0,0,45, ":/I/I/PERSONAJE2.png"); scene->addItem(personaje2); llave= new Objeto (470,35,30,":/I/I/llave1.png"); @@ -1574,10 +1367,10 @@ void MainWindow:: niveles(int opcion) scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); - personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); scene->addItem(personaje1); - personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + personaje2=new Personaje(0,0,45, ":/I/I/PERSONAJE2.png"); scene->addItem(personaje2); llave= new Objeto (470,35,30,":/I/I/llave1.png"); @@ -1611,10 +1404,10 @@ void MainWindow:: niveles(int opcion) scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); - personaje1=new Personaje(180,410,30,1, ":/I/I/PERSONAJE1.png"); + personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); scene->addItem(personaje1); - personaje2=new Personaje(0,0,45,10, ":/I/I/PERSONAJE2.png"); + personaje2=new Personaje(0,0,45, ":/I/I/PERSONAJE2.png"); scene->addItem(personaje2); llave= new Objeto (470,35,30,":/I/I/llave1.png"); @@ -1671,10 +1464,10 @@ void MainWindow::items() muros.push_back(new Pared (-350,50,50,800, ":/I/I/rocas2.png")); //muro vertical scene->addItem(muros.back()); - muros.push_back(new Pared (-120,50,20,50, ":/I/I/BLOQUE.jpg")); //abajo derecha conexion nivel 1 + muros.push_back(new Pared (-120,50,20,50, ":/I/I/BLOQUE.jpg")); //abajo derecha conexion nivel 5 scene->addItem(muros.back()); - muros.push_back(new Pared (-200,50,20,50, ":/I/I/BLOQUE.jpg")); //abajo izqu conexion nivel 1 + muros.push_back(new Pared (-200,50,20,50, ":/I/I/BLOQUE.jpg")); //abajo izqu conexion nivel 5 scene->addItem(muros.back()); muros.push_back(new Pared (-500,-10,50,30, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 4 ancho alto @@ -1834,23 +1627,6 @@ void MainWindow::items() void MainWindow::clean() { - /*scene->removeItem(enemigo1); - delete (enemigo1); - scene->removeItem(personaje1); - delete (personaje1); - - - for (int i=0;ihide(); - scene->removeItem(cuerpos.at(i)); - - delete (cuerpos.at (i)); - cuerpos.removeOne(cuerpos.at(i)); - - - - }*/ for (int i=0;iremoveItem(piedras.at(i)); @@ -2056,98 +1832,29 @@ void MainWindow::guardarPartida() //--------------------------------------------------FISICAS-------------------------------------------------- -void MainWindow:: lanzamiento () +void MainWindow::lanzarfuego() { - - /* int xinicial=0; - int xfinal=personaje1->x(); - int yinicial=0; - int yfinal=personaje1->y(); - while ((xinicial!=xfinal) or (yinicial!=yfinal)) - { - if (xinicialyfinal) - { - yinicial--; - } - path++; - } - //cout<<" PATH: "<<"( "<xfinal) - { - xinicial--; - if(yinicialyfinal) - { - yinicial--; - } - path++; - } - if(path%10==0) - {if (i==1) - { - bolaFuego->setPos(xinicial,yinicial); - scene->addItem(bolaFuego); - timer->start(30); - } - if(i==100) - { - bolaFuego->setPos(xinicial,yinicial); - scene->addItem(bolaFuego); - i=0; - timer->start(30); + if (opcion==1) + {x=dragon->getPosx(); + y=dragon->getPosy(); //(an,posxx,posyy,velocidad,r,path) + cuerpos.push_back(new Particula (0,x, y,100,30,":/I/I/BOLADEFUEGO.png")); + scene->addItem(cuerpos.back()); } - i++; -} - } -*/ - - -} - - -void MainWindow::lanzarfuego() -{ if (opcion==1) - { - x = enemigo1->x(); - y = enemigo1->y(); - qDebug() << "Mainwindow: lanzar juego"<addItem(cuerpos.back()); - timer->start(30); - } if (opcion==2) - { - x = enemigo1->x(); - y = enemigo1->y(); //(an,posxx,posyy,velocidad,r,path) + { //(an,posxx,posyy,velocidad,r,path) cuerpos.push_back(new Particula (0,x, y,200,30,":/I/I/BOLADEFUEGO.png")); scene->addItem(cuerpos.back()); - timer->start(30); } if (opcion==3) - { - x = enemigo1->x(); - y = enemigo1->y(); //(an,posxx,posyy,velocidad,r,path) + { //(an,posxx,posyy,velocidad,r,path) cuerpos.push_back(new Particula (0,x, y,300,30,":/I/I/BOLADEFUEGO.png")); scene->addItem(cuerpos.back()); - timer->start(30); } } void MainWindow::mover() -{ qDebug() << "Mainwindow: mover"< :: iterator it=cuerpos.begin(); it!=cuerpos.end(); it++) +{ for (QList :: iterator it=cuerpos.begin(); it!=cuerpos.end(); it++) { (*it)->CalcularVelocidad(); (*it)->ActualizarPosicion(); @@ -2214,14 +1921,14 @@ void MainWindow::resorte(char letra , Personaje *personaje) void MainWindow::moverEnemigo( ) { if(ban==false) - {enemigo1->setX(enemigo1->x()+2*aceleracion); - if(enemigo1->x()>=514) + {enemigo1->setX(enemigo1->x()+2*friccion*M*G); + if(enemigo1->x()>=305) {ban=true; } } if(ban==true) - {enemigo1->setX(enemigo1->x()-2*aceleracion); - if(enemigo1->x()<=-96) + {enemigo1->setX(enemigo1->x()-2*friccion*M*G); + if(enemigo1->x()<=80) {ban=false; } } @@ -2239,24 +1946,12 @@ MainWindow::~MainWindow() void MainWindow::actualizar() -{/* - - for (int i=0; iAcacelx(*LISTA.at(j)); - - - // LISTA.at(i) ->Acacely(*LISTA.at(j)); - } - } +{ + moverEnemigo(); + counter++; + mover(); + if(counter==6) + {lanzarfuego(); + counter=0; } - for(int i=0;iActualizar(); - }*/ - } diff --git a/mainwindow.h b/mainwindow.h index 9174bf7..0c1f386 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -41,34 +41,11 @@ class MainWindow : public QMainWindow private slots: - - //SLOTS DE LA PARTÍCULA - - - /*double masa; - double posx; - double posy; - double radio; - double vx; - double vy;*/ - - void mover(); - - void actualizar(); - - void lanzamiento (); - - void lanzarfuego(); - void continuar(); void botonInicio(); - void moverEnemigo(); - - void coaliciones (char , Personaje *personaje ); - - void resorte(char letter,Personaje *personaje); + void actualizar(); private: @@ -81,16 +58,11 @@ private slots: //PARTÍCULA - QTimer *timerEnem; QTimer *timer; - QTimer *Timer; - QTimer *disparo; QLabel *label; Particula *cuerpo; - //QListLISTA; //OBJETOS - //Personaje *personaje1; Personaje *enemigo1; Personaje *totem; Personaje *personaje1; @@ -102,6 +74,7 @@ private slots: Objeto *llave; QObject *personaje; Objeto *boton; + Objeto *dragon; vidas *vida; llaves *keys; double x; @@ -110,12 +83,12 @@ private slots: int nivel=0; int i=0; int rigidez=0; - int aceleracion; + int friccion=0; + int counter=0; //____ prueba Particula *particula1; Particula *particula2; - // Sprite *personaje1; void keyPressEvent(QKeyEvent * evento); @@ -135,6 +108,16 @@ private slots: bool visible; + void mover(); + + void lanzarfuego(); + + void moverEnemigo(); + + void coaliciones (char , Personaje *personaje ); + + void resorte(char letter,Personaje *personaje); + QPushButton *start; QPushButton *continuarPartida; QPushButton *guardar; diff --git a/particula.cpp b/particula.cpp new file mode 100644 index 0000000..ef0788d --- /dev/null +++ b/particula.cpp @@ -0,0 +1,67 @@ +#include "particula.h" + +double Particula::getPosy() const +{ + return posy; +} + +double Particula::getPosx() const +{ + return posx; +} + +int Particula::getR() +{ + return radio; +} + +void Particula::setR(int r) +{ + radio=r; +} +QRectF Particula::boundingRect() const +{ + return QRectF(-radio,-radio,2*radio,2*radio); +} + +void Particula::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + QPixmap pixmap; + + pixmap.load(ruta); + + painter->drawPixmap(boundingRect(),pixmap,pixmap.rect()); +} + + +Particula::Particula() +{ + +} + +Particula::Particula(double an, double posxx, double posyy, double velocidad,int r, QString path) +{ + angulo=an; + posx=posxx; + posy=posyy; + vel=velocidad; + ruta=path; + radio=r; + setPos(posx, posy); + +} + +void Particula::ActualizarPosicion() +{ + posx-=vx; + + setPos(posx,posy); +} + +void Particula::CalcularVelocidad() +{ + + vx=vel; + + +} diff --git a/particula.h b/particula.h new file mode 100644 index 0000000..5f12b6b --- /dev/null +++ b/particula.h @@ -0,0 +1,43 @@ +#ifndef PARTICULA_H +#define PARTICULA_H + +#include +#include +#include //seno coseno raiz + +class Particula: public QGraphicsItem +{ + //velocidades y posiciones afectadas por angulos, para que no haya desfase y mas presicion + //se le dan las conidiones iniciales (atributos) + double angulo, vx, vy,vel; + double posx, posy; + int radio; + // se van a recalculas con base en las ecuaciones + double g= 9.8; //tiempo + QString ruta; + + int r=30; +public: + Particula(); + Particula(double an, double posxx, double posyy , double velocidad, int r, QString path); + //para poder saber la posicion a la que va a llegar , depende de la velocidad, antes de actualizar la posicion , la velocidad debe actualizarse + void ActualizarPosicion(); + //primero se calcula la velocidaD Y LUEGO LAS POSICIONES SE ACTUALIZAN + + void CalcularVelocidad(); + void CalcularAceleracion(Particula par ); + + double getPosy() const; + double getPosx() const; + + int getR(); + void setR(int r); + + + + QRectF boundingRect() const ; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr); +}; + +#endif // PARTICULA_H + diff --git a/personaje.cpp b/personaje.cpp index e934b5c..10a66bc 100644 --- a/personaje.cpp +++ b/personaje.cpp @@ -5,13 +5,12 @@ Personaje::Personaje() } -Personaje::Personaje(int x, int y, int r, float f, QString path) +Personaje::Personaje(int x, int y, int r, QString path) { radio=r; posx = x; posy = y; ruta=path; - friccion=f; setPos(posx,posy); } @@ -46,35 +45,26 @@ void Personaje::setPosy(int py) } void Personaje::subir() -{setPos(x(),y()-5*friccion*M*G); +{setPos(x(),y()-5); } void Personaje::bajar() { - setPos(x(),y()+5*friccion*M*G); + setPos(x(),y()+5); } void Personaje::derecha() { - setPos(x()+5*friccion*M*G,y()); + setPos(x()+5,y()); } void Personaje::izquierda() { - setPos(x()-5*friccion*M*G,y()); + setPos(x()-5,y()); } -/*void Personaje::setFriccion( int f ) -{ - friccion=f; -} -int Personaje::getFriccion() -{ - return friccion; -}*/ - QRectF Personaje::boundingRect() const { return QRectF(-radio,-radio,2*radio,2*radio); diff --git a/personaje.h b/personaje.h index d9c3348..ebc56dd 100644 --- a/personaje.h +++ b/personaje.h @@ -13,12 +13,11 @@ class Personaje : public QGraphicsItem int radio; int posx, posy; QString ruta; - float friccion; public: Personaje(); - Personaje ( int x, int y , int r, float friccion , QString path); + Personaje ( int x, int y , int r, QString path); int getR(); void setR(int radio); int getPosx(); @@ -29,10 +28,6 @@ class Personaje : public QGraphicsItem void bajar(); void derecha(); void izquierda(); - float getaceleracion(); - void setaceleracion(int radio); - //void setFriccion(int f); - //int getFriccion( ); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr); From 67c594f8ccaa963d7eefb85e80545457ef033b2c Mon Sep 17 00:00:00 2001 From: saraycubillos <62775794+saraycubillos@users.noreply.github.com> Date: Thu, 30 Jul 2020 23:06:20 -0500 Subject: [PATCH 6/7] Se comentaron muchas cosas de new item --- mainwindow.cpp | 410 +++++++++++++++++++++++++++++++++---------------- mainwindow.h | 28 ++-- 2 files changed, 292 insertions(+), 146 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index a581d5a..4a7aaca 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -9,7 +9,6 @@ MainWindow::MainWindow(QWidget *parent) niveles(opcion); - //-----------------------------BOTÓN START--------------------------- start=new QPushButton("INICIAR JUEGO", this); @@ -41,9 +40,6 @@ QSize(200, 50) )); connect(guardar, SIGNAL (clicked()),this, SLOT (continuar())); guardar ->setStyleSheet("background-color: red"); - -bolaFuego=new Objeto(0,0,30, ":/IMAGENES/BOLA DE FUEGO.png"); - /* timer->stop(); connect(timer,SIGNAL(timeout()),this,SLOT(actualizar())); @@ -569,13 +565,18 @@ if(evento->key()==Qt::Key_7) void MainWindow::coaliciones(char letra , Personaje *personaje) { + /*if(vida->getlife()==0) + { + }*/ + /*if(keys->getkey()==6) + { + piedra->hide(); + }*/ if (personaje==personaje1) { - - if (letra=='A') { //lanzamiento(-40,personaje1->x(),70,personaje1->y()); @@ -593,12 +594,22 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { bolaH->izquierda(); } - if(personaje1->collidesWithItem(enemigo1)) + + if(personaje1->collidesWithItem(bolafuego)) + { + personaje1->derecha(); + vida->decrease(); + } + + if(enemigo1->isVisible()) + {if(personaje1->collidesWithItem(enemigo1)) { resorte('A', personaje1); vida->decrease(); } + } + //------------------------EVALUAR COALISIONES CON MUROS 1(A)------------------ for (int i=0;icollidesWithItem(llave)) { //key->play(); - scene->removeItem(llave); keys->increase(); llave->hide(); } @@ -658,7 +668,15 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { bolaH->derecha(); } - if(personaje1->collidesWithItem(enemigo1)) + + if(personaje1->collidesWithItem(bolafuego)) + { + personaje1->izquierda(); + vida->decrease(); + } + + if(enemigo1->isVisible()) + {if(personaje1->collidesWithItem(enemigo1)) { resorte('D', personaje1); @@ -666,6 +684,7 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) y = enemigo1->y(); vida->decrease(); } + } //----------------------EVALUAR COALISIONES CON MUROS 1(D)------------------ for (int i=0;icollidesWithItem(llave)) { //key->play(); - scene->removeItem(llave); keys->increase(); llave->hide(); } @@ -720,11 +738,20 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { bolaH->subir(); } - if(personaje1->collidesWithItem(enemigo1)) + + if(personaje1->collidesWithItem(bolafuego)) + { + personaje1->bajar(); + vida->decrease(); + } + + if(enemigo1->isVisible()) + {if(personaje1->collidesWithItem(enemigo1)) { resorte('W', personaje1); vida->decrease(); } + } //----------------EVALUAR COALISIONES CON MUROS 1(W))----------------------- for (int i=0;icollidesWithItem(llave)) { //key->play(); - scene->removeItem(llave); keys->increase(); llave->hide(); } @@ -775,10 +801,19 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { bolaH->bajar(); } - if(personaje1->collidesWithItem(enemigo1)) + + if(personaje1->collidesWithItem(bolafuego)) + { + personaje1->subir(); + vida->decrease(); + } + + if(enemigo1->isVisible()) + {if(personaje1->collidesWithItem(enemigo1)) {vida->decrease(); resorte('S', personaje1); } + } //-----------------------EVALUAR COALISIONES CON MUROS 1(S)---------------- for (int i=0;icollidesWithItem(llave)) { //key->play(); - scene->removeItem(llave); keys->increase(); llave->hide(); } @@ -841,20 +875,31 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) bolaH->subir(); } - if(personaje2->collidesWithItem(enemigo1)) + if(personaje2->collidesWithItem(bolafuego)) + { + personaje2->bajar(); + vida->decrease(); + } + + if(enemigo1->isVisible()) + {if(personaje2->collidesWithItem(enemigo1)) { resorte('I', personaje2); vida->decrease(); } + } //-----------------------------EVALUAR COALISIONES CON MUROS 2(I)------------------ for (int i=0;icollidesWithItem(muros.at(i))) - { - personaje2->bajar(); - } + if (muros.at(i)->isVisible()) + { + if (personaje2->collidesWithItem(muros.at(i))) + { + personaje2->bajar(); + } + } } //-------------------------------EVALUAR COALISIONES CON PIEDRAS 2(I)-------------- @@ -873,7 +918,6 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) {if (personaje2->collidesWithItem(llave)) { //key->play(); - scene->removeItem(llave); keys->increase(); llave->hide(); } @@ -895,20 +939,31 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) bolaH->izquierda(); } - if(personaje2->collidesWithItem(enemigo1)) + if(personaje2->collidesWithItem(bolafuego)) + { + personaje2->derecha(); + vida->decrease(); + } + + if(enemigo1->isVisible()) + {if(personaje2->collidesWithItem(enemigo1)) { resorte('J', personaje2); vida->decrease(); - timer->start(30); } + } //-----------------------EVALUAR COALISIONES CON MUROS 2(J)--------------------- + for (int i=0;icollidesWithItem(muros.at(i))) - { - personaje2->derecha(); - } + if (muros.at(i)->isVisible()) + { + if (personaje2->collidesWithItem(muros.at(i))) + { + personaje2->derecha(); + } + } } //-------------------------EVALUAR COALISIONES CON PIEDRAS 2(J)-------------- @@ -926,7 +981,6 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) {if (personaje2->collidesWithItem(llave)) { //key->play(); - scene->removeItem(llave); keys->increase(); llave->hide(); } @@ -948,18 +1002,30 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) bolaH->derecha(); } - if(personaje2->collidesWithItem(enemigo1)) + if(personaje2->collidesWithItem(bolafuego)) + { + personaje2->izquierda(); + vida->decrease(); + } + + if(enemigo1->isVisible()) + {if(personaje2->collidesWithItem(enemigo1)) { resorte('L', personaje2); vida->decrease(); } + } //------------------------EVALUAR COALISIONES CON MUROS 2(L)-------------------------- + for (int i=0;icollidesWithItem(muros.at(i))) - { - personaje2->izquierda(); - } + if (muros.at(i)->isVisible()) + { + if (personaje2->collidesWithItem(muros.at(i))) + { + personaje2->izquierda(); + } + } } //---------------------EVALUAR COALISIONES CON PIEDRAS 2(L)---------------------------- @@ -976,7 +1042,6 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) {if (personaje2->collidesWithItem(llave)) { //key->play(); - scene->removeItem(llave); keys->increase(); llave->hide(); } @@ -997,19 +1062,30 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) bolaH->bajar(); } - if(personaje2->collidesWithItem(enemigo1)) + if(personaje2->collidesWithItem(bolafuego)) + { + personaje2->subir(); + vida->decrease(); + } + + if(enemigo1->isVisible()) + {if(personaje2->collidesWithItem(enemigo1)) {vida->decrease(); resorte('K', personaje2); } + } //--------------------------EVALUAR COALISIONES CON MUROS 2(K)-------------------------- + for (int i=0;icollidesWithItem(muros.at(i))) + if (muros.at(i)->isVisible()) { - personaje2->subir(); + if (personaje2->collidesWithItem(muros.at(i))) + {personaje2->subir(); } } + } //-----------------------------EVALUAR COALISIONES CON PIEDRAS 2(K)---------------------- for (int i=0;icollidesWithItem(llave)) { //key->play(); - scene->removeItem(llave); keys->increase(); llave->hide(); @@ -1100,6 +1175,7 @@ void MainWindow:: niveles(int opcion) label->setMovie(movie); movie->start(); */ + /* QMovie *movie= new QMovie (":/IMAGENES/MENU.gif"); label = new QLabel(this); label->setMovie(movie); @@ -1125,7 +1201,7 @@ void MainWindow:: niveles(int opcion) //TIMER timer= new QTimer; connect(timer,SIGNAL(timeout()), this, SLOT (actualizar())); - timer->start(240); + timer->start(1440); //CREANDO LA ESCENA @@ -1144,14 +1220,16 @@ void MainWindow:: niveles(int opcion) llave= new Objeto (470,35,30,":/I/I/llave1.png"); scene->addItem(llave); - dragon= new Objeto (305, 310,60,":/I/I/dragon.png"); - scene->addItem(dragon); - - enemigo1= new Personaje (475,110,60,":/I/I/ENEMIGO.png"); + enemigo1= new Personaje (475,225,60,":/I/I/ENEMIGO.png"); scene->addItem(enemigo1); - rigidez=10; + bolafuego= new Particula (0,505,505,200,30,":/I/I/BOLADEFUEGO.png"); + scene->addItem(bolafuego); + + rigidez=6; friccion=30; + xmenor=75; + xmayor=330; vida=new vidas(); vida->setPos(120,35); @@ -1175,7 +1253,7 @@ void MainWindow:: niveles(int opcion) //key=new QMediaPlayer (); //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); - timer= new QTimer; + /*timer= new QTimer; connect(timer,SIGNAL(timeout()), this, SLOT (mover())); QTimer *cronometro = new QTimer(this); connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); @@ -1190,7 +1268,7 @@ void MainWindow:: niveles(int opcion) ui->setupUi(this); scene = new QGraphicsScene; ui->graphicsView->setScene(scene); - scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); @@ -1200,15 +1278,19 @@ void MainWindow:: niveles(int opcion) scene->addItem(personaje2); llave= new Objeto (470,35,30,":/I/I/llave1.png"); - scene->addItem(llave); + scene->addItem(llave);*/ - enemigo1= new Personaje (-135,415,60,":/I/I/ENEMIGO.png"); - scene->addItem(enemigo1); + bolaH->hide(); + enemigo1->setPos(500,500); + dragon= new Objeto (305,180,60,":/I/I/dragon.png"); + scene->addItem(dragon); + bolafuego->setPos(305,180); - rigidez=11; - friccion=160; - + rigidez=6; + friccion=20; + ymenor=-15; + ymayor=420; items(); teletransportacion(); @@ -1224,22 +1306,22 @@ void MainWindow:: niveles(int opcion) //key=new QMediaPlayer (); //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); - timer= new QTimer; + /*timer= new QTimer; connect(timer,SIGNAL(timeout()), this, SLOT (mover())); QTimer *cronometro = new QTimer(this); connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); cronometro->start(1000); - /*QTimer *cronometro2 = new QTimer(this); + QTimer *cronometro2 = new QTimer(this); connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); cronometro2->start(1000);*/ //CREANDO LA ESCENA - ui->setupUi(this); - scene = new QGraphicsScene; - ui->graphicsView->setScene(scene); - scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + //ui->setupUi(this); + //scene = new QGraphicsScene; + //ui->graphicsView->setScene(scene); + /*scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); @@ -1249,19 +1331,24 @@ void MainWindow:: niveles(int opcion) scene->addItem(personaje2); llave= new Objeto (470,35,30,":/I/I/llave1.png"); - scene->addItem(llave); + scene->addItem(llave);*/ - enemigo1= new Personaje (395,210,60,":/I/I/SERPIENTE1(1).png"); - scene->addItem(enemigo1); + enemigo1->setPos(-120,80); + dragon->setPos(520,330); + bolafuego->setPos(-20,345); + bolaH->hide(); - totem= new Personaje (0,0,60 , ":/I/I/TOTEMARENA.png"); + /*totem= new Personaje (0,0,60,""); scene->addItem(totem); - timer->start(); - - rigidez=12; - friccion=170; - - items(); + timer->start();*/ + + rigidez=6; + friccion=10; + xmenor=-120; + xmayor=520; + ymayor=350; + ymenor=-5; + items(); teletransportacion(); @@ -1274,7 +1361,7 @@ void MainWindow:: niveles(int opcion) //key=new QMediaPlayer (); //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); - timer= new QTimer; + /*timer= new QTimer; connect(timer,SIGNAL(timeout()), this, SLOT (mover())); QTimer *cronometro = new QTimer(this); connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); @@ -1286,9 +1373,9 @@ void MainWindow:: niveles(int opcion) //CREANDO LA ESCENA ui->setupUi(this); - scene = new QGraphicsScene; + scene = new QGraphicsScene;*/ ui->graphicsView->setScene(scene); - scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + /*scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); @@ -1299,6 +1386,17 @@ void MainWindow:: niveles(int opcion) llave= new Objeto (470,35,30,":/I/I/llave1.png"); scene->addItem(llave); + */ + + bolaH->hide(); + enemigo1->setPos(-120,105); + bolafuego->setPos(-20,345); + xmenor=-120; + xmayor=520; + ymayor=350; + ymenor=5; + rigidez=11; + friccion=10; items(); @@ -1312,7 +1410,7 @@ void MainWindow:: niveles(int opcion) //key=new QMediaPlayer (); //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); - timer= new QTimer; + /*timer= new QTimer; connect(timer,SIGNAL(timeout()), this, SLOT (mover())); QTimer *cronometro = new QTimer(this); connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); @@ -1337,7 +1435,15 @@ void MainWindow:: niveles(int opcion) llave= new Objeto (470,35,30,":/I/I/llave1.png"); scene->addItem(llave); - + */ + bolaH->hide(); + dragon->setPos(515,325); + xmenor=-115; + xmayor=510; + ymenor=5; + ymayor=360; + rigidez=11; + friccion=40; items(); teletransportacion(); @@ -1350,7 +1456,7 @@ void MainWindow:: niveles(int opcion) //key=new QMediaPlayer (); //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); - timer= new QTimer; + /*timer= new QTimer; connect(timer,SIGNAL(timeout()), this, SLOT (mover())); QTimer *cronometro = new QTimer(this); connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); @@ -1362,9 +1468,9 @@ void MainWindow:: niveles(int opcion) //CREANDO LA ESCENA ui->setupUi(this); - scene = new QGraphicsScene; + scene = new QGraphicsScene;*/ ui->graphicsView->setScene(scene); - scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + /*scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); @@ -1375,7 +1481,17 @@ void MainWindow:: niveles(int opcion) llave= new Objeto (470,35,30,":/I/I/llave1.png"); scene->addItem(llave); - + */ + enemigo1->setPos(-95,125); + dragon->setPos(445,360); + bolafuego->setPos(-5,345); + bolaH->hide(); + xmenor=-120; + xmayor=520; + ymenor=55; + ymayor=345; + rigidez=11; + friccion=30; items(); teletransportacion(); @@ -1387,7 +1503,7 @@ void MainWindow:: niveles(int opcion) //key=new QMediaPlayer (); //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); - timer= new QTimer; + /*timer= new QTimer; connect(timer,SIGNAL(timeout()), this, SLOT (mover())); QTimer *cronometro = new QTimer(this); connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); @@ -1399,9 +1515,9 @@ void MainWindow:: niveles(int opcion) //CREANDO LA ESCENA ui->setupUi(this); - scene = new QGraphicsScene; + scene = new QGraphicsScene;*/ ui->graphicsView->setScene(scene); - scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + /*scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); @@ -1411,8 +1527,16 @@ void MainWindow:: niveles(int opcion) scene->addItem(personaje2); llave= new Objeto (470,35,30,":/I/I/llave1.png"); - scene->addItem(llave); - + scene->addItem(llave);*/ + + enemigo1->setPos(-95,105); + dragon->setPos(410,350); + bolaH->hide(); + xmenor=-50; + xmayor=520; + ymayor=350; + rigidez=11; + friccion=30; items(); teletransportacion(); @@ -1423,14 +1547,13 @@ void MainWindow:: niveles(int opcion) void MainWindow::items() { - /* llave= new Objeto (470,35,30,":/IMAGENES/llave1.png"); scene->addItem(llave);*/ - bolaH= new Objeto (75,160, 30,":/I/I/BOLADEMETAL.png"); - scene->addItem(bolaH); - + llave->show(); + bolaH= new Objeto (-25,420, 30,":/I/I/BOLADEMETAL.png"); + scene->addItem(bolaH); muros.push_back(new Pared (200,-450,800,100, "")); scene->addItem(muros.back()); @@ -1476,8 +1599,6 @@ void MainWindow::items() if (opcion==2) { - - muros.push_back(new Pared (-120,50,20,50, ":/I/I/BLOQUE.jpg")); //arriba conex nivel 7 scene->addItem(muros.back()); @@ -1496,6 +1617,7 @@ void MainWindow::items() if (opcion==3) { + muros.push_back(new Pared (150,-160,50,30, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 5 arriba ancho alto scene->addItem(muros.back()); @@ -1541,7 +1663,6 @@ void MainWindow::items() if (opcion==5) { - /* muros.push_back(new Pared (0,200,50,400, ":/IMAGENES/BLOQUE.jpg")); //centro derecha conexion nivel 7 scene->addItem(muros.back()); muros.push_back(new Pared (-320,200,50,400, ":/IMAGENES/BLOQUE.jpg")); //centro izquierda conexion nivel 7 @@ -1575,6 +1696,7 @@ void MainWindow::items() if (opcion==6) { + muros.push_back(new Pared (30,200,50,400, ":/I/I/BLOQUE.jpg")); //centro derecha conexion nivel 7 scene->addItem(muros.back()); @@ -1662,6 +1784,7 @@ void MainWindow::teletransportacion() opcion=5; niveles(opcion); personaje1->setPos(170,345); + } if (personaje1->x()==520 and personaje1->y()==-20) //puerta arriba //conexion nivel 4 @@ -1832,7 +1955,7 @@ void MainWindow::guardarPartida() //--------------------------------------------------FISICAS-------------------------------------------------- -void MainWindow::lanzarfuego() +/*void MainWindow::lanzarfuego() { if (opcion==1) {x=dragon->getPosx(); @@ -1840,47 +1963,61 @@ void MainWindow::lanzarfuego() cuerpos.push_back(new Particula (0,x, y,100,30,":/I/I/BOLADEFUEGO.png")); scene->addItem(cuerpos.back()); } - if (opcion==2) - { //(an,posxx,posyy,velocidad,r,path) - cuerpos.push_back(new Particula (0,x, y,200,30,":/I/I/BOLADEFUEGO.png")); + + if (opcion==3) + { + //(an,posxx,posyy,velocidad,r,path) + cuerpos.push_back(new Particula (0,520,330,300,30,":/I/I/BOLADEFUEGO.png")); + scene->addItem(cuerpos.back()); + } + if (opcion==4) + { //(an,posxx,posyy,velocidad,r,path) + cuerpos.push_back(new Particula (0,520,330,400,30,":/I/I/BOLADEFUEGO.png")); scene->addItem(cuerpos.back()); } - if (opcion==3) - { //(an,posxx,posyy,velocidad,r,path) - cuerpos.push_back(new Particula (0,x, y,300,30,":/I/I/BOLADEFUEGO.png")); + if (opcion==5) + { //(an,posxx,posyy,velocidad,r,path) + cuerpos.push_back(new Particula (0,515,325,500,30,":/I/I/BOLADEFUEGO.png")); scene->addItem(cuerpos.back()); } + if (opcion==6) + { //(an,posxx,posyy,velocidad,r,path) + cuerpos.push_back(new Particula (0,445,360,600,30,":/I/I/BOLADEFUEGO.png")); + scene->addItem(cuerpos.back()); + } + if (opcion==7) + { //(an,posxx,posyy,velocidad,r,path) + cuerpos.push_back(new Particula (0,500,325,600,30,":/I/I/BOLADEFUEGO.png")); + scene->addItem(cuerpos.back()); + } -} - -void MainWindow::mover() -{ for (QList :: iterator it=cuerpos.begin(); it!=cuerpos.end(); it++) - { - (*it)->CalcularVelocidad(); - (*it)->ActualizarPosicion(); - +}*/ +void MainWindow::moverfuego() +{ + if(ban2==false) + {bolafuego->setY(bolafuego->y()+2*friccion*M*G); + if(bolafuego->y()>=ymayor) + {ban2=true; + } } - for (int i=0;isetY(bolafuego->y()-2*friccion*M*G); + if(bolafuego->y()<=ymenor) + {ban2=false; + } + } + if(personaje1->collidesWithItem(bolafuego)) { - if (personaje1->collidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - vida->decrease(); - } - + vida->decrease(); + personaje1->subir(); } - for (int i=0;icollidesWithItem(bolafuego)) { - if (personaje2->collidesWithItem(cuerpos.at(i))) - { - scene->removeItem(cuerpos.at(i)); - cuerpos.removeOne(cuerpos.at(i)); - vida->decrease(); - } - + vida->decrease(); + personaje2->subir(); } + } void MainWindow::resorte(char letra , Personaje *personaje) @@ -1922,16 +2059,26 @@ void MainWindow::moverEnemigo( ) { if(ban==false) {enemigo1->setX(enemigo1->x()+2*friccion*M*G); - if(enemigo1->x()>=305) + if(enemigo1->x()>=xmayor) {ban=true; } } if(ban==true) {enemigo1->setX(enemigo1->x()-2*friccion*M*G); - if(enemigo1->x()<=80) + if(enemigo1->x()<=xmenor) {ban=false; } } + if(personaje1->collidesWithItem(enemigo1)) + { + vida->decrease(); + personaje1->derecha(); + } + if(personaje2->collidesWithItem(enemigo1)) + { + vida->decrease(); + personaje2->derecha(); + } } //-------------------------------------------------DESTRUCTOR--------------------------------------------------------------- @@ -1946,12 +2093,17 @@ MainWindow::~MainWindow() void MainWindow::actualizar() -{ - moverEnemigo(); - counter++; - mover(); - if(counter==6) - {lanzarfuego(); - counter=0; - } +{switch(opcion) + { case 1: + moverEnemigo(); + break; + + case 2: + moverfuego(); + break; + default: + moverEnemigo(); + moverfuego(); + break; + } } diff --git a/mainwindow.h b/mainwindow.h index 0c1f386..65c7fdd 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -37,7 +37,6 @@ class MainWindow : public QMainWindow //QList muros; QList muros; QList piedras; - QList cuerpos; private slots: @@ -60,17 +59,13 @@ private slots: //PARTÍCULA QTimer *timer; QLabel *label; - Particula *cuerpo; //OBJETOS Personaje *enemigo1; - Personaje *totem; Personaje *personaje1; Personaje *personaje2; - Personaje *lanzador; - Objeto *puerta; + Particula *bolafuego; Objeto *bolaH; - Objeto *bolaFuego; Objeto *llave; QObject *personaje; Objeto *boton; @@ -81,14 +76,19 @@ private slots: double y; int opcion=0; int nivel=0; - int i=0; int rigidez=0; int friccion=0; int counter=0; + int xmenor=0; + int xmayor=0; + int ymenor=0; + int ymayor=0; + int path=0; + bool ban=false; + bool ban2=false; + bool visible; //____ prueba - Particula *particula1; - Particula *particula2; void keyPressEvent(QKeyEvent * evento); @@ -102,15 +102,9 @@ private slots: void teletransportacion(); - int path=0; - - bool ban=false; - - bool visible; - - void mover(); + void moverfuego(); - void lanzarfuego(); + //void lanzarfuego(); void moverEnemigo(); From 4553a0e5c8cdcf61b3abd6bc2007208cfff11b13 Mon Sep 17 00:00:00 2001 From: saraycubillos <62775794+saraycubillos@users.noreply.github.com> Date: Mon, 3 Aug 2020 18:48:28 -0500 Subject: [PATCH 7/7] Se agregan las instrucciones, herencia,archivos --- instrucciones.cpp | 14 + instrucciones.h | 22 + instrucciones.ui | 69 ++ llaves.cpp | 9 +- llaves.h | 2 + lose.cpp | 14 + lose.h | 22 + lose.ui | 46 ++ mainwindow.cpp | 1656 ++++++++++++++++++++++++++++++++------------- mainwindow.h | 87 ++- mainwindow.ui | 48 ++ objeto.cpp | 80 +++ objeto.h | 34 + particula.cpp | 51 +- particula.h | 30 +- registro.cpp | 108 +++ registro.h | 42 ++ registro.ui | 140 ++++ timer.cpp | 32 + timer.h | 23 + usuario.cpp | 95 +++ usuario.h | 40 ++ verificar.cpp | 106 +++ verificar.h | 51 ++ verificar.ui | 101 +++ vidas.cpp | 6 + vidas.h | 2 + win.cpp | 14 + win.h | 22 + win.ui | 36 + 30 files changed, 2449 insertions(+), 553 deletions(-) create mode 100644 instrucciones.cpp create mode 100644 instrucciones.h create mode 100644 instrucciones.ui create mode 100644 lose.cpp create mode 100644 lose.h create mode 100644 lose.ui create mode 100644 mainwindow.ui create mode 100644 objeto.cpp create mode 100644 objeto.h create mode 100644 registro.cpp create mode 100644 registro.h create mode 100644 registro.ui create mode 100644 timer.cpp create mode 100644 timer.h create mode 100644 usuario.cpp create mode 100644 usuario.h create mode 100644 verificar.cpp create mode 100644 verificar.h create mode 100644 verificar.ui create mode 100644 win.cpp create mode 100644 win.h create mode 100644 win.ui diff --git a/instrucciones.cpp b/instrucciones.cpp new file mode 100644 index 0000000..9038f78 --- /dev/null +++ b/instrucciones.cpp @@ -0,0 +1,14 @@ +#include "instrucciones.h" +#include "ui_instrucciones.h" + +Instrucciones::Instrucciones(QWidget *parent) : + QDialog(parent), + ui(new Ui::Instrucciones) +{ + ui->setupUi(this); +} + +Instrucciones::~Instrucciones() +{ + delete ui; +} diff --git a/instrucciones.h b/instrucciones.h new file mode 100644 index 0000000..72d1694 --- /dev/null +++ b/instrucciones.h @@ -0,0 +1,22 @@ +#ifndef INSTRUCCIONES_H +#define INSTRUCCIONES_H + +#include + +namespace Ui { +class Instrucciones; +} + +class Instrucciones : public QDialog +{ + Q_OBJECT + +public: + explicit Instrucciones(QWidget *parent = 0); + ~Instrucciones(); + +private: + Ui::Instrucciones *ui; +}; + +#endif // INSTRUCCIONES_H diff --git a/instrucciones.ui b/instrucciones.ui new file mode 100644 index 0000000..d3fb526 --- /dev/null +++ b/instrucciones.ui @@ -0,0 +1,69 @@ + + + Instrucciones + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 15 + 10 + 371 + 281 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">INSTRUCCIONES</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">INTRODUCCIÓN</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Escape medieval es un juego en el que se pueden participar 1 ó 2 jugadores .</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Los hechos se desarrollan en el castillo Alcázar de Segovia cuando un excéntrico aventurero trata de investigar este templo medieval , allí bajo un extraño acontecimiento se pierde en su interior , por lo tanto debe reunír todas las llaves para poder escapar mientras enfrenta a los monstruos que hay en su interior.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">COMO JUGAR </p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">El jugador debe eleigr un nombre , una contraseña y un modo de juego (multi jugador ó un solo jugador)</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Al registrarse deberá acceder .</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Para mover al personaje 1 , use las las teclas :</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">A= IZQUIERDA</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">D=DERECHA</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">W=ARRIBA</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">S=ABAJO</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Para mover al personaje 2 , use las teclas :</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">J=IZQUIERDA</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">L=DERECHA</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">I=ARRIBA</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">K=ABAJO</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Para un solo jugador :</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Capture todas las llaves para desbloquear la puerta final</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">En modo multijugador :</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Capture todas las llaves para desbloquear la puerta final en un tiempo máximo de 5 minutos</p></body></html> + + + + + + diff --git a/llaves.cpp b/llaves.cpp index ee98b11..4874abc 100644 --- a/llaves.cpp +++ b/llaves.cpp @@ -9,7 +9,7 @@ llaves::llaves(QGraphicsItem *parent): QGraphicsTextItem(parent) //ESCRIBIR EL TEXTO setPlainText(QString("Llaves: ")+QString::number(key)); - setDefaultTextColor(Qt::black); + setDefaultTextColor(Qt::red); setFont(QFont("times",16)); } @@ -18,9 +18,16 @@ void llaves::increase() { key++; setPlainText(QString("Llaves: ")+QString::number(key)); + } int llaves::getkey() { return key; } + +void llaves::setKey(int value) +{ + key = value; + setPlainText(QString("Llaves: ")+QString::number(key)); +} diff --git a/llaves.h b/llaves.h index e54e5c3..67aa3ff 100644 --- a/llaves.h +++ b/llaves.h @@ -13,6 +13,8 @@ class llaves: public QGraphicsTextItem void increase(); int getkey(); + void setKey(int value); + private: int key; diff --git a/lose.cpp b/lose.cpp new file mode 100644 index 0000000..0e1eeb7 --- /dev/null +++ b/lose.cpp @@ -0,0 +1,14 @@ +#include "lose.h" +#include "ui_lose.h" + +Lose::Lose(QWidget *parent) : + QDialog(parent), + ui(new Ui::Lose) +{ + ui->setupUi(this); +} + +Lose::~Lose() +{ + delete ui; +} diff --git a/lose.h b/lose.h new file mode 100644 index 0000000..0c8de67 --- /dev/null +++ b/lose.h @@ -0,0 +1,22 @@ +#ifndef LOSE_H +#define LOSE_H + +#include + +namespace Ui { +class Lose; +} + +class Lose : public QDialog +{ + Q_OBJECT + +public: + explicit Lose(QWidget *parent = 0); + ~Lose(); + +private: + Ui::Lose *ui; +}; + +#endif // LOSE_H diff --git a/lose.ui b/lose.ui new file mode 100644 index 0000000..4d94207 --- /dev/null +++ b/lose.ui @@ -0,0 +1,46 @@ + + + Lose + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 10 + 10 + 371 + 271 + + + + + + + 60 + 110 + 256 + 61 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:28pt;">PERDISTE</span></p></body></html> + + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index 4a7aaca..91af976 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,43 +7,71 @@ MainWindow::MainWindow(QWidget *parent) { //intro->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/fantasy.mp3")); +ui->setupUi(this); +scene = new QGraphicsScene; +ui->graphicsView->setScene(scene); +if(llavesL.size()==0) +{llavesL.push_back(new Objeto (-65,220,30,":/I/I/llave1.png")); + scene->addItem(llavesL.back()); +llavesL.push_back(new Objeto (470,35,30,":/I/I/llave1.png")); + scene->addItem(llavesL.back()); +llavesL.push_back(new Objeto (480,45,30,":/I/I/llave1.png")); + scene->addItem(llavesL.back()); +llavesL.push_back(new Objeto (490,55,30,":/I/I/llave1.png")); + scene->addItem(llavesL.back()); +llavesL.push_back(new Objeto (10,100,30,":/I/I/llave1.png")); + scene->addItem(llavesL.back()); +llavesL.push_back(new Objeto (460,25,30,":/I/I/llave1.png")); + scene->addItem(llavesL.back()); +} +for (int i=0;ihide(); + + } +niveles(opcion,jugadores); -niveles(opcion); -//-----------------------------BOTÓN START--------------------------- +//--------------------BOTÓN INICIAR JUEGO NUEVO---------------------- -start=new QPushButton("INICIAR JUEGO", this); +start=new QPushButton("INICIAR JUEGO NUEVO", this); start->setGeometry(QRect( QPoint(310,160), // Valores por defecto 250x160 QSize(200, 50) )); //Valores por defecto : 200x 50 -connect(start, SIGNAL (clicked()),this, SLOT (botonInicio())); +connect(start, SIGNAL (clicked()),this, SLOT (Iniciar())); start->setStyleSheet("background-color: gray"); +//-----------------------BOTÓN INSTRUCCIONES------------------ + +instruccion=new QPushButton (" INSTRUCCIONES ",this); + +instruccion->setGeometry(QRect( QPoint(310,300), +QSize(200, 50) )); + +connect(instruccion, SIGNAL (clicked()),this, SLOT (instrucciones())); +instruccion->setStyleSheet("background-color: gray"); -//-----------------------------BOTÓN CONTINUAR PARTIDA------------------ -continuarPartida=new QPushButton ("CONTINUAR PARTIDA ",this); +//-----------------------------BOTÓN REGISTRO ------------------ -continuarPartida->setGeometry(QRect( QPoint(310,300), +registrar=new QPushButton ("REGISTRARSE",this); + +registrar->setGeometry(QRect( QPoint(310,450), QSize(200, 50) )); -connect(continuarPartida, SIGNAL (clicked()),this, SLOT (continuar())); -continuarPartida->setStyleSheet("background-color: gray"); +connect(registrar, SIGNAL (clicked()),this, SLOT (registro())); +registrar ->setStyleSheet("background-color: gray"); -//-----------------------------BOTÓN GUARDAR JUEGO ------------------ +//-----------------------------BOTÓN GUARDADO ------------------ -guardar=new QPushButton ("GUARDAR PARTIDA",this); +save=new QPushButton ("GUARDAR PARTIDA",this); -guardar->setGeometry(QRect( QPoint(0,0), +save->setGeometry(QRect( QPoint(0,0), QSize(200, 50) )); -connect(guardar, SIGNAL (clicked()),this, SLOT (continuar())); -guardar ->setStyleSheet("background-color: red"); -/* -timer->stop(); -connect(timer,SIGNAL(timeout()),this,SLOT(actualizar())); -timer->start(dt);*/ +connect(save, SIGNAL (clicked()),this, SLOT (guardar())); +save ->setStyleSheet("background-color: gray"); @@ -518,51 +546,51 @@ if(evento->key()==Qt::Key_0) guardarPartida(); } -if(evento->key()==Qt::Key_1) +/*if(evento->key()==Qt::Key_1) { clean(); opcion=1; - niveles (opcion); + niveles (opcion,jugadores); } if(evento->key()==Qt::Key_2) { clean(); opcion=2; - niveles (opcion); + niveles (opcion,jugadores); } if(evento->key()==Qt::Key_3) { clean(); opcion=3; - niveles (opcion); + niveles (opcion,jugadores); } if(evento->key()==Qt::Key_4) { clean(); opcion=4; - niveles (opcion); + niveles (opcion,jugadores); } if(evento->key()==Qt::Key_5) { clean(); opcion=5; - niveles (opcion); + niveles (opcion,jugadores); } if(evento->key()==Qt::Key_6) { clean(); opcion=6; - niveles (opcion); + niveles (opcion,jugadores); } if(evento->key()==Qt::Key_7) { clean(); opcion=7; - niveles (opcion); -} + niveles (opcion,jugadores); +}*/ } -void MainWindow::coaliciones(char letra , Personaje *personaje) +void MainWindow::coaliciones(char letra , Objeto *personaje) { /*if(vida->getlife()==0) @@ -583,26 +611,41 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) //---------------------------GIRO DEL PERSONAJE1 (A)------------------------------ - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(180); - personaje1->izquierda(); + /*personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(180);*/ + personaje1->izquierda(1,1); //------------------------------COALISIONES1 (A) ---------------------------- + if (bolaH->isVisible()) + { if(personaje1->collidesWithItem(bolaH)) { - bolaH->izquierda(); + bolaH->izquierda(3,1); + } } + if (bolafuego->isVisible()) + { if(personaje1->collidesWithItem(bolafuego)) { - personaje1->derecha(); + personaje1->derecha(1,1); + vida->decrease(); + } + } + if (dragon->isVisible()) + { + if(personaje1->collidesWithItem(dragon)) + { + personaje1->derecha(1,1); vida->decrease(); } + } if(enemigo1->isVisible()) - {if(personaje1->collidesWithItem(enemigo1)) + { + if(personaje1->collidesWithItem(enemigo1)) { resorte('A', personaje1); @@ -619,13 +662,12 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) if (personaje1->collidesWithItem(muros.at(i))) { - personaje1->derecha(); + personaje1->derecha(1,1); } } } - //--------------------EVALUAR COALISIONES CON PIEDRAS 1(A)-------------------- for (int i=0;icollidesWithItem(piedras.at(i))) { - personaje1->derecha(); + personaje1->derecha(1,1); } } } //--------------------------CAPTURAR LLAVES 1(A)------------------------------- - if(llave->isVisible()) - { - if (personaje1->collidesWithItem(llave)) - { + //key->play(); - keys->increase(); - llave->hide(); - } + + //llave->hide(); + + for (int i=0; icollidesWithItem(llavesL.at(i))) + if(llavesL.at(i)->isVisible()) + {{if (personaje1->collidesWithItem(llavesL.at(i))) + {scene->removeItem(llavesL.at(i)); + llavesL.removeOne(llavesL.at(i)); + keys->increase(); + } + } + } } } @@ -657,23 +706,38 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) //lanzamiento(-40,personaje1->x(),70,personaje1->y()); //--------------------------GIRO DEL PERSONAJE 1(D)--------------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(0); - personaje1->derecha(); + /*personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(0);*/ + personaje1->derecha(1,1); //---------------------------COALISIONES 1(D)---------------------------- + if (bolaH->isVisible()) + { if(personaje1->collidesWithItem(bolaH)) { - bolaH->derecha(); + bolaH->derecha(3,1); + } } + if (bolafuego->isVisible()) + { if(personaje1->collidesWithItem(bolafuego)) { - personaje1->izquierda(); + personaje1->izquierda(1,1); + vida->decrease(); + } + } + + if (dragon->isVisible()) + { + if(personaje1->collidesWithItem(dragon)) + { + personaje1->izquierda(1,1); vida->decrease(); } + } if(enemigo1->isVisible()) {if(personaje1->collidesWithItem(enemigo1)) @@ -695,7 +759,7 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) - personaje1->izquierda(); + personaje1->izquierda(1,1); } } } @@ -708,42 +772,58 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) if (personaje1->collidesWithItem(piedras.at(i))) { - personaje1->izquierda(); + personaje1->izquierda(1,1); } } } //----------------------------CAPTURAR LLAVES 1(D)---------------------------------- - if(llave->isVisible()) - { - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - keys->increase(); - llave->hide(); + for (int i=0; iisVisible()) + {{if (personaje1->collidesWithItem(llavesL.at(i))) + {scene->removeItem(llavesL.at(i)); + llavesL.removeOne(llavesL.at(i)); + keys->increase(); + } } } } if (letra=='W') { //-------------------------GIRO DE PERSONAJE 1(W)----------------------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(270); - personaje1->subir(); + /*personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(270);*/ + personaje1->subir(1,1); //----------------------------COALISIONES 1(W)-------------------------------- + if (bolaH->isVisible()) + { if(personaje1->collidesWithItem(bolaH)) { - bolaH->subir(); + bolaH->subir(3,1); + } } + if (bolafuego->isVisible()) + { if(personaje1->collidesWithItem(bolafuego)) { - personaje1->bajar(); + personaje1->bajar(1,1); vida->decrease(); } + } + + if (dragon->isVisible()) + { + if(personaje1->collidesWithItem(dragon)) + { + personaje1->bajar(1,1); + vida->decrease(); + } + } + if(enemigo1->isVisible()) {if(personaje1->collidesWithItem(enemigo1)) @@ -752,6 +832,7 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) vida->decrease(); } } + //----------------EVALUAR COALISIONES CON MUROS 1(W))----------------------- for (int i=0;icollidesWithItem(muros.at(i))) { - personaje1->bajar(); + personaje1->bajar(1,1); } } } @@ -772,41 +853,56 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) if (personaje1->collidesWithItem(piedras.at(i))) { - personaje1->bajar(); + personaje1->bajar(1,1); } } } //-----------------------------CAPTURAR LLAVES 1(W)---------------------------- - if(llave->isVisible()) - { - if (personaje1->collidesWithItem(llave)) - { - //key->play(); - keys->increase(); - llave->hide(); + for (int i=0; iisVisible()) + {{if (personaje1->collidesWithItem(llavesL.at(i))) + {scene->removeItem(llavesL.at(i)); + llavesL.removeOne(llavesL.at(i)); + keys->increase(); + } } } } if (letra=='S') { //---------------------------GIRO DE PERSONAJE 1(S)--------------------------- - personaje1->setTransformOriginPoint(0,0); - personaje1->setRotation(90); - personaje1->bajar(); + /*personaje1->setTransformOriginPoint(0,0); + personaje1->setRotation(90);*/ + personaje1->bajar(1,1); //------------------------------COALISIONES 1(S)----------------------------- + if (bolaH->isVisible()) + { if(personaje1->collidesWithItem(bolaH)) { - bolaH->bajar(); + bolaH->bajar(3,1); + } } + if (bolafuego->isVisible()) + { if(personaje1->collidesWithItem(bolafuego)) { - personaje1->subir(); + personaje1->subir(1,1); vida->decrease(); } + } + + if (dragon->isVisible()) + { + if(personaje1->collidesWithItem(dragon)) + { + personaje1->subir(1,1); + vida->decrease(); + } + } if(enemigo1->isVisible()) {if(personaje1->collidesWithItem(enemigo1)) @@ -823,7 +919,7 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) if (personaje1->collidesWithItem(muros.at(i))) { - personaje1->subir(); + personaje1->subir(1,1); } } } @@ -836,20 +932,21 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) if (personaje1->collidesWithItem(piedras.at(i))) { - personaje1->subir(); + personaje1->subir(1,1); } } } //--------------------------CAPTURAR LLAVES 1(S)------------------------- - if(llave->isVisible()) - {if (personaje1->collidesWithItem(llave)) - { - //key->play(); + for (int i=0; iisVisible()) + {{if (personaje1->collidesWithItem(llavesL.at(i))) + {scene->removeItem(llavesL.at(i)); + llavesL.removeOne(llavesL.at(i)); keys->increase(); - llave->hide(); - } - } + } + } + } } @@ -863,23 +960,38 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) if (letra=='I') { //-------------------GIRO DE PERSONAJE 2(I)------------------- - personaje2->setTransformOriginPoint(0,0); - personaje2->setRotation(270); - personaje2->subir(); + /*personaje2->setTransformOriginPoint(0,0); + personaje2->setRotation(270);*/ + personaje2->subir(1,1); //--------------------------COALISIONES 2(I)------------------------ + if (bolaH->isVisible()) + { if(personaje2->collidesWithItem(bolaH)) { - bolaH->subir(); + bolaH->subir(3,1); + } } + if (bolafuego->isVisible()) + { if(personaje2->collidesWithItem(bolafuego)) { - personaje2->bajar(); + personaje2->bajar(1,1); + vida->decrease(); + } + } + + if (dragon->isVisible()) + { + if(personaje2->collidesWithItem(dragon)) + { + personaje2->bajar(1,1); vida->decrease(); } + } if(enemigo1->isVisible()) {if(personaje2->collidesWithItem(enemigo1)) @@ -897,29 +1009,36 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { if (personaje2->collidesWithItem(muros.at(i))) { - personaje2->bajar(); + personaje2->bajar(1,1); } } } + //-------------------------------EVALUAR COALISIONES CON PIEDRAS 2(I)-------------- + //qDebug() <<"Personaje 2 visible"<isVisible()) + { if (personaje2->collidesWithItem(piedras.at(i))) { - personaje2->bajar(); + personaje2->bajar(1,1); + } } } //------------------------------------CAPTURAR LLAVES 2(I)-------------------- - if(llave->isVisible()) - {if (personaje2->collidesWithItem(llave)) - { - //key->play(); - keys->increase(); - llave->hide(); + for (int i=0; iisVisible()) + {{if (personaje2->collidesWithItem(llavesL.at(i))) + {scene->removeItem(llavesL.at(i)); + llavesL.removeOne(llavesL.at(i)); + keys->increase(); + } } } } @@ -927,23 +1046,38 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) if (letra=='J') { //---------GIRO DEL PERSONAJE------- - personaje2->setTransformOriginPoint(0,0); - personaje2->setRotation(180); - personaje2->izquierda(); + /*personaje2->setTransformOriginPoint(0,0); + personaje2->setRotation(180);*/ + personaje2->izquierda(1,1); //------------------------COALISIONES 2(J)---------------------------------- + if (bolaH->isVisible()) + { if(personaje2->collidesWithItem(bolaH)) { - bolaH->izquierda(); + bolaH->izquierda(3,1); + } } + if (bolafuego->isVisible()) + { if(personaje2->collidesWithItem(bolafuego)) { - personaje2->derecha(); + personaje2->derecha(1,1); vida->decrease(); } + } + + if (dragon->isVisible()) + { + if(personaje2->collidesWithItem(dragon)) + { + personaje2->derecha(1,1); + vida->decrease(); + } + } if(enemigo1->isVisible()) {if(personaje2->collidesWithItem(enemigo1)) @@ -961,7 +1095,7 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { if (personaje2->collidesWithItem(muros.at(i))) { - personaje2->derecha(); + personaje2->derecha(1,1); } } } @@ -969,44 +1103,63 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) for (int i=0;iisVisible()) + { if (personaje2->collidesWithItem(piedras.at(i))) { - personaje2->derecha(); + personaje2->derecha(1,1); + } } } //----------------------------CAPTURAR LLAVES 2(J)----------------------- - if(llave->isVisible()) - {if (personaje2->collidesWithItem(llave)) - { - //key->play(); - keys->increase(); - llave->hide(); - } - } + for (int i=0; iisVisible()) + {{if (personaje2->collidesWithItem(llavesL.at(i))) + {scene->removeItem(llavesL.at(i)); + llavesL.removeOne(llavesL.at(i)); + keys->increase(); + } + } + } } if (letra=='L') { //---------GIRO DEL PERSONAJE------- - personaje2->setTransformOriginPoint(0,0); - personaje2->setRotation(0); - personaje2->derecha(); + /*personaje2->setTransformOriginPoint(0,0); + personaje2->setRotation(0);*/ + personaje2->derecha(1,1); //-------------------------------COALISIONES 2(L) -------------------------------- + if (bolaH->isVisible()) + { if(personaje2->collidesWithItem(bolaH)) { - bolaH->derecha(); + bolaH->derecha(3,1); + } } + if (bolafuego->isVisible()) + { if(personaje2->collidesWithItem(bolafuego)) { - personaje2->izquierda(); + personaje2->izquierda(1,1); + vida->decrease(); + } + } + + if (dragon->isVisible()) + { + if(personaje2->collidesWithItem(dragon)) + { + personaje2->izquierda(1,1); vida->decrease(); } + } if(enemigo1->isVisible()) {if(personaje2->collidesWithItem(enemigo1)) @@ -1023,7 +1176,7 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) { if (personaje2->collidesWithItem(muros.at(i))) { - personaje2->izquierda(); + personaje2->izquierda(1,1); } } } @@ -1031,42 +1184,62 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) for (int i=0;iisVisible()) + { if (personaje2->collidesWithItem(piedras.at(i))) { - personaje2->izquierda(); + personaje2->izquierda(1,1); } } + } + //------------------------------CAPTURAR LLAVES 2(L)-------------------------------- - if(llave->isVisible()) - {if (personaje2->collidesWithItem(llave)) - { - //key->play(); - keys->increase(); - llave->hide(); + for (int i=0; iisVisible()) + {{if (personaje2->collidesWithItem(llavesL.at(i))) + {scene->removeItem(llavesL.at(i)); + llavesL.removeOne(llavesL.at(i)); + keys->increase(); + } } } } if (letra=='K') { //---------------------------------GIRO DE PERSONAJE 2(K)---------------------- - personaje2->setTransformOriginPoint(0,0); - personaje2->setRotation(90); - personaje2->bajar(); + /*personaje2->setTransformOriginPoint(0,0); + personaje2->setRotation(90);*/ + personaje2->bajar(1,1); //----------------------------------COALISIONES 2(K)-------------------------------- + if (bolaH->isVisible()) + { if(personaje2->collidesWithItem(bolaH)) { - bolaH->bajar(); + bolaH->bajar(3,1); + } } + if (bolafuego->isVisible()) + { if(personaje2->collidesWithItem(bolafuego)) { - personaje2->subir(); + personaje2->subir(1,1); + vida->decrease(); + } + } + + if (dragon->isVisible()) + { + if(personaje2->collidesWithItem(dragon)) + { + personaje2->subir(1,1); vida->decrease(); } + } if(enemigo1->isVisible()) {if(personaje2->collidesWithItem(enemigo1)) @@ -1082,246 +1255,581 @@ void MainWindow::coaliciones(char letra , Personaje *personaje) if (muros.at(i)->isVisible()) { if (personaje2->collidesWithItem(muros.at(i))) - {personaje2->subir(); + {personaje2->subir(1,1); } } } //-----------------------------EVALUAR COALISIONES CON PIEDRAS 2(K)---------------------- for (int i=0;iisVisible()) { if (personaje2->collidesWithItem(piedras.at(i))) { - personaje2->subir(); + personaje2->subir(1,1); } } + } //-----------------------------CAPTURAR LLAVES 2(K)------------------------------------ - if(llave->isVisible()) - {if (personaje2->collidesWithItem(llave)) - { - //key->play(); + for (int i=0; iisVisible()) + {{if (personaje2->collidesWithItem(llavesL.at(i))) + {scene->removeItem(llavesL.at(i)); + llavesL.removeOne(llavesL.at(i)); keys->increase(); - llave->hide(); - - } - } + } + } + } } } } - - - - - - - //------------------------------------------------------NIVELES-------------------------------------------------- - -void MainWindow::botonInicio() +void MainWindow::registro() { - opcion=1; - niveles(opcion); + regis=new Registro(this); + regis->show(); } + void MainWindow::continuar() { - - QString l; - QFile archivo("PARTIDA.txt"); - QTextStream datosArchivo(&archivo); - if (!archivo.exists()) - { - qDebug()<<" EL ARCHIVO SELECCIONADO NO EXISTE "; - - } - if(archivo.open(QIODevice::ReadOnly | QIODevice::Text)) - { - if (!archivo.isOpen()) - { - qDebug()<<" EL ARCHIVO NO SE HA PODIDO ABRIR "; - - } - l=archivo.readAll(); - qDebug()<show(); + ban3=true; } -void MainWindow:: niveles(int opcion) + +void MainWindow::setnivel(int opcion_) { - if (opcion==0) - { + opcion=opcion_; + niveles (opcion,jugadores); +} - ui->setupUi(this); - scene = new QGraphicsScene; - ui->graphicsView->setScene(scene); +void MainWindow::SETMODO(int modoo) +{ + jugadores=modoo; + qDebug()<<"cantidad de jugadores CUANDO INICIO "<setMovie(movie); - movie->start(); - */ +void MainWindow::VIDAS(int opcion_) +{ + qDebug()<<"vidas despues de guardar"<setMovie(movie); - movie->start();*/ + vida->setLife(opcion_); +} - scene->setBackgroundBrush(QPixmap(":/I/I/MAINMENU.png")); - scene->setSceneRect(0,0,790,550); +void MainWindow::LLAVES(int opcion_) +{ + qDebug()<<"llaves despues de guardar"<setKey(opcion_); + if (keys->getkey()==6) + { + for (int i=0; iposx==175 and piedras.at(i)->posy==30) + { - //intro=new QMediaPlayer (); - //intro->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/fantasy.mp3")); + piedras.at(i)->hide(); - //intro->play(); + } + } + } +} +void MainWindow::TIEMPO(int opcion_) +{ + qDebug()<<"Tiempo después de guardar"<settime(opcion_); +} - } - if (opcion==1) - { //intro->stop(); - //key=new QMediaPlayer (); - //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); +void MainWindow::Iniciar() +{ + Verificar *verificar; + verificar=new Verificar (this); + verificar->show(); +} - //TIMER - timer= new QTimer; - connect(timer,SIGNAL(timeout()), this, SLOT (actualizar())); - timer->start(1440); +void MainWindow::guardar() +{ +arch =false; - //CREANDO LA ESCENA - ui->setupUi(this); - scene = new QGraphicsScene; - ui->graphicsView->setScene(scene); - scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); - scene->setSceneRect(0,0,400,400); + QString nivel= QString::number(opcion); + //QString nivel="7"; - personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); - scene->addItem(personaje1); + QString contrasena=user->getContrasena(); - personaje2=new Personaje(0,0,45, ":/I/I/PERSONAJE2.png"); - scene->addItem(personaje2); + QString modo=user->getModoDeJuego(); - llave= new Objeto (470,35,30,":/I/I/llave1.png"); - scene->addItem(llave); + QString usu=user->getNombre(); - enemigo1= new Personaje (475,225,60,":/I/I/ENEMIGO.png"); - scene->addItem(enemigo1); - bolafuego= new Particula (0,505,505,200,30,":/I/I/BOLADEFUEGO.png"); - scene->addItem(bolafuego); - rigidez=6; - friccion=30; - xmenor=75; - xmayor=330; + QString VIDAS=QString::number(vida->getlife()); //LLAVES,VIDAS Y TIEMPO QUE DEBE RECIBIR EL ARCHIVO - vida=new vidas(); - vida->setPos(120,35); - scene->addItem(vida); - keys=new llaves(); - keys->setPos(270,35); - scene->addItem(keys); + QString LLAVES=QString::number(keys->getkey()); - items(); + QString TIEMPO=QString::number(tiempo->gettime()); - teletransportacion(); + //user=new Usuario; + user->setNivel(nivel); + QListcont_nivel={contrasena,nivel}; - } - if (opcion==2) - { +qDebug()<<"name "<< usu<<" pass "<stop(); - //key=new QMediaPlayer (); - //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + // QFile archivo ("C:/Users/Usuario/Desktop/Nueva carpeta (2)/E-M/REGISTRO/registro.txt"); + QFile writearchivo("D:/E-MEDIEVAL/E-MEDIEVAL/REGISTRO/registro.txt"); + QFile readarchivo("D:/E-MEDIEVAL/E-MEDIEVAL/REGISTRO/registro.txt"); + QFile readcambios("D:/E-MEDIEVAL/E-MEDIEVAL/REGISTRO/cambios.txt"); + QFile writecambios("D:/E-MEDIEVAL/E-MEDIEVAL/REGISTRO/cambios.txt"); + // QFile cambios1("C:/Users/Usuario/Desktop/Nueva carpeta (2)/E-M/REGISTRO/cambios.txt"); + // archivo.open(QIODevice::ReadOnly | QIODevice::Text); - /*timer= new QTimer; - connect(timer,SIGNAL(timeout()), this, SLOT (mover())); - QTimer *cronometro = new QTimer(this); - connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); - cronometro->start(1000); + writearchivo.open(QIODevice::WriteOnly | QIODevice::WriteOnly); + readarchivo.open(QIODevice::WriteOnly | QIODevice::ReadOnly); - QTimer *cronometro2 = new QTimer(this); - connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); - cronometro2->start(1000); + readcambios.open(QIODevice::ReadOnly | QIODevice::ReadOnly); + writecambios.open(QIODevice::ReadOnly | QIODevice::WriteOnly); + // cambios1.open(QIODevice::ReadOnly | QIODevice::WriteOnly); + // QTextStream datosArchivo (&archivo); + QTextStream WRITEARCHIVO (&writearchivo); + QTextStream READARCHIVO (&readarchivo); - //CREANDO LA ESCENA - ui->setupUi(this); - scene = new QGraphicsScene; - ui->graphicsView->setScene(scene); - scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); - scene->setSceneRect(0,0,400,400); + QTextStream READCAMBIOS (&readcambios); + QTextStream WRITECAMBIOS (&writecambios); - personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); - scene->addItem(personaje1); - personaje2=new Personaje(0,0,45, ":/I/I/PERSONAJE2.png"); - scene->addItem(personaje2); + //QString linea= CAMBIOS.readLine(); + while (!READCAMBIOS.atEnd()) + { - llave= new Objeto (470,35,30,":/I/I/llave1.png"); - scene->addItem(llave);*/ + READCAMBIOS>>ArchivoUsuario>>passArchivo>>nivelUsuario>>mode>>Vidas>>Llaves>>Tiempo; - bolaH->hide(); - enemigo1->setPos(500,500); - dragon= new Objeto (305,180,60,":/I/I/dragon.png"); - scene->addItem(dragon); - bolafuego->setPos(305,180); + //qDebug()<<"name "<< ArchivoUsuario<<" pass "<>ArchivoUsuario1>>passArchivo1>>nivelUsuario1>>mode1>>vidas1>>llaves1>>tiempo1>>endl; + if (usu==ArchivoUsuario1) + { + WRITECAMBIOS<> registro; + registro[usu]=cont_nivel; + escribir<stop(); - //key=new QMediaPlayer (); - //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + QMessageBox::Cancel);*/ - /*timer= new QTimer; - connect(timer,SIGNAL(timeout()), this, SLOT (mover())); - QTimer *cronometro = new QTimer(this); - connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); + } +} + +void MainWindow::guardarPartida() +{ + QString level, R; + + + level=QString::number(opcion); + QFile archivo("PARTIDA.txt"); + if(archivo.open(QIODevice::Append | QIODevice::Text)){ + QTextStream datosArchivo(&archivo); + + + datosArchivo << level<< endl; + + } + archivo.close(); +} + +void MainWindow::setUser(Usuario *value) +{ + user = value; +} + +void MainWindow::ganar() +{ + Win *gana; + gana=new Win (this); + gana->show(); + arch =false; + ReinicioDEnivel(); + + +} + +void MainWindow::ReinicioDEnivel() +{ + arch=false; + QString nivel= QString::number(opcion); + //QString nivel="7"; + + QString contrasena=user->getContrasena(); + + QString modo=user->getModoDeJuego(); + + QString usu=user->getNombre(); + + qDebug()<<"modo"<getlife()); //LLAVES Y VIDAS QUE DEBE RECIBIR EL ARCHIVO + + QString LLAVES=QString::number(keys->getkey()); + + //user=new Usuario; + user->setNivel(nivel); + + QListcont_nivel={contrasena,nivel}; + +//qDebug()<<"name "<< usu<<" pass "<>ArchivoUsuario>>passArchivo>>nivelUsuario>>mode>>Vidas>>Llaves; + + qDebug()<<"name "<< ArchivoUsuario<<" pass "<>ArchivoUsuario1>>passArchivo1>>nivelUsuario1>>mode1>>vidas1>>llaves1>>endl; + if (usu==ArchivoUsuario1) + { + WRITECAMBIOS<> registro; + registro[usu]=cont_nivel; + escribir<show(); +} + +void MainWindow::instrucciones() +{ + Instrucciones *instr; + instr=new Instrucciones (this); + instr->show(); + + +} + +//------------------------------------------------------NIVELES-------------------------------------------------- + +void MainWindow:: niveles(int opcion,int jugadores) +{ + if (opcion==0) + { + timer= new QTimer; + connect(timer,SIGNAL(timeout()), this, SLOT (actualizar())); + timer->start(1440); + + //..................CREANDO LA ESCENA............. + + scene->setBackgroundBrush(QPixmap(":/I/I/MAINMENU.png")); + if (opcion==0) + { + scene->setSceneRect(0,0,790,550); + + } + + // 310,300 + //LLAVE + + personaje1=new Objeto(180,410,30, ":/I/I/PERSONAJE1.png"); + scene->addItem(personaje1); + personaje1->hide(); + + personaje2=new Objeto(180,410,30, ":/I/I/PERSONAJE1.png"); + scene->addItem(personaje2); + personaje2->hide(); + + enemigo1= new Objeto (475,225,60,":/I/I/ENEMIGO.png"); + scene->addItem(enemigo1); + enemigo1->hide(); + + dragon= new Objeto (305,180,40,":/I/I/dragon.png"); + scene->addItem(dragon); + dragon->hide(); + + bolaH= new Objeto (-25,420, 30,":/I/I/BOLADEMETAL.png"); + scene->addItem(bolaH); + bolafuego= new Particula (505,505,200,30,":/I/I/BOLADEFUEGO.png"); + scene->addItem(bolafuego); + + //intro=new QMediaPlayer (); + //intro->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/fantasy.mp3")); + + + //intro->play(); + + muros.push_back(new Pared (200,-450,800,100, "")); + scene->addItem(muros.back()); + + muros.push_back(new Pared (200,150,800,100, "")); + scene->addItem(muros.back()); + + muros.push_back(new Pared (250,100,100,800, "")); + scene->addItem(muros.back()); + + muros.push_back(new Pared (-550,100,100,800, "")); + scene->addItem(muros.back()); + + for (int i=0;ihide(); + + } + + piedras.push_back(new Objeto(175,30,40,":/I/I/P1.png")); + scene->addItem(piedras.back()); + + //CANTIDAD DE VIDAS + vida=new vidas(); + vida->setLife(5); + vida->setPos(200,-90); + scene->addItem(vida); + vida->hide(); + + + //CANTIDAD DE LLAVES + keys=new llaves(); + keys->setKey(0); + keys->setPos(70,-90); + scene->addItem(keys); + + //CANTIDAD DE Tiempo + tiempo=new Timer(); + tiempo->settime(313); + tiempo->setPos(435,-90); + + } + if (opcion==1) + { + qDebug()<<"entra nivel 1"<stop(); + //key=new QMediaPlayer (); + //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + + //------------------------TIMER------------------ + //timer= new QTimer; + //connect(timer,SIGNAL(timeout()), this, SLOT (actualizar())); + //timer->start(1440); + + + scene->setSceneRect(0,0,400,400); + scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + start->hide(); + instruccion->hide(); + registrar->hide(); + + + + vida->show(); + qDebug()<<"numero de jugadores"<addItem(tiempo); + personaje2->setPos(100,410); + personaje2->show(); + } + + bolaH->hide(); + scene->addItem(vida); + scene->addItem(keys); + + personaje1->setPos(-120,420); + personaje1->show(); + + for (int i=0; igetPosx()==-65 and llavesL.at(i)->getPosy()==220) + {llavesL.at(i)->show(); + } + else + {llavesL.at(i)->hide(); + } + } + //vida->show(); + //vida->setPos(120,35); + + for (int i=0; igetPosx()==175 and piedras.at(i)->getPosy()==30) + {piedras.at(i)->hide(); + } + } + + enemigo1->setPos(475,225); + enemigo1->show(); + + dragon->setPos(305,180); + dragon->show(); + + //bolafuego= new Particula (0,505,505,200,30,":/I/I/BOLA DE FUEGO.png"); + //scene->addItem(bolafuego); + + rigidez=3; + friccion=10; + xmenor=60; + xmayor=330; + /*piedras.push_back(new Objeto(170,35,40,":/I/I/ROCAS.png")); + scene->addItem(piedras.back()); + piedras.back()->hide();*/ + + items(); + + teletransportacion(); + + + } + if (opcion==2) + { + + + + //intro->stop(); + //key=new QMediaPlayer (); + //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + + /*timer= new QTimer; + connect(timer,SIGNAL(timeout()), this, SLOT (mover())); + QTimer *cronometro = new QTimer(this); + connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); cronometro->start(1000); QTimer *cronometro2 = new QTimer(this); connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); - cronometro2->start(1000);*/ + cronometro2->start(1000); //CREANDO LA ESCENA - //ui->setupUi(this); - //scene = new QGraphicsScene; - //ui->graphicsView->setScene(scene); - /*scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); + ui->setupUi(this); + scene = new QGraphicsScene; + ui->graphicsView->setScene(scene); + scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); @@ -1332,18 +1840,144 @@ void MainWindow:: niveles(int opcion) llave= new Objeto (470,35,30,":/I/I/llave1.png"); scene->addItem(llave);*/ + scene->setSceneRect(0,0,400,400); + scene->setBackgroundBrush(QPixmap(":/I/I/HIELO.png")); + start->hide(); + instruccion->hide(); + registrar->hide(); + + bolaH->hide(); + + if(jugadores==2) + {scene->addItem(tiempo); + personaje2->setPos(100,410); + personaje2->show(); + } + + for (int i=0; igetPosx()==175 and piedras.at(i)->getPosy()==30) + {piedras.at(i)->show(); + } + else if (keys->getkey()==6) + { + qDebug()<<"LLAVES N2"<getkey(); + for (int i=0; iposx==175 and piedras.at(i)->posy==30) + { + + piedras.at(i)->hide(); + + + } + } + } + } + + personaje1->show(); + personaje1->setPos(360,420); + + enemigo1->show(); + enemigo1->setPos(500,500); + + dragon->show(); + scene->addItem(dragon); + //bolafuego->setPos(305,180); + + for (int i=0; igetPosx()==470 and llavesL.at(i)->getPosy()==35) + {llavesL.at(i)->show(); + } + else + {llavesL.at(i)->hide(); + } + } + + vida->show(); + //vida->setPos(120,35); + + keys->setPos(70,-90); + scene->addItem(keys); + + rigidez=4; + friccion=20; + ymenor=-15; + ymayor=420; + xmayor=520; + xmenor=-35; + items(); + + teletransportacion(); + + } + if (opcion==3) + { + + + + //intro->stop(); + //key=new QMediaPlayer (); + //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); + + /*timer= new QTimer; + connect(timer,SIGNAL(timeout()), this, SLOT (mover())); + QTimer *cronometro = new QTimer(this); + connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); + cronometro->start(1000); + + QTimer *cronometro2 = new QTimer(this); + connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); + cronometro2->start(1000);*/ + + scene->setSceneRect(0,0,400,400); + scene->setBackgroundBrush(QPixmap(":/I/I/H1.jpg")); + start->hide(); + instruccion->hide(); + registrar->hide(); + vida->show(); + + if(jugadores==2) + {scene->addItem(tiempo); + personaje2->setPos(100,410); + personaje2->show(); + } + + for (int i=0; igetPosx()==175 and piedras.at(i)->getPosy()==30) + { + piedras.at(i)->hide(); + } + } + + for (int i=0; igetPosx()==480 and llavesL.at(i)->getPosy()==45) + {llavesL.at(i)->show(); + } + else + {llavesL.at(i)->hide(); + } + } + + + personaje1->show(); + personaje1->setPos(-120,420); + + enemigo1->show(); enemigo1->setPos(-120,80); - dragon->setPos(520,330); - bolafuego->setPos(-20,345); + dragon->setPos(435,300); + dragon->show(); + + //bolafuego->setPos(-20,345); bolaH->hide(); /*totem= new Personaje (0,0,60,""); scene->addItem(totem); timer->start();*/ - rigidez=6; - friccion=10; + rigidez=3; + friccion=20; xmenor=-120; xmayor=520; ymayor=350; @@ -1374,23 +2008,43 @@ void MainWindow:: niveles(int opcion) //CREANDO LA ESCENA ui->setupUi(this); scene = new QGraphicsScene;*/ - ui->graphicsView->setScene(scene); - /*scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); scene->setSceneRect(0,0,400,400); + scene->setBackgroundBrush(QPixmap(":/I/I/ARENA.jpg")); + start->hide(); + instruccion->hide(); + registrar->hide(); + vida->show(); - personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); - scene->addItem(personaje1); + for (int i=0; igetPosx()==175 and piedras.at(i)->getPosy()==30) + { + piedras.at(i)->hide(); + } + } - personaje2=new Personaje(0,0,45, ":/I/I/PERSONAJE2.png"); - scene->addItem(personaje2); + for (int i=0; igetPosx()==490 and llavesL.at(i)->getPosy()==55) + {llavesL.at(i)->show(); + } + else + {llavesL.at(i)->hide(); + } + } - llave= new Objeto (470,35,30,":/I/I/llave1.png"); - scene->addItem(llave); - */ + if(jugadores==2) + {scene->addItem(tiempo); + personaje2->setPos(100,410); + personaje2->show(); + } bolaH->hide(); + enemigo1->show(); enemigo1->setPos(-120,105); - bolafuego->setPos(-20,345); + + personaje1->show(); + personaje1->setPos(180,420); + //bolafuego->setPos(-20,345); xmenor=-120; xmayor=520; ymayor=350; @@ -1405,45 +2059,63 @@ void MainWindow:: niveles(int opcion) } if (opcion==5) { - + qDebug()<<" ENTRO AL NIVEL 5"; //intro->stop(); //key=new QMediaPlayer (); //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); - /*timer= new QTimer; - connect(timer,SIGNAL(timeout()), this, SLOT (mover())); - QTimer *cronometro = new QTimer(this); - connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); - cronometro->start(1000); + scene->setSceneRect(0,0,400,400); + scene->setBackgroundBrush(QPixmap(":/I/I/L3.jpg")); - QTimer *cronometro2 = new QTimer(this); - connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); - cronometro2->start(1000); + start->hide(); + instruccion->hide(); + registrar->hide(); + vida->show(); - //CREANDO LA ESCENA - ui->setupUi(this); - scene = new QGraphicsScene; - ui->graphicsView->setScene(scene); - scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); - scene->setSceneRect(0,0,400,400); + for (int i=0; igetPosx()==175 and piedras.at(i)->getPosy()==30) + { + piedras.at(i)->hide(); + } + } - personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); - scene->addItem(personaje1); + if(jugadores==2) + {scene->addItem(tiempo); + personaje2->setPos(100,410); + personaje2->show(); + } - personaje2=new Personaje(0,0,45, ":/I/I/PERSONAJE2.png"); - scene->addItem(personaje2); + personaje1->setPos(-120,420); + personaje1->show(); - llave= new Objeto (470,35,30,":/I/I/llave1.png"); - scene->addItem(llave); - */ - bolaH->hide(); - dragon->setPos(515,325); - xmenor=-115; - xmayor=510; - ymenor=5; - ymayor=360; - rigidez=11; - friccion=40; + enemigo1->show(); + enemigo1->setPos(100,10); + bolaH->setPos(0,215); + bolaH->show(); + + bolafuego->setX(165); + + dragon->setPos(355,215); + dragon->show(); + + for (int i=0; igetPosx()==10 and llavesL.at(i)->getPosy()==100) + {llavesL.at(i)->show(); + } + else + {llavesL.at(i)->hide(); + } + } + + keys->setPos(70,-90); + scene->addItem(keys); + xmenor=55; + xmayor=320; + ymenor=110; + ymayor=370; + rigidez=3; + friccion=20; items(); teletransportacion(); @@ -1456,42 +2128,54 @@ void MainWindow:: niveles(int opcion) //key=new QMediaPlayer (); //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); - /*timer= new QTimer; - connect(timer,SIGNAL(timeout()), this, SLOT (mover())); - QTimer *cronometro = new QTimer(this); - connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); - cronometro->start(1000); + scene->setSceneRect(0,0,400,400); + scene->setBackgroundBrush(QPixmap(":/I/I/L7.png")); + start->hide(); + instruccion->hide(); + registrar->hide(); + vida->show(); - QTimer *cronometro2 = new QTimer(this); - connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); - cronometro2->start(1000); + for (int i=0; igetPosx()==175 and piedras.at(i)->getPosy()==30) + { + piedras.at(i)->hide(); + } + } - //CREANDO LA ESCENA - ui->setupUi(this); - scene = new QGraphicsScene;*/ - ui->graphicsView->setScene(scene); - /*scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); - scene->setSceneRect(0,0,400,400); + for (int i=0; igetPosx()==460 and llavesL.at(i)->getPosy()==25) + {llavesL.at(i)->show(); + } + else + {llavesL.at(i)->hide(); + } + } - personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); - scene->addItem(personaje1); + if(jugadores==2) + {scene->addItem(tiempo); + personaje2->setPos(100,410); + personaje2->show(); + } - personaje2=new Personaje(0,0,45, ":/I/I/PERSONAJE2.png"); - scene->addItem(personaje2); + personaje1->show(); + personaje1->setPos(-120,420); - llave= new Objeto (470,35,30,":/I/I/llave1.png"); - scene->addItem(llave); - */ + enemigo1->show(); enemigo1->setPos(-95,125); + + dragon->show(); dragon->setPos(445,360); - bolafuego->setPos(-5,345); + //bolafuego->setPos(-5,345); bolaH->hide(); + bolafuego->setX(95); xmenor=-120; xmayor=520; - ymenor=55; - ymayor=345; - rigidez=11; + ymenor=-45; + ymayor=410; + rigidez=6; friccion=30; + items(); teletransportacion(); @@ -1503,42 +2187,55 @@ void MainWindow:: niveles(int opcion) //key=new QMediaPlayer (); //key->setMedia(QUrl("qrc:/SONIDOS/SONIDOS/KEY.wav")); - /*timer= new QTimer; - connect(timer,SIGNAL(timeout()), this, SLOT (mover())); - QTimer *cronometro = new QTimer(this); - connect(cronometro, SIGNAL(timeout()),this,SLOT(lanzarfuego())); - cronometro->start(1000); - - QTimer *cronometro2 = new QTimer(this); - connect(cronometro2, SIGNAL(timeout()),this,SLOT(lanzamiento())); - cronometro2->start(1000); + scene->setSceneRect(0,0,400,400); + scene->setBackgroundBrush(QPixmap(":/I/I/LAVA1.png")); - //CREANDO LA ESCENA - ui->setupUi(this); - scene = new QGraphicsScene;*/ - ui->graphicsView->setScene(scene); - /*scene->setBackgroundBrush(QPixmap(":/I/I/LN1.jpg")); - scene->setSceneRect(0,0,400,400); + for (int i=0; igetPosx()==175 and piedras.at(i)->getPosy()==30) + { + piedras.at(i)->hide(); + } + } - personaje1=new Personaje(180,410,30, ":/I/I/PERSONAJE1.png"); - scene->addItem(personaje1); + start->hide(); + instruccion->hide(); + registrar->hide(); + bolaH->hide(); + vida->show(); - personaje2=new Personaje(0,0,45, ":/I/I/PERSONAJE2.png"); - scene->addItem(personaje2); + if (personaje1->x()==520 and personaje1->y()==360) //puerta derecha conexión parte de arriba + { + personaje1->setPos(520,60); + } + if (personaje1->x()==-120 and personaje1->y()==60) //puerta final + { + ganar(); + this->close(); + } - llave= new Objeto (470,35,30,":/I/I/llave1.png"); - scene->addItem(llave);*/ + if(jugadores==2) + {scene->addItem(tiempo); + personaje2->setPos(100,410); + personaje2->show(); + } enemigo1->setPos(-95,105); - dragon->setPos(410,350); - bolaH->hide(); + enemigo1->show(); + + dragon->setPos(320,355); + dragon->show(); + + personaje1->setPos(-115,350); + personaje1->show(); + xmenor=-50; xmayor=520; ymayor=350; rigidez=11; friccion=30; - items(); + items(); teletransportacion(); } @@ -1550,38 +2247,39 @@ void MainWindow::items() /* llave= new Objeto (470,35,30,":/IMAGENES/llave1.png"); scene->addItem(llave);*/ - llave->show(); - - bolaH= new Objeto (-25,420, 30,":/I/I/BOLADEMETAL.png"); - scene->addItem(bolaH); + for (int i=0;igetPosx()==200 and muros.at(i)->getPosy()==-450) + {muros.at(i)->show(); + scene->addItem(muros.at(i));} - muros.push_back(new Pared (200,-450,800,100, "")); - scene->addItem(muros.back()); + else if(muros.at(i)->getPosx()==200 and muros.at(i)->getPosy()==150) + {muros.at(i)->show(); + scene->addItem(muros.at(i));} - muros.push_back(new Pared (200,150,800,100, "")); - scene->addItem(muros.back()); + else if(muros.at(i)->getPosx()==250 and muros.at(i)->getPosy()==100) + {muros.at(i)->show(); + scene->addItem(muros.at(i));} - muros.push_back(new Pared (250,100,100,800, "")); - scene->addItem(muros.back()); + else if(muros.at(i)->getPosx()==-550 and muros.at(i)->getPosy()==100) + {muros.at(i)->show(); + scene->addItem(muros.at(i));} - muros.push_back(new Pared (-550,100,100,800, "")); - scene->addItem(muros.back()); + else + {muros.at(i)->hide();} + } if (opcion==1) { - piedras.push_back(new Objeto(-120,305,40,":/I/I/P1.png")); + piedras.push_back(new Objeto(-100,320,40,":/I/I/P1.png")); scene->addItem(piedras.back()); - piedras.push_back(new Objeto(-30,275,40,":/I/I/P1.png")); + piedras.push_back(new Objeto(-15,290,40,":/I/I/P1.png")); scene->addItem(piedras.back()); - piedras.push_back(new Objeto(-10,180,40,":/I/I/P1.png")); + piedras.push_back(new Objeto(0,200,40,":/I/I/P1.png")); scene->addItem(piedras.back()); - piedras.push_back(new Objeto(-50,105,40,":/I/I/P1.png")); - scene->addItem(piedras.back()); - - piedras.push_back(new Objeto(-120,85,40,":/I/I/P1.png")); + piedras.push_back(new Objeto(-50,120,40,":/I/I/P1.png")); scene->addItem(piedras.back()); muros.push_back(new Pared (-350,50,50,800, ":/I/I/rocas2.png")); //muro vertical @@ -1595,6 +2293,12 @@ void MainWindow::items() muros.push_back(new Pared (-500,-10,50,30, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 4 ancho alto scene->addItem(muros.back()); + + muros.push_back(new Pared (150,-160,50,30, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 2 arriba ancho alto conex n 2 + scene->addItem(muros.back()); + + muros.push_back(new Pared (150,-250,50,30, ":/I/I/BLOQUE.jpg")); //puerta conexion nivel 3 abajo ancho alto conex nivel 2 + scene->addItem(muros.back()); } if (opcion==2) @@ -1613,6 +2317,14 @@ void MainWindow::items() muros.push_back(new Pared (-500,-230,50,20, ":/I/I/BLOQUE.jpg")); //derecha abajo scene->addItem(muros.back()); + + for (int i=0;ix()==170 and piedras.at(i)->y()==35) + { + piedras.at(i)->show(); + } + } } if (opcion==3) @@ -1745,32 +2457,16 @@ void MainWindow::items() muros.push_back(new Pared (-500,-390,50,20, ":/I/I/BLOQUE.jpg")); //puerta primera parte derecha (abajo) scene->addItem(muros.back()); } + } void MainWindow::clean() { for (int i=0;iremoveItem(piedras.at(i)); piedras.at(i)->hide(); - //delete (piedras.at (i)); - // piedras.removeOne(piedras.at(i)); - - - } - - for (int i=0;ihide(); - //scene->removeItem(muros.at(i)); - - //delete (muros.at (i)); - //muros.removeOne(muros.at(i)); - } - /*scene->removeItem(puerta); - delete (puerta);*/ } @@ -1780,20 +2476,33 @@ void MainWindow::teletransportacion() { if (personaje1->x()==170 and personaje1->y()==-20) //puerta arriba //conexion nivel 5 { + clean(); + opcion=5; - niveles(opcion); + niveles(opcion, jugadores); personaje1->setPos(170,345); - + personaje2->setPos(115,350); } if (personaje1->x()==520 and personaje1->y()==-20) //puerta arriba //conexion nivel 4 { clean(); opcion=4; - niveles(opcion); + niveles(opcion,jugadores); personaje1->setPos(-80,-20); + personaje2->setPos(-55,-20); } + if (personaje1->x()==-120 and personaje1->y()==220) + { + + clean(); + opcion=6; + niveles(opcion,jugadores); + personaje1->setPos(455,250); + } + + } if (opcion==2) @@ -1803,21 +2512,25 @@ void MainWindow::teletransportacion() { clean(); opcion=7; - niveles(opcion); + niveles(opcion,jugadores); + personaje1->setPos(-115,350); + personaje2->setPos(-10,335); } if (personaje1->x()==520 and personaje1->y()==200) //puerta izquierda //conexion nivel 5 { clean(); opcion=5; - niveles(opcion); + niveles(opcion,jugadores); personaje1->setPos(-65,215); + personaje2->setPos(-50,320); } - if (personaje1->x()==-120 and personaje1->y()==420) //puerta abajo //conexion nivel 1 + if (personaje1->x()==-120 and personaje1->y()==420) //puerta abajo //conexion nivel 6 { clean(); opcion=6; - niveles(opcion); - personaje1->setPos(-120,25); + niveles(opcion,jugadores); + personaje1->setPos(-120,5); + personaje2->setPos(-60,30); } /*if (personaje1->x()==520 and personaje1->y()==200) //puerta derecha //conexion nivel 3 { @@ -1833,15 +2546,17 @@ void MainWindow::teletransportacion() { clean(); opcion=5; - niveles(opcion); + niveles(opcion,jugadores); personaje1->setPos(455,205); + personaje2->setPos(375,205); } if (personaje1->x()==485 and personaje1->y()==420) //puerta izquierda //conexion nivel 4 { clean(); opcion=4; - niveles(opcion); + niveles(opcion,jugadores); personaje1->setPos(280,20); + personaje2->setPos(350,-20); } } @@ -1853,15 +2568,16 @@ void MainWindow::teletransportacion() { clean(); opcion=1; - niveles(opcion); + niveles(opcion,jugadores); personaje1->setPos(515,-20); + personaje2->setPos(430,-20); } if (personaje1->x()==280 and personaje1->y()==-20) //puerta arriba //conexion nivel 3 { clean(); opcion=3; - niveles(opcion); + niveles(opcion,jugadores); personaje1->setPos(475,360); } @@ -1875,24 +2591,27 @@ void MainWindow::teletransportacion() { clean(); opcion=1; - niveles(opcion); + niveles(opcion,jugadores); personaje1->setPos(155,45); + personaje2->setPos(105,40); } if (personaje1->x()==520 and personaje1->y()==200) //puerta derecha//conexion nivel 3 { clean(); opcion=3; - niveles(opcion); + niveles(opcion,jugadores); personaje1->setPos(-70,220); + personaje2->setPos(-70,305); } if (personaje1->x()==-120 and personaje1->y()==220) //puerta izquierda //conexion nivel 2 { clean(); opcion=2; - niveles(opcion); + niveles(opcion,jugadores); personaje1->setPos(460,205); + personaje2->setPos(470,115); } @@ -1905,53 +2624,43 @@ void MainWindow::teletransportacion() { clean(); opcion=1; - niveles(opcion); - //personaje1->setPos(515,-20); + niveles(opcion,jugadores); + personaje1->setPos(-110,220); + personaje2->setPos(-70,220); } if (personaje1->x()==-120 and personaje1->y()==-15) //puerta arriba //conexion nivel 2 { clean(); opcion=2; - niveles(opcion); + niveles(opcion,jugadores); personaje1->setPos(-115,355); } } if (opcion==7) { - if (personaje1->x()==520 and personaje1->y()==360) //puerta derecha conex nivel 1 + if (personaje1->x()==520 and personaje1->y()==360) //puerta derecha conexión parte de arriba { - clean(); + personaje1->setPos(520,60); } + if (personaje1->x()==-120 and personaje1->y()==60) //puerta final + { - } - -} - - -void MainWindow::guardarPartida() -{ - QString level, R; - + ganar(); + this->close(); - level=QString::number(opcion); - QFile archivo("PARTIDA.txt"); - if(archivo.open(QIODevice::Append | QIODevice::Text)){ - QTextStream datosArchivo(&archivo); + } - datosArchivo << level<< endl; + } - } - archivo.close(); } - //--------------------------------------------------FISICAS-------------------------------------------------- @@ -1998,29 +2707,32 @@ void MainWindow::moverfuego() if(ban2==false) {bolafuego->setY(bolafuego->y()+2*friccion*M*G); if(bolafuego->y()>=ymayor) - {ban2=true; - } + {ban2=true;} + if(bolaH->collidesWithItem(bolafuego)) + {ban2=true;} } if(ban2==true) {bolafuego->setY(bolafuego->y()-2*friccion*M*G); if(bolafuego->y()<=ymenor) {ban2=false; } + if(bolaH->collidesWithItem(bolafuego)) + {ban2=false;} } if(personaje1->collidesWithItem(bolafuego)) { vida->decrease(); - personaje1->subir(); + personaje1->subir(1,1); } if(personaje2->collidesWithItem(bolafuego)) { vida->decrease(); - personaje2->subir(); + personaje2->subir(1,1); } } -void MainWindow::resorte(char letra , Personaje *personaje) +void MainWindow::resorte(char letra , Objeto *personaje) { if (personaje==personaje1) { @@ -2060,24 +2772,26 @@ void MainWindow::moverEnemigo( ) if(ban==false) {enemigo1->setX(enemigo1->x()+2*friccion*M*G); if(enemigo1->x()>=xmayor) - {ban=true; - } + {ban=true;} + if(bolaH->collidesWithItem(enemigo1)) + {ban=true;} } if(ban==true) {enemigo1->setX(enemigo1->x()-2*friccion*M*G); if(enemigo1->x()<=xmenor) - {ban=false; - } + {ban=false;} + if(bolaH->collidesWithItem(bolafuego)) + {ban=false;} } if(personaje1->collidesWithItem(enemigo1)) { vida->decrease(); - personaje1->derecha(); + personaje1->derecha(1,1); } if(personaje2->collidesWithItem(enemigo1)) { vida->decrease(); - personaje2->derecha(); + personaje2->derecha(1,1); } } @@ -2096,14 +2810,20 @@ void MainWindow::actualizar() {switch(opcion) { case 1: moverEnemigo(); + if(jugadores==2) + {tiempo->decrease();} break; case 2: moverfuego(); + if(jugadores==2) + {tiempo->decrease();} break; default: moverEnemigo(); moverfuego(); + if(jugadores==2) + {tiempo->decrease();} break; } } diff --git a/mainwindow.h b/mainwindow.h index 65c7fdd..d5aea30 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -20,6 +20,14 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; @@ -37,20 +45,51 @@ class MainWindow : public QMainWindow //QList muros; QList muros; QList piedras; + QList llavesL; + + void setnivel(int opcion_); + + void VIDAS(int opcion_); + + void LLAVES(int opcion_); + + void TIEMPO(int opcion_); + + void SETMODO(int modoo); + + void setUser(Usuario *value); private slots: void continuar(); - void botonInicio(); + //void botonInicio(); void actualizar(); + void Iniciar(); + + void registro(); + + void guardar(); + + void ganar(); + + void instrucciones(); + + void ReinicioDEnivel(); + + void perder(); + private: Ui::MainWindow *ui; QGraphicsScene *scene; + //TIPO VENTANAS + Usuario *user; + Registro *regis; + //SONIDOS //QMediaPlayer *key; //QMediaPlayer *intro; @@ -60,18 +99,42 @@ private slots: QTimer *timer; QLabel *label; + //-------BOTONES + QPushButton *start; + QPushButton *instruccion; + QPushButton *save; + QLineEdit *usuario; + + //--------ARCHIVOS-------- + QFile archivo; + QString ArchivoUsuario; + QString passArchivo; + QString nivelUsuario; + QString mode; + QString ArchivoUsuario1; + QString passArchivo1; + QString nivelUsuario1; + QString mode1; + QString Vidas; + QString Llaves; + QString Tiempo; + QString vidas1; + QString llaves1; + QString tiempo1; + QPushButton *registrar; + //OBJETOS - Personaje *enemigo1; - Personaje *personaje1; - Personaje *personaje2; + Objeto *enemigo1; + Objeto *personaje1; + Objeto *personaje2; Particula *bolafuego; Objeto *bolaH; - Objeto *llave; QObject *personaje; Objeto *boton; Objeto *dragon; vidas *vida; llaves *keys; + Timer *tiempo; double x; double y; int opcion=0; @@ -84,9 +147,13 @@ private slots: int ymenor=0; int ymayor=0; int path=0; + int jugadores=0; bool ban=false; bool ban2=false; + bool ban3; bool visible; + bool arch; + int opcionArchivo=1; //____ prueba @@ -94,7 +161,7 @@ private slots: void items(); - void niveles(int); + void niveles(int,int); void guardarPartida(); @@ -108,13 +175,9 @@ private slots: void moverEnemigo(); - void coaliciones (char , Personaje *personaje ); + void coaliciones (char , Objeto *personaje); - void resorte(char letter,Personaje *personaje); + void resorte(char letter,Objeto *personaje); -QPushButton *start; -QPushButton *continuarPartida; -QPushButton *guardar; -QFile archivo; }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..1d578bf --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,48 @@ + + + MainWindow + + + + 0 + 0 + 812 + 605 + + + + MainWindow + + + /*#graphicsView +{ +background-image : url(:/IMAGENES/MAINMENU.png); +}*/ + + + + + + -10 + 10 + 800 + 581 + + + + + + + + 0 + 0 + 812 + 20 + + + + + + + + diff --git a/objeto.cpp b/objeto.cpp new file mode 100644 index 0000000..8700d62 --- /dev/null +++ b/objeto.cpp @@ -0,0 +1,80 @@ +#include "objeto.h" + +Objeto::Objeto() +{ + +} + +Objeto::Objeto(int x, int y, int r, QString rt) +{ + posx=x; + posy=y; + radio=r; + ruta=rt; + setPos(posx,posy); +} + +int Objeto::getR() +{ + return radio; +} + +void Objeto::setR(int r) +{ + radio=r; +} + + +int Objeto::getPosx() +{ + return posx; +} + +void Objeto::setPosx(int px) +{ + posx=px; +} + +int Objeto::getPosy() +{ + return posy; +} + +void Objeto::setPosy(int py) +{ + posy = py; +} +void Objeto::subir(int ECI, int ECF) +{ + setPos(x(),y()-5*ECI*ECF); +} + +void Objeto::bajar(int ECI, int ECF) +{ + setPos(x(),y()+5*ECI*ECF); +} + +void Objeto::derecha(int ECI,int ECF) +{ + setPos(x()+5*ECI*ECF,y()); +} + +void Objeto::izquierda(int ECI, int ECF) +{ + setPos(x()-5*ECI*ECF,y()); +} + +QRectF Objeto::boundingRect() const +{ + return QRectF(-radio,-radio,2*radio,2*radio); + +} + +void Objeto::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + QPixmap pixmap; + + pixmap.load(ruta); + + painter->drawPixmap(boundingRect(),pixmap,pixmap.rect()); +} diff --git a/objeto.h b/objeto.h new file mode 100644 index 0000000..805ee43 --- /dev/null +++ b/objeto.h @@ -0,0 +1,34 @@ + #ifndef OBJETO_H + #define OBJETO_H + #include + #define M 5 + #define G 1 + #include + #include + class Objeto : public QGraphicsItem + {public: + + int radio; + int posx, posy; + QString ruta; + int ECI; + int ECF; + + public: + Objeto(); + Objeto(int x, int y, int r, QString ruta); + int getR(); + void setR(int r); + int getPosx(); + void setPosx(int px); + int getPosy(); + void setPosy(int py); + void subir(int ECI,int ECF); + void bajar(int ECI,int ECF); + void derecha(int ECI,int ECF); + void izquierda(int ECI,int ECF); + QRectF boundingRect() const; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr); + }; + + #endif // OBJETO_H diff --git a/particula.cpp b/particula.cpp index ef0788d..8b85205 100644 --- a/particula.cpp +++ b/particula.cpp @@ -1,47 +1,17 @@ #include "particula.h" -double Particula::getPosy() const +void Particula::setVel(double value) { - return posy; + vel = value; } -double Particula::getPosx() const -{ - return posx; -} - -int Particula::getR() -{ - return radio; -} - -void Particula::setR(int r) -{ - radio=r; -} -QRectF Particula::boundingRect() const -{ - return QRectF(-radio,-radio,2*radio,2*radio); -} - -void Particula::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - QPixmap pixmap; - - pixmap.load(ruta); - - painter->drawPixmap(boundingRect(),pixmap,pixmap.rect()); -} - - Particula::Particula() { - + } -Particula::Particula(double an, double posxx, double posyy, double velocidad,int r, QString path) +Particula::Particula(double posxx, double posyy, double velocidad, int r, QString path) { - angulo=an; posx=posxx; posy=posyy; vel=velocidad; @@ -51,17 +21,4 @@ Particula::Particula(double an, double posxx, double posyy, double velocidad,int } -void Particula::ActualizarPosicion() -{ - posx-=vx; - setPos(posx,posy); -} - -void Particula::CalcularVelocidad() -{ - - vx=vel; - - -} diff --git a/particula.h b/particula.h index 5f12b6b..849ba04 100644 --- a/particula.h +++ b/particula.h @@ -1,42 +1,22 @@ #ifndef PARTICULA_H #define PARTICULA_H - +#include #include #include #include //seno coseno raiz -class Particula: public QGraphicsItem +class Particula: public Objeto { - //velocidades y posiciones afectadas por angulos, para que no haya desfase y mas presicion //se le dan las conidiones iniciales (atributos) - double angulo, vx, vy,vel; - double posx, posy; - int radio; + double vel; // se van a recalculas con base en las ecuaciones double g= 9.8; //tiempo - QString ruta; - int r=30; public: Particula(); - Particula(double an, double posxx, double posyy , double velocidad, int r, QString path); - //para poder saber la posicion a la que va a llegar , depende de la velocidad, antes de actualizar la posicion , la velocidad debe actualizarse - void ActualizarPosicion(); - //primero se calcula la velocidaD Y LUEGO LAS POSICIONES SE ACTUALIZAN - - void CalcularVelocidad(); - void CalcularAceleracion(Particula par ); - - double getPosy() const; - double getPosx() const; - - int getR(); - void setR(int r); - - + Particula( double posxx, double posyy , double velocidad, int r, QString path); - QRectF boundingRect() const ; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr); + void setVel(double value); }; #endif // PARTICULA_H diff --git a/registro.cpp b/registro.cpp new file mode 100644 index 0000000..e42d7bf --- /dev/null +++ b/registro.cpp @@ -0,0 +1,108 @@ +#include "registro.h" +#include "ui_registro.h" + +Registro::Registro(QWidget *parent) : + QDialog(parent), + ui(new Ui::Registro) +{ + ui->setupUi(this); + scene = new QGraphicsScene; + ui->graphicsView->setScene(scene); + + +} + +Registro::~Registro() +{ + delete ui; +} + + +void Registro::on_pushButton_2_clicked() +{ + QString usuario= ui->USUARIO->text(); + QString contrasena=ui->CONTRASENA->text(); + QString nivel="1"; + QString vidas="6"; + QString llaves="0"; + QString time="313"; + QListcont_nivel={contrasena,nivel}; + QListcont2_nivel={contrasena,nivel}; + + QFile archivo ("D:/E-MEDIEVAL/E-MEDIEVAL/REGISTRO/registro.txt"); + QFile archivo1("D:/E-MEDIEVAL/E-MEDIEVAL/REGISTRO/registro.txt"); + QFile cambios("D:/E-MEDIEVAL/E-MEDIEVAL/REGISTRO/cambios.txt"); + archivo.open(QIODevice::ReadOnly | QIODevice::Text); + archivo1.open(QIODevice::WriteOnly | QIODevice::Append); + cambios.open(QIODevice::WriteOnly | QIODevice::Append); + QTextStream datosArchivo (&archivo); + QTextStream escribir (&archivo1); + QTextStream write (&cambios); + + if ((modo!="1" and modo!="2") or (usuario=="") or (contrasena=="") ) + { + QMessageBox::warning(this, tr("REGISTRO NO VÁLIDO"), + + tr("DEBE COMPLETAR TODOS LOS CAMPOS REQUERIDOS"), + QMessageBox::Cancel); + + } + + else + { + ban=1; + } + + while (!datosArchivo.atEnd()) + { + + datosArchivo>>ArchivoUsuario; //lee el usuario del archivo, la primera línea + + if (usuario==ArchivoUsuario) + { + ban=0; + QMessageBox::warning(this, tr("REGISTRO NO VÁLIDO"), + tr("EL USUARIO YA ESTÁ REGISTRADO"), + + QMessageBox::Cancel); + } + } + if (ban==1) + { + hide(); + //QMap> registro; + //QMap> registro2; + //registro[usuario]=cont_nivel; + //registro2[usuario]=cont_nivel; + //QListcont2_nivel={contrasena,nivel}; + write< +#include +#include +#include +#include +namespace Ui { +class Registro; +} + +class Registro : public QDialog +{ + Q_OBJECT + +public: + explicit Registro(QWidget *parent = nullptr); + ~Registro(); + + // QString getNivel() const; + //void setNivel(const QString &value); + +private slots: + void on_pushButton_clicked(); + + void on_pushButton_2_clicked(); + + void on_pushButton_3_clicked(); + +private: + Ui::Registro *ui; + QGraphicsScene *scene; + // QMainWindow *juego; + int ban=1; + QString ArchivoUsuario; + QString modo; + // QString nivel; + +}; + +#endif // REGISTRO_H diff --git a/registro.ui b/registro.ui new file mode 100644 index 0000000..a9f167a --- /dev/null +++ b/registro.ui @@ -0,0 +1,140 @@ + + + Registro + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 15 + 11 + 371 + 271 + + + + + + + 180 + 30 + 51 + 20 + + + + REGISTRO + + + + + + 80 + 60 + 111 + 16 + + + + NOMBRE DE USUARIO + + + + + + 80 + 100 + 71 + 16 + + + + CONTRASEÑA + + + + + + 140 + 140 + 131 + 16 + + + + ELIJA EL MODO DE JUEGO + + + + + + 80 + 180 + 75 + 23 + + + + UN JUGADOR + + + + + + 154 + 230 + 81 + 23 + + + + REGISTRARSE + + + + + + 234 + 180 + 91 + 23 + + + + MULTIJUGADOR + + + + + + 230 + 60 + 113 + 20 + + + + + + + 230 + 100 + 113 + 20 + + + + + + + diff --git a/timer.cpp b/timer.cpp new file mode 100644 index 0000000..e235e06 --- /dev/null +++ b/timer.cpp @@ -0,0 +1,32 @@ +#include "timer.h" + +#include + +Timer::Timer(QGraphicsItem *parent): QGraphicsTextItem(parent) +{ + //inicializar las vidas en 3 + time = 313; + + //ESCRIBIR EL TEXTO + setPlainText(QString("Tiempo: ")+QString::number(time)); + setDefaultTextColor(Qt::red); + setFont(QFont("times",16)); + +} + +void Timer::decrease() +{ + time--; + setPlainText(QString("Tiempo: ")+QString::number(time)); +} + +int Timer::gettime() +{ + return time; +} + +void Timer::settime(int value) +{ + time = value; + setPlainText(QString("Tiempo: ")+QString::number(time)); +} diff --git a/timer.h b/timer.h new file mode 100644 index 0000000..f96c256 --- /dev/null +++ b/timer.h @@ -0,0 +1,23 @@ +#ifndef TIMER_H +#define TIMER_H + +#include + + +class Timer: public QGraphicsTextItem +{ + +public: + + Timer(QGraphicsItem * parent=0); + + void decrease(); + int gettime(); + void settime(int value); + +private: + + int time; +}; + +#endif // TIMER_H diff --git a/usuario.cpp b/usuario.cpp new file mode 100644 index 0000000..9d44b4f --- /dev/null +++ b/usuario.cpp @@ -0,0 +1,95 @@ +#include "usuario.h" + + + + + +QString Usuario::getNombre() const +{ + return nombre; +} + +void Usuario::setNombre(QString value) +{ + nombre = value; +} + + +QString Usuario::getContrasena() const +{ + return contrasena; +} + +void Usuario::setContrasena(QString value) +{ + contrasena = value; +} + +QString Usuario::getNivel() const +{ + return nivel; +} + +void Usuario::setNivel(const QString &value) +{ + nivel = value; +} + +QString Usuario::getModoDeJuego() const +{ + return modoDeJuego; +} + +void Usuario::setModoDeJuego(const QString &value) +{ + modoDeJuego = value; +} + + +QString Usuario::getVIDAS() const +{ + return VIDAS; +} + +void Usuario::setVIDAS(const QString &value) +{ + VIDAS = value; +} + +QString Usuario::getLLAVES() const +{ + return LLAVES; +} + +void Usuario::setLLAVES(const QString &value) +{ + LLAVES = value; +} + +QString Usuario::getTIEMPO() const +{ + return TIEMPO; +} + +void Usuario::setTIEMPO(const QString &value) +{ + TIEMPO = value; +} + +Usuario::Usuario() +{ + +} + + + +Usuario::Usuario(QString name, QString pass, QString level, QString mode, QString vidas_, QString llaves_, QString tiempo_) +{ + nombre=name; + contrasena=pass; + nivel=level; + modoDeJuego=mode; + VIDAS=vidas_; + LLAVES=llaves_; + TIEMPO=tiempo_; +} diff --git a/usuario.h b/usuario.h new file mode 100644 index 0000000..646228c --- /dev/null +++ b/usuario.h @@ -0,0 +1,40 @@ +#ifndef USUARIO_H +#define USUARIO_H +#include + +class Usuario +{ + QString nombre; + QString contrasena; + QString nivel; + QString modoDeJuego; + QString VIDAS; + QString LLAVES; + QString TIEMPO; + +public: + Usuario(); + Usuario(QString name, QString pass, QString level, QString modo, QString VIDAS, QString LLAVES, QString tiempo_); + + + QString getNombre() const; + void setNombre(QString value); + QString getContrasena() const; + void setContrasena(QString value); + QString getNivel() const; + void setNivel(const QString &value); + QString getModoDeJuego() const; + void setModoDeJuego(const QString &value); + QString getVidas() const; + void setVidas(const QString &value); + QString getLlaves() const; + void setLlaves(const QString &value); + QString getVIDAS() const; + void setVIDAS(const QString &value); + QString getLLAVES() const; + void setLLAVES(const QString &value); + QString getTIEMPO() const; + void setTIEMPO(const QString &value); +}; + +#endif // USUARIO_H diff --git a/verificar.cpp b/verificar.cpp new file mode 100644 index 0000000..b9b3d0c --- /dev/null +++ b/verificar.cpp @@ -0,0 +1,106 @@ +#include "verificar.h" +#include "ui_verificar.h" + +Verificar::Verificar(QWidget *parent) : + QDialog(parent), + ui(new Ui::Verificar) +{ + ui->setupUi(this); +} + +Verificar::~Verificar() +{ + delete ui; +} + +void Verificar::on_pushButton_clicked() +{ + QString usuario= ui->USUARIO->text(); + QString contrasena=ui->CONTRASENA->text(); + QString nivel="1"; + QString vidas="6"; + QString llaves="0"; + QString tiempo="313"; + QListcont_nivel={contrasena,nivel}; +//---------------------------------ABRE REGISTRO PARA VERIFICAR EN QUE NIVEL ESTÁ + QFile archivo ("D:/E-MEDIEVAL/E-MEDIEVAL/REGISTRO/registro.txt"); + //QFile cambios("D:/E-MEDIEVAL/E-MEDIEVAL/REGISTRO/REGISTRO/cambios.txt"); + archivo.open(QIODevice::ReadOnly | QIODevice::Text); + //cambios.open(QIODevice::ReadOnly | QIODevice::Text); + + // QTextStream escribir (&archivo); + + QTextStream datosArchivo (&archivo); + + // QTextStream escribir (&cambios); + + //QTextStream datosArchivo (&cambios); + + + while (!datosArchivo.atEnd()) + { + + datosArchivo>>ArchivoUsuario>>passArchivo>>nivelUsuario>>modo>>Vidas>>Llaves>>Tiempoj>>endl; + + + + + if (usuario==ArchivoUsuario) + { + + + if (contrasena==passArchivo) + { + //qDebug()<<"NIVEL USUARIO"<setNombre(usuario); + user->setContrasena(contrasena); + user->setNivel(nivel); + user->setModoDeJuego(modo); + user->setTIEMPO(Tiempoj); + MainWindow *EM= new MainWindow (); + EM->setUser(user); + level=nivelUsuario.toInt(); + LIFE=Vidas.toInt(); + llavecita=Llaves.toInt(); + jugadores=modo.toInt(); + tiempoj=Tiempoj.toInt(); + EM->setnivel(level); + EM->SETMODO(jugadores); + EM->VIDAS(LIFE); + EM->LLAVES(llavecita); + EM->TIEMPO(tiempoj); + EM->show(); + + + + } + + + } + } + if (ban==1) + { + ban=0; + hide(); + QMessageBox::warning(this, tr("NO SE PUEDE INGRESAR"), + tr("USUARIO NO REGISTRADO"), + + QMessageBox::Cancel); + + } +} + +/*int Verificar::cargarText() +{ + return level; +}*/ diff --git a/verificar.h b/verificar.h new file mode 100644 index 0000000..8dfa99f --- /dev/null +++ b/verificar.h @@ -0,0 +1,51 @@ +#ifndef VERIFICAR_H +#define VERIFICAR_H + +#include +#include +#include +#include +#include +#include +#include +namespace Ui { +class Verificar; +} + +class Verificar : public QDialog +{ + Q_OBJECT + +public: + explicit Verificar(QWidget *parent = nullptr); + ~Verificar(); + QString passArchivo; + QString archivoUsuario; + QString nivelUsuario; + QString modo; + QString Vidas; + QString Llaves; + QString Tiempoj; + //int cargarText(); +private slots: + void on_pushButton_clicked(); + + +private: + Ui::Verificar *ui; + QGraphicsScene *scene; + // QMainWindow *juego; + int ban=1; + int level; + int LIFE; + int llavecita; + int tiempoj; + int jugadores; + //QString *nivel; + QString ArchivoUsuario; + //MainWindow *EM; + Usuario *user; + +}; + +#endif // VERIFICAR_H diff --git a/verificar.ui b/verificar.ui new file mode 100644 index 0000000..a272ee2 --- /dev/null +++ b/verificar.ui @@ -0,0 +1,101 @@ + + + Verificar + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 20 + 20 + 361 + 261 + + + + + + + 50 + 80 + 111 + 20 + + + + INGRESE EL USUARIO + + + + + + 40 + 160 + 131 + 16 + + + + INGRESE LA CONTRASEÑA + + + + + + 150 + 230 + 91 + 23 + + + + INICIAR JUEGO + + + + + + 230 + 80 + 113 + 20 + + + + + + + 230 + 160 + 113 + 20 + + + + + + + 170 + 30 + 81 + 20 + + + + VERIFICANDO + + + + + + diff --git a/vidas.cpp b/vidas.cpp index 297bb80..6ff3d4d 100644 --- a/vidas.cpp +++ b/vidas.cpp @@ -24,3 +24,9 @@ int vidas::getlife() { return life; } + +void vidas::setLife(int value) +{ + life = value; + setPlainText(QString("Vidas: ")+QString::number(life)); +} diff --git a/vidas.h b/vidas.h index 26b5746..3b6aa5a 100644 --- a/vidas.h +++ b/vidas.h @@ -14,6 +14,8 @@ class vidas: public QGraphicsTextItem void decrease(); int getlife(); + void setLife(int value); + private: int life; diff --git a/win.cpp b/win.cpp new file mode 100644 index 0000000..cd50a82 --- /dev/null +++ b/win.cpp @@ -0,0 +1,14 @@ +#include "win.h" +#include "ui_win.h" + +Win::Win(QWidget *parent) : + QDialog(parent), + ui(new Ui::Win) +{ + ui->setupUi(this); +} + +Win::~Win() +{ + delete ui; +} diff --git a/win.h b/win.h new file mode 100644 index 0000000..8503f8a --- /dev/null +++ b/win.h @@ -0,0 +1,22 @@ +#ifndef WIN_H +#define WIN_H + +#include + +namespace Ui { +class Win; +} + +class Win : public QDialog +{ + Q_OBJECT + +public: + explicit Win(QWidget *parent = 0); + ~Win(); + +private: + Ui::Win *ui; +}; + +#endif // WIN_H diff --git a/win.ui b/win.ui new file mode 100644 index 0000000..3979150 --- /dev/null +++ b/win.ui @@ -0,0 +1,36 @@ + + + Win + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 70 + 110 + 256 + 71 + + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:28pt;">GANASTE</span></p></body></html> + + + + + +