Advertisement
Guest User

Untitled

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