Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 13.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <ctype.h>
  4. #include <conio.h>
  5. #include <vector>
  6. #include <ctime>
  7. #define ARRIBA    72
  8. #define IZQUIERDA 75
  9. #define ABAJO     80
  10. #define DERECHA   77
  11. #define ALTO 2
  12. #define ANCHO 5
  13. int vidas = 3;
  14. int puntos = 0;
  15. /**/
  16. #define ALEATORIO(NUM1, NUM2) rand() % (NUM2 - NUM1 + 1) + NUM1;
  17. using namespace std;
  18. using namespace System;
  19. enum Color { NEGRO, ROJO, AZUL, BLANCO, VERDE, AMARILLO, MORADO };
  20. void CambiarColorFondo(Color c) {
  21.     switch (c)
  22.     {
  23.     case NEGRO:     Console::BackgroundColor = ConsoleColor::Black; break;
  24.     case ROJO:      Console::BackgroundColor = ConsoleColor::Red; break;
  25.     case AZUL:      Console::BackgroundColor = ConsoleColor::Blue; break;
  26.     case BLANCO:    Console::BackgroundColor = ConsoleColor::White; break;
  27.     case VERDE:     Console::BackgroundColor = ConsoleColor::Green; break;
  28.     case AMARILLO:  Console::BackgroundColor = ConsoleColor::Yellow; break;
  29.     case MORADO:    Console::BackgroundColor = ConsoleColor::Magenta; break;
  30.     }
  31. }
  32. void CambiarColorLetra(Color c) {
  33.     switch (c) {
  34.     case NEGRO:     Console::ForegroundColor = ConsoleColor::Black; break;
  35.     case ROJO:      Console::ForegroundColor = ConsoleColor::Red; break;
  36.     case AZUL:      Console::ForegroundColor = ConsoleColor::Blue; break;
  37.     case BLANCO:    Console::ForegroundColor = ConsoleColor::White; break;
  38.     case VERDE:     Console::ForegroundColor = ConsoleColor::Green; break;
  39.     case AMARILLO:  Console::ForegroundColor = ConsoleColor::Yellow; break;
  40.     case MORADO:    Console::ForegroundColor = ConsoleColor::Magenta; break;
  41.     }
  42. }
  43.  
  44. typedef struct bala {
  45.     short x;
  46.     short y;
  47.     bala(short a = 2, short b = 3) {
  48.         x = a;
  49.         y = b;
  50.     }
  51.     void animar() {
  52.         Console::SetCursorPosition(x, y);
  53.         cout << " ";
  54.         if (y > 0) {
  55.             y--;
  56.         }
  57.         Console::SetCursorPosition(x, y);
  58.         cout << "*";
  59.     }
  60.     ~bala() {
  61.         Console::SetCursorPosition(x, y);
  62.         cout << " ";
  63.     }
  64. };
  65. typedef struct abeja {
  66.     short x;
  67.     short y;
  68.     int pasos;
  69.     short dx;
  70.     short dy;
  71.     short retraso;
  72.     char imagen[3][4];
  73.     abeja(short a = 20, short b = 20, short c = 0) {
  74.         x = a;
  75.         y = b;
  76.         pasos = c;
  77.         dx = 1;
  78.         dy = 1;
  79.         retraso = 0;
  80.         imagen[0][0] = ' ';
  81.         imagen[0][1] = char(92);
  82.         imagen[0][2] = '/';
  83.         imagen[0][3] = ' ';
  84.         imagen[1][0] = '(';
  85.         imagen[1][1] = char(248);
  86.         imagen[1][2] = ')';
  87.         imagen[1][3] = ')';
  88.         imagen[2][0] = ' ';
  89.         imagen[2][1] = char(39);
  90.         imagen[2][2] = char(39);
  91.         imagen[2][3] = ' ';
  92.     }
  93.     ~abeja() {
  94.         borrar();
  95.     }
  96.     void animar() {
  97.         if (retraso == 1000) {
  98.             borrar();
  99.             mover();
  100.             restriccion();
  101.             dibujar();
  102.             retraso = 0;
  103.         }
  104.         retraso++;
  105.     }
  106.     void dibujar() {
  107.         for (int i = 0; i < 3; i++) {
  108.             Console::SetCursorPosition(x, y + i);
  109.             for (int j = 0; j < 4; j++) {
  110.                 if (i == 0) {
  111.                     CambiarColorLetra(AZUL);
  112.                 }
  113.                 else if (i == 1 && j == 1) {
  114.                     CambiarColorLetra(ROJO);
  115.                 }
  116.                 else if (i == 1 && j > 1 || i == 1 && j == 0) {
  117.                     CambiarColorLetra(AMARILLO);
  118.                 }
  119.                 else if (i == 2) {
  120.                     CambiarColorLetra(ROJO);
  121.                 }
  122.                 cout << imagen[i][j];
  123.             }
  124.         }
  125.     }
  126.     void borrar() {
  127.         for (int i = 0; i < 3; i++) {
  128.             Console::SetCursorPosition(x, y + i);
  129.             for (int j = 0; j < 4; j++) {
  130.                 cout << ' ';
  131.             }
  132.         }
  133.     }
  134.     void mover() {
  135.         if (x == 1 || x == 100) {
  136.             dx *= -1;
  137.         }
  138.         x += dx;
  139.     }
  140.     void restriccion() {
  141.         if (x == -1) {
  142.             x = 0;
  143.         }
  144.         else if (y == -1) {
  145.             y = 0;
  146.         }
  147.     }
  148.  
  149. };
  150. typedef struct comandante {
  151.     int vc = 2;
  152.     short x;
  153.     short y;
  154.     int pasos;
  155.     short dx;
  156.     short dy;
  157.     short retraso;
  158.     int xbala;
  159.     int ybala;
  160.     int dybala;
  161.     short retraso1 = 0;
  162.     int disparar;
  163.     char imagen[3][6];
  164.     comandante(short a = 30, short b = 15, short c = 0) {
  165.         x = a;
  166.         y = b;
  167.         pasos = c;
  168.         dx = 1;
  169.         dy = 1;
  170.         retraso = 0;
  171.         xbala = ALEATORIO(30, 60);
  172.         ybala = y;
  173.         dybala = 1;
  174.         imagen[0][0] = ' ';
  175.         imagen[0][1] = ' ';
  176.         imagen[0][2] = '*';
  177.         imagen[0][3] = '*';
  178.         imagen[0][4] = ' ';
  179.         imagen[0][5] = ' ';
  180.         imagen[1][0] = ' ';
  181.         imagen[1][1] = ' ';
  182.         imagen[1][2] = '*';
  183.         imagen[1][3] = '*';
  184.         imagen[1][4] = ' ';
  185.         imagen[1][5] = ' ';
  186.         imagen[2][0] = '{';
  187.         imagen[2][1] = '¨';
  188.         imagen[2][2] = ' ';
  189.         imagen[2][3] = ' ';
  190.         imagen[2][4] = '¨';
  191.         imagen[2][5] = '}';
  192.     }
  193.     ~comandante() {
  194.         borrar();
  195.         Console::SetCursorPosition(xbala, ybala);
  196.         cout << " ";
  197.     }
  198.     void animar(vector<bala*> &disparar, vector<abeja*> &abejaA) {
  199.  
  200.         if (retraso == 1000) {
  201.  
  202.            
  203.             borrar();
  204.             mover();
  205.             restriccion();
  206.             if (vc == 1) {
  207.                 dibujar2();
  208.             }
  209.             if (vc == 2) {
  210.                 dibujar();
  211.             }
  212.  
  213.             animarBala(abejaA);
  214.             if (ybala == 45) {
  215.                 borrarBala();
  216.             }
  217.             retraso = 0;
  218.         }
  219.         retraso++;
  220.     }
  221.     void dibujar() {
  222.         for (int i = 0; i < 3; i++) {
  223.             Console::SetCursorPosition(x, y + i);
  224.             for (int j = 0; j < 6; j++) {
  225.                 if (i < 2) {
  226.                     CambiarColorLetra(AZUL);
  227.  
  228.                 }
  229.                 else {
  230.                     CambiarColorLetra(AMARILLO);
  231.                 }
  232.                 cout << imagen[i][j];
  233.             }
  234.         }
  235.     }
  236.     void borrar() {
  237.         for (int i = 0; i < 3; i++) {
  238.             Console::SetCursorPosition(x, y + i);
  239.             for (int j = 0; j < 6; j++) {
  240.                 cout << ' ';
  241.             }
  242.         }
  243.     }
  244.     void mover() {
  245.         if (x == 30 || x == 90) {
  246.             dx *= -1;
  247.         }
  248.         x += dx;
  249.            
  250.    
  251.        
  252.     }
  253.     void dibujar2() {
  254.         for (int i = 0; i < 3; i++) {
  255.             Console::SetCursorPosition(x, y + i);
  256.             for (int j = 0; j < 6; j++) {
  257.                 if (i < 2) {
  258.                     CambiarColorLetra(MORADO);
  259.  
  260.                 }
  261.                 else {
  262.                     CambiarColorLetra(AMARILLO);
  263.                 }
  264.                 cout << imagen[i][j];
  265.             }
  266.         }
  267.     }
  268.     void restriccion() {
  269.         if (x == -1) {
  270.             x = 0;
  271.         }else if (x == 120) {
  272.             x = 119;
  273.         }else if (y == -1) {
  274.             y = 0;
  275.         }else if (y == 35) {
  276.             y = 34;
  277.         }
  278.     }
  279.     void crearBala() {
  280.         Console::SetCursorPosition(xbala, ybala);
  281.         cout << "*";
  282.     }
  283.     void borrarBala() {
  284.         Console::SetCursorPosition(xbala, ybala);
  285.         cout << " ";
  286.     }
  287.     void animarBala(vector<abeja*> &abejaA) {
  288.                 borrarBala();
  289.                 if (ybala == 45) {
  290.                     disparar = ALEATORIO(30, 60);
  291.                 }
  292.                 if (ybala == 45) {
  293.                     borrarBala();
  294.                 }
  295.                 if (ybala < 45) {
  296.                     ybala += dybala;
  297.                 }
  298.                 if (x == disparar) {
  299.                     xbala = x + 3;
  300.                     ybala = y + 3;
  301.                 }
  302.                 crearBala();
  303.            
  304.    
  305.        
  306.        
  307.     }
  308.     void cambiarColor(vector<bala*> &disparar) {
  309.         for (int j = 0; j < 5; ++j) {
  310.             for (int i = 0; i < disparar.size(); ++i) {
  311.                 if (disparar[i]->x == x + j && disparar[i]->y == y) {
  312.                     vc--;
  313.                     Console::SetCursorPosition(4, 4);
  314.                     cout << vc;
  315.                 }
  316.             }
  317.         }
  318.  
  319.  
  320.     }
  321.  
  322. };
  323. typedef struct personaje {
  324.     short x;
  325.     short y;
  326.     int pasos;
  327.     char imagen[ALTO][ANCHO];
  328.     personaje(short a = 50, short b = 35, short c = 0) {
  329.         x = a;
  330.         y = b;
  331.         pasos = c;
  332.         imagen[0][0] = ' ';
  333.         imagen[0][1] = ':';
  334.         imagen[0][2] = '^';
  335.         imagen[0][3] = ':';
  336.         imagen[0][4] = ' ';
  337.         imagen[1][0] = ':';
  338.         imagen[1][1] = '^';
  339.         imagen[1][2] = ':';
  340.         imagen[1][3] = '^';
  341.         imagen[1][4] = ':';
  342.     }
  343.  
  344.     void animar(char direccion) {
  345.         borrar();
  346.         mover(direccion);
  347.         restriccion();
  348.         dibujar();
  349.     }
  350.     void dibujar() {
  351.  
  352.         for (int i = 0; i < ALTO; i++) {
  353.             Console::SetCursorPosition(x, y + i);
  354.             for (int j = 0; j < ANCHO; j++) {
  355.                 if (j == 1 && i == 0 || j == 3 && i == 0 || j == 0 && i == 1 || j == 2 && i == 1 || j == 4 && i == 1) {
  356.                     CambiarColorLetra(ROJO);
  357.                 }
  358.                 else {
  359.                     CambiarColorLetra(BLANCO);
  360.                 }
  361.                 cout << imagen[i][j];
  362.             }
  363.         }
  364.     }
  365.     void borrar() {
  366.         for (int i = 0; i < ALTO; i++) {
  367.             Console::SetCursorPosition(x, y + i);
  368.             for (int j = 0; j < ANCHO; j++) {
  369.                 cout << ' ';
  370.             }
  371.         }
  372.     }
  373.     void mover(char direccion) {
  374.         switch (toupper(direccion)) {
  375.         case ARRIBA: y -= 3; pasos++; break;
  376.         case ABAJO: y += 3; pasos++; break;
  377.         case IZQUIERDA: x -= 3; pasos++; break;
  378.         case DERECHA: x += 3; pasos++; break;
  379.         }
  380.     }
  381.     void restriccion() {
  382.         if (x == -1) {
  383.             x = 0;
  384.         }
  385.         else if (y == -1) {
  386.             y = 0;
  387.         }
  388.     }
  389.  
  390. };
  391. typedef struct mariposa {
  392.     short x;
  393.     short y;
  394.     int pasos;
  395.     short dx;
  396.     short dy;
  397.     short retraso;
  398.     char imagen[2][6];
  399.     mariposa(short a = 70, short b = 25, short c = 0) {
  400.         x = a;
  401.         y = b;
  402.         pasos = c;
  403.         dx = 1;
  404.         dy = 1;
  405.         retraso = 0;
  406.         imagen[0][0] = ' ';
  407.         imagen[0][1] = char(92);
  408.         imagen[0][2] = char(92);
  409.         imagen[0][3] = '/';
  410.         imagen[0][4] = '/';
  411.         imagen[0][5] = ' ';
  412.         imagen[1][0] = ' ';
  413.         imagen[1][1] = ' ';
  414.         imagen[1][2] = char(39);
  415.         imagen[1][3] = char(39);
  416.         imagen[1][4] = ' ';
  417.         imagen[1][5] = ' ';
  418.     }
  419.     ~mariposa() {
  420.         borrar();
  421.     }
  422.     void animar(vector<comandante*> &comandanteA, personaje* &personajeA) {
  423.         if (retraso == 1000) {
  424.             borrar();
  425.             mover();
  426.             restriccion();
  427.             dibujar();
  428.             score(comandanteA, personajeA);
  429.             retraso = 0;
  430.         }
  431.         retraso++;
  432.     }
  433.     void dibujar() {
  434.         for (int i = 0; i < 2; i++) {
  435.             Console::SetCursorPosition(x, y + i);
  436.             for (int j = 0; j < 6; j++) {
  437.                 if (i == 0) {
  438.                     CambiarColorLetra(ROJO);
  439.                 }
  440.                 else {
  441.                     CambiarColorLetra(AZUL);
  442.                 }
  443.                 cout << imagen[i][j];
  444.             }
  445.         }
  446.     }
  447.     void score(vector<comandante*> &comandanteA, personaje* &personajeA) {
  448.        
  449.         for (int j = 0; j < comandanteA.size(); ++j) {
  450.             for (int i = 0; i < 5; ++i) {
  451.                 if (comandanteA[j]->xbala == personajeA->x + i && comandanteA[j]->ybala == personajeA->y) {
  452.                     vidas--;
  453.                 }
  454.                 if (vidas == 1 || vidas == 2) {
  455.                     personajeA->dibujar();
  456.                 }
  457.                 else if (vidas == 0) {
  458.  
  459.                 }
  460.             }
  461.         }
  462.    
  463.         Console::SetCursorPosition(1, 2);      
  464.         cout << "Puntos: " << puntos;
  465.  
  466.  
  467.     }
  468.     void borrar() {
  469.         for (int i = 0; i < 2; i++) {
  470.             Console::SetCursorPosition(x, y + i);
  471.             for (int j = 0; j < 6; j++) {
  472.                 cout << ' ';
  473.             }
  474.         }
  475.     }
  476.     void mover() {
  477.         if (x == 1 || x == 100) {
  478.             dx *= -1;
  479.         }
  480.         x += dx;
  481.     }
  482.     void restriccion() {
  483.         if (x == -1) {
  484.             x = 0;
  485.         }
  486.         else if (y == -1) {
  487.             y = 0;
  488.         }
  489.     }
  490. };
  491.  
  492. void game() {
  493.     int retraso = 0;
  494.     int retrasov = 0;
  495.     Random random;
  496.     personaje* personajeA = new personaje[1];
  497.     vector<comandante*> comandanteA;
  498.     vector<bala*> disparar;
  499.     vector<abeja*> abejaA;
  500.     vector<mariposa*> mariposaA;
  501.     system("cls");
  502.     bool continuar = true;
  503.     for (int i = 0; i < 4; ++i) {
  504.  
  505.         comandanteA.push_back(new comandante());
  506.         abejaA.push_back(new abeja());
  507.         mariposaA.push_back(new mariposa());
  508.     }
  509.  
  510.  
  511.     for (int i = 0; i < 4; ++i) {
  512.         comandanteA[i]->x = ALEATORIO(30, 90);
  513.         abejaA[i]->x = ALEATORIO(30, 90);
  514.         mariposaA[i]->x = ALEATORIO(60, 90);
  515.         _sleep(15);
  516.  
  517.     }
  518.  
  519.  
  520.     while (continuar) {
  521.        
  522.  
  523.         if (kbhit()) {
  524.             char direccion = getch();
  525.             personajeA[0].animar(direccion);
  526.             if (direccion == 32) {
  527.                 disparar.push_back(new bala(personajeA->x + 2, personajeA->y - 1));
  528.             }
  529.  
  530.         }
  531.        
  532.         for (int e = 0; e < comandanteA.size(); e++) {
  533.             if (comandanteA[e]->y >= 0) {
  534.                 comandanteA[e]->animar(disparar, abejaA);
  535.             }
  536.             for (int i = 0; i < disparar.size(); i++, retraso++) {
  537.             if (retraso == 500) {
  538.             disparar[i]->animar();
  539.             retraso = 0;
  540.             }
  541.                 if (retraso == 500) {
  542.                     disparar[i]->animar();
  543.                     retraso = 0;
  544.                 }
  545.            
  546.                 if (disparar[i]->x == comandanteA[e]->x + 1 && disparar[i]->y == comandanteA[e]->y || disparar[i]->x == comandanteA[e]->x + 2 && disparar[i]->y == comandanteA[e]->y || disparar[i]->x == comandanteA[e]->x + 3 && disparar[i]->y == comandanteA[e]->y || disparar[i]->x == comandanteA[e]->x + 4 && disparar[i]->y == comandanteA[e]->y || disparar[i]->x == comandanteA[e]->x + 5 && disparar[i]->y == comandanteA[e]->y) {
  547.                     comandanteA[e]->vc--;
  548.                     if (comandanteA[e]->vc == 0) {
  549.                         delete comandanteA[e];
  550.                         comandanteA.erase(comandanteA.begin() + e);
  551.                         e--;
  552.                         puntos += 130;
  553.                     }
  554.  
  555.  
  556.  
  557.                 }
  558.                 if (disparar[i]->y == 0) {
  559.                     delete disparar[i];
  560.                     disparar.erase(disparar.begin() + i);
  561.                     i--;
  562.                 }
  563.  
  564.  
  565.                 retraso++;
  566.             }
  567.  
  568.  
  569.         }
  570.         /*for (int e = 0; e < abejaA.size(); e++) {
  571.             if (abejaA[e]->y >= 0) {
  572.                 abejaA[e]->animar();
  573.             }
  574.             for (int i = 0; i < disparar.size(); i++, retraso++) {
  575.             if (retraso == 500) {
  576.             disparar[i]->animar();
  577.             retraso = 0;
  578.             }
  579.             if (disparar[i]->x == abejaA[e]->x + 1 && disparar[i]->y == abejaA[e]->y || disparar[i]->x == abejaA[e]->x + 2 && disparar[i]->y == abejaA[e]->y || disparar[i]->x == abejaA[e]->x + 3 && disparar[i]->y == abejaA[e]->y || disparar[i]->x == abejaA[e]->x + 4 && disparar[i]->y == abejaA[e]->y || disparar[i]->x == abejaA[e]->x + 5 && disparar[i]->y == abejaA[e]->y) {
  580.             delete abejaA[e];
  581.             abejaA.erase(abejaA.begin() + e);
  582.             e--;
  583.             puntos += 130;
  584.             }
  585.             if (disparar[i]->y == 0) {
  586.             delete disparar[i];
  587.             disparar.erase(disparar.begin() + i);
  588.             i--;
  589.             }
  590.  
  591.  
  592.  
  593.             retraso++;
  594.             }
  595.         }*/
  596.         for (int e = 0; e < mariposaA.size(); e++) {
  597.             if (mariposaA[e]->y >= 0) {
  598.                 mariposaA[e]->animar(comandanteA,personajeA);
  599.             }
  600.             for (int i = 0; i < disparar.size(); i++, retraso++) {
  601.                 if (retraso == 500) {
  602.                     disparar[i]->animar();
  603.                     retraso = 0;
  604.                 }
  605.             if (disparar[i]->x == mariposaA[e]->x + 1 && disparar[i]->y == mariposaA[e]->y || disparar[i]->x == mariposaA[e]->x + 2 && disparar[i]->y == mariposaA[e]->y || disparar[i]->x == mariposaA[e]->x + 3 && disparar[i]->y == mariposaA[e]->y || disparar[i]->x == mariposaA[e]->x + 4 && disparar[i]->y == mariposaA[e]->y || disparar[i]->x == mariposaA[e]->x + 5 && disparar[i]->y == mariposaA[e]->y) {
  606.             delete mariposaA[e];
  607.             mariposaA.erase(mariposaA.begin() + e);
  608.             e--;
  609.             puntos += 130;
  610.             }
  611.             if (disparar[i]->y == 0) {
  612.  
  613.             delete disparar[i];
  614.             disparar.erase(disparar.begin() + i);
  615.             i--;
  616.             }
  617.  
  618.  
  619.  
  620.             retraso++;
  621.             }
  622.         }
  623.        
  624.     }
  625.  
  626. }
  627. void main() {
  628.  
  629.     Console::CursorVisible = false;
  630.     Console::SetWindowSize(120, 50);
  631.     game();
  632.     return;
  633.  
  634. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement