Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <ctype.h>
- #include <conio.h>
- #include <vector>
- #include <ctime>
- #define ARRIBA 72
- #define IZQUIERDA 75
- #define ABAJO 80
- #define DERECHA 77
- #define ALTO 2
- #define ANCHO 5
- int vidas = 3;
- int puntos = 0;
- /**/
- #define ALEATORIO(NUM1, NUM2) rand() % (NUM2 - NUM1 + 1) + NUM1;
- using namespace std;
- using namespace System;
- enum Color { NEGRO, ROJO, AZUL, BLANCO, VERDE, AMARILLO, MORADO };
- void CambiarColorFondo(Color c) {
- switch (c)
- {
- case NEGRO: Console::BackgroundColor = ConsoleColor::Black; break;
- case ROJO: Console::BackgroundColor = ConsoleColor::Red; break;
- case AZUL: Console::BackgroundColor = ConsoleColor::Blue; break;
- case BLANCO: Console::BackgroundColor = ConsoleColor::White; break;
- case VERDE: Console::BackgroundColor = ConsoleColor::Green; break;
- case AMARILLO: Console::BackgroundColor = ConsoleColor::Yellow; break;
- case MORADO: Console::BackgroundColor = ConsoleColor::Magenta; break;
- }
- }
- void CambiarColorLetra(Color c) {
- switch (c) {
- case NEGRO: Console::ForegroundColor = ConsoleColor::Black; break;
- case ROJO: Console::ForegroundColor = ConsoleColor::Red; break;
- case AZUL: Console::ForegroundColor = ConsoleColor::Blue; break;
- case BLANCO: Console::ForegroundColor = ConsoleColor::White; break;
- case VERDE: Console::ForegroundColor = ConsoleColor::Green; break;
- case AMARILLO: Console::ForegroundColor = ConsoleColor::Yellow; break;
- case MORADO: Console::ForegroundColor = ConsoleColor::Magenta; break;
- }
- }
- typedef struct bala {
- short x;
- short y;
- bala(short a = 2, short b = 3) {
- x = a;
- y = b;
- }
- void animar() {
- Console::SetCursorPosition(x, y);
- cout << " ";
- if (y > 0) {
- y--;
- }
- Console::SetCursorPosition(x, y);
- cout << "*";
- }
- ~bala() {
- Console::SetCursorPosition(x, y);
- cout << " ";
- }
- };
- typedef struct abeja {
- short x;
- short y;
- int pasos;
- short dx;
- short dy;
- short retraso;
- char imagen[3][4];
- abeja(short a = 20, short b = 20, short c = 0) {
- x = a;
- y = b;
- pasos = c;
- dx = 1;
- dy = 1;
- retraso = 0;
- imagen[0][0] = ' ';
- imagen[0][1] = char(92);
- imagen[0][2] = '/';
- imagen[0][3] = ' ';
- imagen[1][0] = '(';
- imagen[1][1] = char(248);
- imagen[1][2] = ')';
- imagen[1][3] = ')';
- imagen[2][0] = ' ';
- imagen[2][1] = char(39);
- imagen[2][2] = char(39);
- imagen[2][3] = ' ';
- }
- ~abeja() {
- borrar();
- }
- void animar() {
- if (retraso == 1000) {
- borrar();
- mover();
- restriccion();
- dibujar();
- retraso = 0;
- }
- retraso++;
- }
- void dibujar() {
- for (int i = 0; i < 3; i++) {
- Console::SetCursorPosition(x, y + i);
- for (int j = 0; j < 4; j++) {
- if (i == 0) {
- CambiarColorLetra(AZUL);
- }
- else if (i == 1 && j == 1) {
- CambiarColorLetra(ROJO);
- }
- else if (i == 1 && j > 1 || i == 1 && j == 0) {
- CambiarColorLetra(AMARILLO);
- }
- else if (i == 2) {
- CambiarColorLetra(ROJO);
- }
- cout << imagen[i][j];
- }
- }
- }
- void borrar() {
- for (int i = 0; i < 3; i++) {
- Console::SetCursorPosition(x, y + i);
- for (int j = 0; j < 4; j++) {
- cout << ' ';
- }
- }
- }
- void mover() {
- if (x == 1 || x == 100) {
- dx *= -1;
- }
- x += dx;
- }
- void restriccion() {
- if (x == -1) {
- x = 0;
- }
- else if (y == -1) {
- y = 0;
- }
- }
- };
- typedef struct comandante {
- int vc = 2;
- short x;
- short y;
- int pasos;
- short dx;
- short dy;
- short retraso;
- int xbala;
- int ybala;
- int dybala;
- short retraso1 = 0;
- int disparar;
- char imagen[3][6];
- comandante(short a = 30, short b = 15, short c = 0) {
- x = a;
- y = b;
- pasos = c;
- dx = 1;
- dy = 1;
- retraso = 0;
- xbala = ALEATORIO(30, 60);
- ybala = y;
- dybala = 1;
- imagen[0][0] = ' ';
- imagen[0][1] = ' ';
- imagen[0][2] = '*';
- imagen[0][3] = '*';
- imagen[0][4] = ' ';
- imagen[0][5] = ' ';
- imagen[1][0] = ' ';
- imagen[1][1] = ' ';
- imagen[1][2] = '*';
- imagen[1][3] = '*';
- imagen[1][4] = ' ';
- imagen[1][5] = ' ';
- imagen[2][0] = '{';
- imagen[2][1] = '¨';
- imagen[2][2] = ' ';
- imagen[2][3] = ' ';
- imagen[2][4] = '¨';
- imagen[2][5] = '}';
- }
- ~comandante() {
- borrar();
- Console::SetCursorPosition(xbala, ybala);
- cout << " ";
- }
- void animar(vector<bala*> &disparar, vector<abeja*> &abejaA) {
- if (retraso == 1000) {
- borrar();
- mover();
- restriccion();
- if (vc == 1) {
- dibujar2();
- }
- if (vc == 2) {
- dibujar();
- }
- animarBala(abejaA);
- if (ybala == 45) {
- borrarBala();
- }
- retraso = 0;
- }
- retraso++;
- }
- void dibujar() {
- for (int i = 0; i < 3; i++) {
- Console::SetCursorPosition(x, y + i);
- for (int j = 0; j < 6; j++) {
- if (i < 2) {
- CambiarColorLetra(AZUL);
- }
- else {
- CambiarColorLetra(AMARILLO);
- }
- cout << imagen[i][j];
- }
- }
- }
- void borrar() {
- for (int i = 0; i < 3; i++) {
- Console::SetCursorPosition(x, y + i);
- for (int j = 0; j < 6; j++) {
- cout << ' ';
- }
- }
- }
- void mover() {
- if (x == 30 || x == 90) {
- dx *= -1;
- }
- x += dx;
- }
- void dibujar2() {
- for (int i = 0; i < 3; i++) {
- Console::SetCursorPosition(x, y + i);
- for (int j = 0; j < 6; j++) {
- if (i < 2) {
- CambiarColorLetra(MORADO);
- }
- else {
- CambiarColorLetra(AMARILLO);
- }
- cout << imagen[i][j];
- }
- }
- }
- void restriccion() {
- if (x == -1) {
- x = 0;
- }else if (x == 120) {
- x = 119;
- }else if (y == -1) {
- y = 0;
- }else if (y == 35) {
- y = 34;
- }
- }
- void crearBala() {
- Console::SetCursorPosition(xbala, ybala);
- cout << "*";
- }
- void borrarBala() {
- Console::SetCursorPosition(xbala, ybala);
- cout << " ";
- }
- void animarBala(vector<abeja*> &abejaA) {
- borrarBala();
- if (ybala == 45) {
- disparar = ALEATORIO(30, 60);
- }
- if (ybala == 45) {
- borrarBala();
- }
- if (ybala < 45) {
- ybala += dybala;
- }
- if (x == disparar) {
- xbala = x + 3;
- ybala = y + 3;
- }
- crearBala();
- }
- void cambiarColor(vector<bala*> &disparar) {
- for (int j = 0; j < 5; ++j) {
- for (int i = 0; i < disparar.size(); ++i) {
- if (disparar[i]->x == x + j && disparar[i]->y == y) {
- vc--;
- Console::SetCursorPosition(4, 4);
- cout << vc;
- }
- }
- }
- }
- };
- typedef struct personaje {
- short x;
- short y;
- int pasos;
- char imagen[ALTO][ANCHO];
- personaje(short a = 50, short b = 35, short c = 0) {
- x = a;
- y = b;
- pasos = c;
- imagen[0][0] = ' ';
- imagen[0][1] = ':';
- imagen[0][2] = '^';
- imagen[0][3] = ':';
- imagen[0][4] = ' ';
- imagen[1][0] = ':';
- imagen[1][1] = '^';
- imagen[1][2] = ':';
- imagen[1][3] = '^';
- imagen[1][4] = ':';
- }
- void animar(char direccion) {
- borrar();
- mover(direccion);
- restriccion();
- dibujar();
- }
- void dibujar() {
- for (int i = 0; i < ALTO; i++) {
- Console::SetCursorPosition(x, y + i);
- for (int j = 0; j < ANCHO; j++) {
- if (j == 1 && i == 0 || j == 3 && i == 0 || j == 0 && i == 1 || j == 2 && i == 1 || j == 4 && i == 1) {
- CambiarColorLetra(ROJO);
- }
- else {
- CambiarColorLetra(BLANCO);
- }
- cout << imagen[i][j];
- }
- }
- }
- void borrar() {
- for (int i = 0; i < ALTO; i++) {
- Console::SetCursorPosition(x, y + i);
- for (int j = 0; j < ANCHO; j++) {
- cout << ' ';
- }
- }
- }
- void mover(char direccion) {
- switch (toupper(direccion)) {
- case ARRIBA: y -= 3; pasos++; break;
- case ABAJO: y += 3; pasos++; break;
- case IZQUIERDA: x -= 3; pasos++; break;
- case DERECHA: x += 3; pasos++; break;
- }
- }
- void restriccion() {
- if (x == -1) {
- x = 0;
- }
- else if (y == -1) {
- y = 0;
- }
- }
- };
- typedef struct mariposa {
- short x;
- short y;
- int pasos;
- short dx;
- short dy;
- short retraso;
- char imagen[2][6];
- mariposa(short a = 70, short b = 25, short c = 0) {
- x = a;
- y = b;
- pasos = c;
- dx = 1;
- dy = 1;
- retraso = 0;
- imagen[0][0] = ' ';
- imagen[0][1] = char(92);
- imagen[0][2] = char(92);
- imagen[0][3] = '/';
- imagen[0][4] = '/';
- imagen[0][5] = ' ';
- imagen[1][0] = ' ';
- imagen[1][1] = ' ';
- imagen[1][2] = char(39);
- imagen[1][3] = char(39);
- imagen[1][4] = ' ';
- imagen[1][5] = ' ';
- }
- ~mariposa() {
- borrar();
- }
- void animar(vector<comandante*> &comandanteA, personaje* &personajeA) {
- if (retraso == 1000) {
- borrar();
- mover();
- restriccion();
- dibujar();
- score(comandanteA, personajeA);
- retraso = 0;
- }
- retraso++;
- }
- void dibujar() {
- for (int i = 0; i < 2; i++) {
- Console::SetCursorPosition(x, y + i);
- for (int j = 0; j < 6; j++) {
- if (i == 0) {
- CambiarColorLetra(ROJO);
- }
- else {
- CambiarColorLetra(AZUL);
- }
- cout << imagen[i][j];
- }
- }
- }
- void score(vector<comandante*> &comandanteA, personaje* &personajeA) {
- for (int j = 0; j < comandanteA.size(); ++j) {
- for (int i = 0; i < 5; ++i) {
- if (comandanteA[j]->xbala == personajeA->x + i && comandanteA[j]->ybala == personajeA->y) {
- vidas--;
- }
- if (vidas == 1 || vidas == 2) {
- personajeA->dibujar();
- }
- else if (vidas == 0) {
- }
- }
- }
- Console::SetCursorPosition(1, 2);
- cout << "Puntos: " << puntos;
- }
- void borrar() {
- for (int i = 0; i < 2; i++) {
- Console::SetCursorPosition(x, y + i);
- for (int j = 0; j < 6; j++) {
- cout << ' ';
- }
- }
- }
- void mover() {
- if (x == 1 || x == 100) {
- dx *= -1;
- }
- x += dx;
- }
- void restriccion() {
- if (x == -1) {
- x = 0;
- }
- else if (y == -1) {
- y = 0;
- }
- }
- };
- void game() {
- int retraso = 0;
- int retrasov = 0;
- Random random;
- personaje* personajeA = new personaje[1];
- vector<comandante*> comandanteA;
- vector<bala*> disparar;
- vector<abeja*> abejaA;
- vector<mariposa*> mariposaA;
- system("cls");
- bool continuar = true;
- for (int i = 0; i < 4; ++i) {
- comandanteA.push_back(new comandante());
- abejaA.push_back(new abeja());
- mariposaA.push_back(new mariposa());
- }
- for (int i = 0; i < 4; ++i) {
- comandanteA[i]->x = ALEATORIO(30, 90);
- abejaA[i]->x = ALEATORIO(30, 90);
- mariposaA[i]->x = ALEATORIO(60, 90);
- _sleep(15);
- }
- while (continuar) {
- if (kbhit()) {
- char direccion = getch();
- personajeA[0].animar(direccion);
- if (direccion == 32) {
- disparar.push_back(new bala(personajeA->x + 2, personajeA->y - 1));
- }
- }
- for (int e = 0; e < comandanteA.size(); e++) {
- if (comandanteA[e]->y >= 0) {
- comandanteA[e]->animar(disparar, abejaA);
- }
- for (int i = 0; i < disparar.size(); i++, retraso++) {
- if (retraso == 500) {
- disparar[i]->animar();
- retraso = 0;
- }
- if (retraso == 500) {
- disparar[i]->animar();
- retraso = 0;
- }
- 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) {
- comandanteA[e]->vc--;
- if (comandanteA[e]->vc == 0) {
- delete comandanteA[e];
- comandanteA.erase(comandanteA.begin() + e);
- e--;
- puntos += 130;
- }
- }
- if (disparar[i]->y == 0) {
- delete disparar[i];
- disparar.erase(disparar.begin() + i);
- i--;
- }
- retraso++;
- }
- }
- /*for (int e = 0; e < abejaA.size(); e++) {
- if (abejaA[e]->y >= 0) {
- abejaA[e]->animar();
- }
- for (int i = 0; i < disparar.size(); i++, retraso++) {
- if (retraso == 500) {
- disparar[i]->animar();
- retraso = 0;
- }
- 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) {
- delete abejaA[e];
- abejaA.erase(abejaA.begin() + e);
- e--;
- puntos += 130;
- }
- if (disparar[i]->y == 0) {
- delete disparar[i];
- disparar.erase(disparar.begin() + i);
- i--;
- }
- retraso++;
- }
- }*/
- for (int e = 0; e < mariposaA.size(); e++) {
- if (mariposaA[e]->y >= 0) {
- mariposaA[e]->animar(comandanteA,personajeA);
- }
- for (int i = 0; i < disparar.size(); i++, retraso++) {
- if (retraso == 500) {
- disparar[i]->animar();
- retraso = 0;
- }
- 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) {
- delete mariposaA[e];
- mariposaA.erase(mariposaA.begin() + e);
- e--;
- puntos += 130;
- }
- if (disparar[i]->y == 0) {
- delete disparar[i];
- disparar.erase(disparar.begin() + i);
- i--;
- }
- retraso++;
- }
- }
- }
- }
- void main() {
- Console::CursorVisible = false;
- Console::SetWindowSize(120, 50);
- game();
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement