Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctype.h>
  3. #include <conio.h>
  4. #include <time.h>
  5. #include <vector>
  6. using namespace std;
  7. using namespace System;
  8. #define IZQUIERDA 75
  9. #define DERECHA 77
  10. #define DISPARAR 32
  11. #define ALTO 2
  12. #define ANCHO 8
  13. #define ESC 27
  14. #define BORDEDERECHA 50
  15. #define BORDEIZQUIERDA 15
  16. #define ALEATORIO (INI, FIN) rand() % (FIN - INI + 1) + INI
  17. struct enemigo {
  18. short x;
  19. short y;
  20. short dx;
  21. char enemigos[2][4]{
  22. { '-','-','-','-' },
  23. { ' ','|','|',' ' } };
  24. enemigo(int _x = 19, int _y = rand() % 10 + 5) {
  25. x = _x;
  26. y = _y;
  27. dx = 1;
  28. }
  29. void animar() {
  30. borrar();
  31. mover();
  32. dibujar();
  33. }
  34. void borrar() {
  35. for (short f = 0; f < 2; ++f) {
  36. Console::SetCursorPosition(x, y + f);
  37. for (short c = 0; c < 4; ++c) {
  38. cout << " ";
  39. }
  40. }
  41. }
  42. void mover() {
  43. if (x == BORDEIZQUIERDA + 4 || x == BORDEDERECHA + 4) dx *= -1;
  44. x += dx;
  45. }
  46. void dibujar() {
  47. Console::ForegroundColor = ConsoleColor::Yellow;
  48. Console::SetCursorPosition(x, y);
  49. for (short f = 0; f < 2; ++f) {
  50. Console::SetCursorPosition(x, y + f);
  51. for (short c = 0; c < 4; ++c) {
  52. cout << enemigos[f][c];
  53. }
  54. }
  55. }
  56. };
  57. struct enemigos2 {
  58. short x;
  59. short y;
  60. short dx;
  61. short dy;
  62. char enemigos[2][3]{
  63. { '-','-','-' },
  64. { ' ','"',' ' } };
  65. enemigos2(int _x = 19, int _y = rand() % 8 + 5) {
  66. x = _x;
  67. y = _y;
  68. dx = 1;
  69. dy = 1;
  70. }
  71. void animar() {
  72. borrar();
  73. mover();
  74. dibujar();
  75. }
  76. void borrar() {
  77. for (short f = 0; f < 2; ++f) {
  78. Console::SetCursorPosition(x, y + f);
  79. for (short c = 0; c < 3; ++c) {
  80. cout << " ";
  81. }
  82. }
  83. }
  84. void mover() {
  85. if (x == BORDEIZQUIERDA + 3 || x == BORDEDERECHA + 6) dx *= -1;
  86. x += dx;
  87. }
  88. void dibujar() {
  89. Console::ForegroundColor = ConsoleColor::Red;
  90. Console::SetCursorPosition(x, y);
  91. for (short f = 0; f < 2; ++f) {
  92. Console::SetCursorPosition(x, y + f);
  93. for (short c = 0; c < 3; ++c) {
  94. cout << enemigos[f][c];
  95. }
  96. }
  97. }
  98. };
  99. struct enemigos3 {
  100. short x;
  101. int vida = 2;
  102. short y;
  103. short dx;
  104. short dy;
  105. char enemigos[3][4]{
  106. { '/','(',')','/' },
  107. { ' ','(',')',' ' },
  108. { ' ','"','"',' ' } };
  109. enemigos3(int _x = rand() % 11 + 11, int _y = 2) {
  110. x = _x;
  111. y = _y;
  112. dx = 1;
  113. dy = 1;
  114. }
  115. void animar() {
  116. borrar();
  117. mover();
  118. dibujar();
  119. }
  120. void borrar() {
  121. for (short f = 0; f < 3; ++f) {
  122. Console::SetCursorPosition(x, y + f);
  123. for (short c = 0; c < 4; ++c) {
  124. cout << " ";
  125. }
  126. }
  127. }
  128. void mover() {
  129. if (x == BORDEIZQUIERDA || x == BORDEDERECHA + 4) dx *= -1;
  130. x += dx;
  131. }
  132. void dibujar() {
  133. Console::ForegroundColor = ConsoleColor::Blue;
  134. Console::SetCursorPosition(x, y);
  135. for (short f = 0; f < 3; ++f) {
  136. Console::SetCursorPosition(x, y + f);
  137. for (short c = 0; c < 4; ++c) {
  138. cout << enemigos[f][c];
  139. if (vida == 1)
  140. {
  141. Console::ForegroundColor = ConsoleColor::DarkMagenta;
  142. dibujar();
  143. }
  144. }
  145. }
  146. }
  147. };
  148. struct bala {
  149. short x, y;
  150. bala(int _x = 10, int _y = 10) {
  151. x = _x;
  152. y = _y;
  153. }
  154. void animar() {
  155. borrar();
  156. mover();
  157. dibujar();
  158. }
  159. void mover() {
  160. y--;
  161. }
  162. void dibujar() {
  163. Console::SetCursorPosition(x, y);
  164. cout << char(34);
  165. }
  166. void borrar() {
  167. Console::SetCursorPosition(x, y);
  168. cout << " ";
  169. }
  170. };
  171. struct personaje {
  172. int vidas = 4;
  173. short x;
  174. short y;
  175. char nave[ALTO][ANCHO]{
  176. { ' ',' ',' ','|','|',' ',' ',' ' },
  177. { '!','-','[','>','<',']' ,'-','!', } };
  178. personaje(short _x = 0, short _y = 0) {
  179. x = _x;
  180. y = _y;
  181. vidas = 3;
  182. }
  183. void animar(char direccion) {
  184. borrar();
  185. mover(direccion);
  186. dibujar();
  187. }
  188. void mover(char direccion) {
  189. if (direccion == IZQUIERDA && x>0)x--;
  190. if (direccion == DERECHA && x<BORDEDERECHA)x++;
  191. }
  192. void dibujar() {
  193. Console::ForegroundColor = ConsoleColor::White;
  194. for (short f = 0; f < ALTO; ++f) {
  195. Console::SetCursorPosition(x, y + f);
  196. for (short c = 0; c < ANCHO; ++c) {
  197. cout << nave[f][c];
  198. }
  199. }
  200. }
  201. void borrar() {
  202. for (short f = 0; f < ALTO; ++f) {
  203. Console::SetCursorPosition(x, y + f);
  204. for (short c = 0; c < ANCHO; ++c) {
  205. cout << " ";
  206. }
  207. }
  208. }
  209. };
  210. bool colision(short xe, short ye, short &xb, short &yb) {
  211. for (int i = 0; i < 2; i++) {
  212. for (int j = 0; j < 4; j++) {
  213. if (xe + i == xb && ye + j == yb) return true;
  214. else return false;
  215. }
  216. }
  217. }
  218. void jugar() {
  219. int contE = 5;
  220. int puntaje = 0;
  221. personaje nave = personaje(36, 37);
  222. vector<enemigo*>pEnemigosM;
  223. vector<enemigos2*>pEnemigosA;
  224. vector<enemigos3*>pEnemigosC;
  225. bool continuar = true;
  226. vector<bala*> balas;
  227. for (short i = 0; i < 2; i++) {
  228. int x = rand() % 31 + 18;
  229. int y = rand() % 16 + 7;
  230. pEnemigosA.push_back(new enemigos2(x, y));
  231. }
  232. for (short i = 0; i < 2; i++) {
  233. int x = rand() % 31 + 18;
  234. int y = rand() % 16 + 5;
  235. pEnemigosM.push_back(new enemigo(x, y));
  236. }
  237. for (short i = 0; i < 1; i++) {
  238. int x = rand() % 30 + 18;
  239. int y = rand() % 1 + 2;
  240. pEnemigosC.push_back(new enemigos3(x, y));
  241. }
  242. while (continuar) {
  243. if (kbhit()) {
  244. char direccion = getch();
  245. nave.animar(direccion);
  246. if (direccion == DISPARAR)
  247. {
  248. balas.push_back(new bala(nave.x + 4, nave.y - 1));
  249. }
  250. }
  251. for (short i = 0; i < pEnemigosM.size(); i++) {
  252. pEnemigosM[i]->animar();
  253. }
  254. for (short i = 0; i < pEnemigosA.size(); i++) {
  255. pEnemigosA[i]->animar();
  256. }
  257. for (short i = 0; i < pEnemigosC.size(); i++) {
  258. pEnemigosC[i]->animar();
  259. }
  260. for (int i = 0; i < balas.size(); i++) {
  261. if (balas[i]->y != 2) {
  262. balas[i]->animar();
  263. for (int j = 0; j < pEnemigosM.size(); j++) {
  264. if (colision(pEnemigosM[j]->x, pEnemigosM[j]->y + 1, balas[i]->x, balas[i]->y) ||
  265. colision(pEnemigosM[j]->x + 1, pEnemigosM[j]->y + 1, balas[i]->x, balas[i]->y) ||
  266. colision(pEnemigosM[j]->x + 2, pEnemigosM[j]->y + 1, balas[i]->x, balas[i]->y) ||
  267. colision(pEnemigosM[j]->x + 3, pEnemigosM[j]->y + 1, balas[i]->x, balas[i]->y)) {
  268. puntaje += 100;
  269. Console::SetCursorPosition(90, 1);
  270. Console::ForegroundColor = ConsoleColor::White;
  271. cout << "PUNTAJE = " << puntaje;
  272. pEnemigosM[j]->borrar();
  273. delete pEnemigosM[j];
  274. pEnemigosM.erase(pEnemigosM.begin() + j);
  275. j--;
  276. contE--;
  277. if (contE == 0)
  278. {
  279. continuar = false;
  280. }
  281. }
  282. }
  283. for (int k = 0; k < pEnemigosA.size(); k++) {
  284. if (colision(pEnemigosA[k]->x, pEnemigosA[k]->y + 1, balas[i]->x, balas[i]->y) ||
  285. colision(pEnemigosA[k]->x + 1, pEnemigosA[k]->y + 1, balas[i]->x, balas[i]->y) ||
  286. colision(pEnemigosA[k]->x + 2, pEnemigosA[k]->y + 1, balas[i]->x, balas[i]->y) ||
  287. colision(pEnemigosA[k]->x + 3, pEnemigosA[k]->y + 1, balas[i]->x, balas[i]->y)) {
  288. puntaje += 100;
  289. Console::SetCursorPosition(90, 1);
  290. Console::ForegroundColor = ConsoleColor::White;
  291. cout << "PUNTAJE = " << puntaje;
  292. pEnemigosA[k]->borrar();
  293. delete pEnemigosA[k];
  294. pEnemigosA.erase(pEnemigosA.begin() + k);
  295. k--;
  296. contE--;
  297. if (contE == 0)
  298. {
  299. continuar = false;
  300. }
  301. }
  302. }
  303. for (int l = 0; l < pEnemigosC.size(); l++) {
  304. if (colision(pEnemigosC[l]->x, pEnemigosC[l]->y + 1, balas[i]->x, balas[l]->y) ||
  305. colision(pEnemigosC[l]->x + 1, pEnemigosC[l]->y + 1, balas[i]->x, balas[i]->y) ||
  306. colision(pEnemigosC[l]->x + 2, pEnemigosC[l]->y + 1, balas[i]->x, balas[i]->y) ||
  307. colision(pEnemigosC[l]->x + 3, pEnemigosC[l]->y + 1, balas[i]->x, balas[i]->y)) {
  308. puntaje += 100;
  309. Console::SetCursorPosition(90, 1);
  310. Console::ForegroundColor = ConsoleColor::White;
  311. cout << "PUNTAJE = " << puntaje;
  312. pEnemigosC[l]->borrar();
  313. delete pEnemigosC[l];
  314. pEnemigosC.erase(pEnemigosC.begin() + l);
  315. l--;
  316. contE--;
  317. if (contE == 0)
  318. {
  319. continuar = false;
  320. }
  321. }
  322. }
  323. }
  324. else {
  325. balas[i]->borrar();
  326. delete balas[i];
  327. balas.erase(balas.begin() + i);
  328. i--;
  329. break;
  330. }
  331. }
  332. _sleep(45);
  333. }
  334. system("cls");
  335. Console::SetCursorPosition(45, 37);
  336. cout << "NIVEL 2" << endl;
  337. system("pause");
  338. system("cls");
  339. int contE2 = 5;
  340. int puntaje2 = 0;
  341. personaje nave2 = personaje(35, 37);
  342. vector<enemigo*>pEnemigosM2;
  343. vector<enemigos2*>pEnemigosA2;
  344. vector<enemigos3*>pEnemigosC2;
  345. bool continuar2 = true;
  346. vector<bala*> balas2;
  347. for (short i = 0; i < 2; i++) {
  348. int x = rand() % 31 + 20;
  349. int y = rand() % 16 + 7;
  350. pEnemigosA2.push_back(new enemigos2(x, y));
  351. }
  352. for (short i = 0; i < 2; i++) {
  353. int x = rand() % 31 + 20;
  354. int y = rand() % 16 + 5;
  355. pEnemigosM2.push_back(new enemigo(x, y));
  356. }
  357. for (short i = 0; i < 1; i++) {
  358. int x = rand() % 30 + 20;
  359. int y = rand() % 1 + 2;
  360. pEnemigosC2.push_back(new enemigos3(x, y));
  361. }
  362. while (continuar2) {
  363. if (kbhit()) {
  364. char direccion2 = getch();
  365. nave2.animar(direccion2);
  366. if (direccion2 == DISPARAR)
  367. {
  368. balas2.push_back(new bala(nave2.x + 4, nave2.y - 1));
  369. }
  370. }
  371. for (short i = 0; i < pEnemigosM2.size(); i++) {
  372. pEnemigosM2[i]->animar();
  373. }
  374. for (short i = 0; i < pEnemigosA2.size(); i++) {
  375. pEnemigosA2[i]->animar();
  376. }
  377. for (short i = 0; i < pEnemigosC2.size(); i++) {
  378. pEnemigosC2[i]->animar();
  379. }
  380. for (int i = 0; i < balas2.size(); i++) {
  381. if (balas2[i]->y != 2) {
  382. balas2[i]->animar();
  383. for (int j = 0; j < pEnemigosM2.size(); j++) {
  384. if (colision(pEnemigosM2[j]->x, pEnemigosM2[j]->y + 1, balas2[i]->x, balas2[i]->y) ||
  385. colision(pEnemigosM2[j]->x + 1, pEnemigosM2[j]->y + 1, balas2[i]->x, balas2[i]->y) ||
  386. colision(pEnemigosM2[j]->x + 2, pEnemigosM2[j]->y + 1, balas2[i]->x, balas2[i]->y) ||
  387. colision(pEnemigosM2[j]->x + 3, pEnemigosM2[j]->y + 1, balas2[i]->x, balas2[i]->y)) {
  388. puntaje += 100;
  389. Console::SetCursorPosition(90, 1);
  390. Console::ForegroundColor = ConsoleColor::White;
  391. cout << "PUNTAJE = " << puntaje;
  392. pEnemigosM2[j]->borrar();
  393. delete pEnemigosM2[j];
  394. pEnemigosM2.erase(pEnemigosM2.begin() + j);
  395. j--;
  396. contE2--;
  397. if (contE2 == 0)
  398. {
  399. continuar2 = false;
  400. }
  401. }
  402. }
  403. for (int k = 0; k < pEnemigosA2.size(); k++) {
  404. if (colision(pEnemigosA2[k]->x, pEnemigosA2[k]->y + 1, balas2[i]->x, balas2[i]->y) ||
  405. colision(pEnemigosA2[k]->x + 1, pEnemigosA2[k]->y + 1, balas2[i]->x, balas2[i]->y) ||
  406. colision(pEnemigosA2[k]->x + 2, pEnemigosA2[k]->y + 1, balas2[i]->x, balas2[i]->y) ||
  407. colision(pEnemigosA2[k]->x + 3, pEnemigosA2[k]->y + 1, balas2[i]->x, balas2[i]->y)) {
  408. puntaje += 100;
  409. Console::SetCursorPosition(90, 1);
  410. Console::ForegroundColor = ConsoleColor::White;
  411. cout << "PUNTAJE = " << puntaje;
  412. pEnemigosA2[k]->borrar();
  413. delete pEnemigosA2[k];
  414. pEnemigosA2.erase(pEnemigosA2.begin() + k);
  415. k--;
  416. contE2--;
  417. if (contE2 == 0)
  418. {
  419. continuar2 = false;
  420. }
  421. }
  422. }
  423. for (int l = 0; l < pEnemigosC2.size(); l++) {
  424. if (colision(pEnemigosC2[l]->x, pEnemigosC2[l]->y + 1, balas2[i]->x, balas2[l]->y) ||
  425. colision(pEnemigosC2[l]->x + 1, pEnemigosC2[l]->y + 1, balas2[i]->x, balas2[i]->y) ||
  426. colision(pEnemigosC2[l]->x + 2, pEnemigosC2[l]->y + 1, balas2[i]->x, balas2[i]->y) ||
  427. colision(pEnemigosC2[l]->x + 3, pEnemigosC2[l]->y + 1, balas2[i]->x, balas2[i]->y)) {
  428. puntaje += 100;
  429. Console::SetCursorPosition(90, 1);
  430. Console::ForegroundColor = ConsoleColor::White;
  431. cout << "PUNTAJE = " << puntaje;
  432. pEnemigosC2[l]->borrar();
  433. delete pEnemigosC2[l];
  434. pEnemigosC2.erase(pEnemigosC2.begin() + l);
  435. l--;
  436. contE2--;
  437. if (contE2 == 0)
  438. {
  439. continuar2 = false;
  440. }
  441. }
  442. }
  443. }
  444. else {
  445. balas2[i]->borrar();
  446. delete balas2[i];
  447. balas2.erase(balas2.begin() + i);
  448. i--;
  449. break;
  450. }
  451. }
  452. _sleep(45);
  453. }
  454. system("cls");
  455. Console::SetCursorPosition(45, 37);
  456. cout << "NIVEL 3" << endl;
  457. system("pause");
  458. system("cls");
  459. int contE3 = 5;
  460. int puntaje3 = 0;
  461. personaje nave3 = personaje(35, 37);
  462. vector<enemigo*>pEnemigosM3;
  463. vector<enemigos2*>pEnemigosA3;
  464. vector<enemigos3*>pEnemigosC3;
  465. bool continuar3 = true;
  466. vector<bala*> balas3;
  467. for (short i = 0; i < 2; i++) {
  468. int x = rand() % 31 + 20;
  469. int y = rand() % 16 + 7;
  470. pEnemigosA3.push_back(new enemigos2(x, y));
  471. }
  472. for (short i = 0; i < 2; i++) {
  473. int x = rand() % 31 + 20;
  474. int y = rand() % 16 + 5;
  475. pEnemigosM3.push_back(new enemigo(x, y));
  476. }
  477. for (short i = 0; i < 1; i++) {
  478. int x = rand() % 30 + 20;
  479. int y = rand() % 1 + 2;
  480. pEnemigosC3.push_back(new enemigos3(x, y));
  481. }
  482. while (continuar3) {
  483. if (kbhit()) {
  484. char direccion3 = getch();
  485. nave3.animar(direccion3);
  486. if (direccion3 == DISPARAR)
  487. {
  488. balas3.push_back(new bala(nave3.x + 4, nave3.y - 1));
  489. }
  490. }
  491. for (short i = 0; i < pEnemigosM3.size(); i++) {
  492. pEnemigosM3[i]->animar();
  493. }
  494. for (short i = 0; i < pEnemigosA3.size(); i++) {
  495. pEnemigosA3[i]->animar();
  496. }
  497. for (short i = 0; i < pEnemigosC3.size(); i++) {
  498. pEnemigosC3[i]->animar();
  499. }
  500. for (int i = 0; i < balas3.size(); i++) {
  501. if (balas3[i]->y != 2) {
  502. balas3[i]->animar();
  503. for (int j = 0; j < pEnemigosM3.size(); j++) {
  504. if (colision(pEnemigosM3[j]->x, pEnemigosM3[j]->y + 1, balas3[i]->x, balas3[i]->y) ||
  505. colision(pEnemigosM3[j]->x + 1, pEnemigosM3[j]->y + 1, balas3[i]->x, balas3[i]->y) ||
  506. colision(pEnemigosM3[j]->x + 2, pEnemigosM3[j]->y + 1, balas3[i]->x, balas3[i]->y) ||
  507. colision(pEnemigosM3[j]->x + 3, pEnemigosM3[j]->y + 1, balas3[i]->x, balas3[i]->y)) {
  508. puntaje += 100;
  509. Console::SetCursorPosition(90, 1);
  510. Console::ForegroundColor = ConsoleColor::White;
  511. cout << "PUNTAJE = " << puntaje;
  512. pEnemigosM3[j]->borrar();
  513. delete pEnemigosM3[j];
  514. pEnemigosM3.erase(pEnemigosM3.begin() + j);
  515. j--;
  516. contE3--;
  517. if (contE3 == 0)
  518. {
  519. continuar3 = false;
  520. }
  521. }
  522. }
  523. for (int k = 0; k < pEnemigosA3.size(); k++) {
  524. if (colision(pEnemigosA3[k]->x, pEnemigosA3[k]->y + 1, balas3[i]->x, balas3[i]->y) ||
  525. colision(pEnemigosA3[k]->x + 1, pEnemigosA3[k]->y + 1, balas3[i]->x, balas3[i]->y) ||
  526. colision(pEnemigosA3[k]->x + 2, pEnemigosA3[k]->y + 1, balas3[i]->x, balas3[i]->y) ||
  527. colision(pEnemigosA3[k]->x + 3, pEnemigosA3[k]->y + 1, balas3[i]->x, balas3[i]->y)) {
  528. puntaje += 100;
  529. Console::SetCursorPosition(90, 1);
  530. Console::ForegroundColor = ConsoleColor::White;
  531. cout << "PUNTAJE = " << puntaje;
  532. pEnemigosA3[k]->borrar();
  533. delete pEnemigosA3[k];
  534. pEnemigosA3.erase(pEnemigosA3.begin() + k);
  535. k--;
  536. contE3--;
  537. if (contE3 == 0)
  538. {
  539. continuar3 = false;
  540. }
  541. }
  542. }
  543. for (int l = 0; l < pEnemigosC3.size(); l++) {
  544. if (colision(pEnemigosC3[l]->x, pEnemigosC3[l]->y + 1, balas3[i]->x, balas3[l]->y) ||
  545. colision(pEnemigosC3[l]->x + 1, pEnemigosC3[l]->y + 1, balas3[i]->x, balas3[i]->y) ||
  546. colision(pEnemigosC3[l]->x + 2, pEnemigosC3[l]->y + 1, balas3[i]->x, balas3[i]->y) ||
  547. colision(pEnemigosC3[l]->x + 3, pEnemigosC3[l]->y + 1, balas3[i]->x, balas3[i]->y)) {
  548. puntaje += 100;
  549. Console::SetCursorPosition(90, 1);
  550. Console::ForegroundColor = ConsoleColor::White;
  551. cout << "PUNTAJE = " << puntaje;
  552. pEnemigosC3[l]->borrar();
  553. delete pEnemigosC3[l];
  554. pEnemigosC3.erase(pEnemigosC3.begin() + l);
  555. l--;
  556. contE3--;
  557. if (contE3 == 0)
  558. {
  559. continuar3 = false;
  560. }
  561. }
  562. }
  563. }
  564. else {
  565. balas3[i]->borrar();
  566. delete balas3[i];
  567. balas3.erase(balas3.begin() + i);
  568. i--;
  569. break;
  570. }
  571. }
  572. _sleep(45);
  573. }
  574. system("cls");
  575. Console::SetCursorPosition(45, 37);
  576. cout << "NIVEL 4" << endl;
  577. system("pause");
  578. system("cls");
  579. int contE4 = 5;
  580. personaje nave4 = personaje(35, 37);
  581. vector<enemigo*>pEnemigosM4;
  582. vector<enemigos2*>pEnemigosA4;
  583. vector<enemigos3*>pEnemigosC4;
  584. bool continuar4 = true;
  585. vector<bala*> balas4;
  586. for (short i = 0; i < 2; i++) {
  587. int x = rand() % 31 + 20;
  588. int y = rand() % 16 + 7;
  589. pEnemigosA4.push_back(new enemigos2(x, y));
  590. }
  591. for (short i = 0; i < 2; i++) {
  592. int x = rand() % 31 + 20;
  593. int y = rand() % 16 + 5;
  594. pEnemigosM4.push_back(new enemigo(x, y));
  595. }
  596. for (short i = 0; i < 1; i++) {
  597. int x = rand() % 30 + 20;
  598. int y = rand() % 1 + 2;
  599. pEnemigosC4.push_back(new enemigos3(x, y));
  600. }
  601. while (continuar4) {
  602. if (kbhit()) {
  603. char direccion4 = getch();
  604. nave4.animar(direccion4);
  605. if (direccion4 == DISPARAR)
  606. {
  607. balas4.push_back(new bala(nave4.x + 4, nave4.y - 1));
  608. }
  609. }
  610. for (short i = 0; i < pEnemigosM4.size(); i++) {
  611. pEnemigosM4[i]->animar();
  612. }
  613. for (short i = 0; i < pEnemigosA4.size(); i++) {
  614. pEnemigosA4[i]->animar();
  615. }
  616. for (short i = 0; i < pEnemigosC4.size(); i++) {
  617. pEnemigosC4[i]->animar();
  618. }
  619. for (int i = 0; i < balas4.size(); i++) {
  620. if (balas4[i]->y != 2) {
  621. balas4[i]->animar();
  622. for (int j = 0; j < pEnemigosM4.size(); j++) {
  623. if (colision(pEnemigosM4[j]->x, pEnemigosM4[j]->y + 1, balas4[i]->x, balas4[i]->y) ||
  624. colision(pEnemigosM4[j]->x + 1, pEnemigosM4[j]->y + 1, balas4[i]->x, balas4[i]->y) ||
  625. colision(pEnemigosM4[j]->x + 2, pEnemigosM4[j]->y + 1, balas4[i]->x, balas4[i]->y) ||
  626. colision(pEnemigosM4[j]->x + 3, pEnemigosM4[j]->y + 1, balas4[i]->x, balas4[i]->y)) {
  627. puntaje += 100;
  628. Console::SetCursorPosition(90, 1);
  629. Console::ForegroundColor = ConsoleColor::White;
  630. cout << "PUNTAJE = " << puntaje;
  631. pEnemigosM4[j]->borrar();
  632. delete pEnemigosM4[j];
  633.  
  634. pEnemigosM4.erase(pEnemigosM4.begin() + j);
  635. j--;
  636. contE4--;
  637. if (contE4 == 0)
  638. {
  639. continuar3 = false;
  640. }
  641. }
  642. }
  643. for (int k = 0; k < pEnemigosA4.size(); k++) {
  644. if (colision(pEnemigosA4[k]->x, pEnemigosA4[k]->y + 1, balas4[i]->x, balas4[i]->y) ||
  645. colision(pEnemigosA4[k]->x + 1, pEnemigosA4[k]->y + 1, balas4[i]->x, balas4[i]->y) ||
  646. colision(pEnemigosA4[k]->x + 2, pEnemigosA4[k]->y + 1, balas4[i]->x, balas4[i]->y) ||
  647. colision(pEnemigosA4[k]->x + 3, pEnemigosA4[k]->y + 1, balas4[i]->x, balas4[i]->y)) {
  648. puntaje += 100;
  649. Console::SetCursorPosition(90, 1);
  650. Console::ForegroundColor = ConsoleColor::White;
  651. cout << "PUNTAJE = " << puntaje;
  652. pEnemigosA4[k]->borrar();
  653. delete pEnemigosA4[k];
  654. pEnemigosA4.erase(pEnemigosA4.begin() + k);
  655. k--;
  656. contE3--;
  657. if (contE4 == 0)
  658. {
  659. continuar4 = false;
  660. }
  661. }
  662. }
  663. for (int l = 0; l < pEnemigosC4.size(); l++) {
  664. if (colision(pEnemigosC4[l]->x, pEnemigosC4[l]->y + 1, balas4[i]->x, balas4[l]->y) ||
  665. colision(pEnemigosC4[l]->x + 1, pEnemigosC4[l]->y + 1, balas4[i]->x, balas3[i]->y) ||
  666. colision(pEnemigosC4[l]->x + 2, pEnemigosC4[l]->y + 1, balas4[i]->x, balas4[i]->y) ||
  667. colision(pEnemigosC4[l]->x + 3, pEnemigosC4[l]->y + 1, balas4[i]->x, balas4[i]->y)) {
  668. puntaje += 100;
  669. Console::SetCursorPosition(90, 1);
  670. Console::ForegroundColor = ConsoleColor::White;
  671. cout << "PUNTAJE = " << puntaje;
  672. pEnemigosC4[l]->borrar();
  673. delete pEnemigosC4[l];
  674. pEnemigosC4.erase(pEnemigosC4.begin() + l);
  675. l--;
  676. contE4--;
  677. if (contE4 == 0)
  678. {
  679. continuar4 = false;
  680. }
  681. }
  682. }
  683. }
  684. else {
  685. balas4[i]->borrar();
  686. delete balas4[i];
  687. balas4.erase(balas4.begin() + i);
  688. i--;
  689. break;
  690. }
  691. }
  692. _sleep(45);
  693. }
  694. }
  695. void instrucciones() {
  696.  
  697. Console::SetCursorPosition(50, 20);
  698. Console::ForegroundColor = ConsoleColor::DarkYellow;
  699. cout << "Derecha: ->" << endl;
  700.  
  701. Console::SetCursorPosition(50, 21);
  702. Console::ForegroundColor = ConsoleColor::DarkYellow;
  703. cout << "Izquierda: <-";
  704.  
  705. Console::SetCursorPosition(50, 22);
  706. Console::ForegroundColor = ConsoleColor::DarkYellow;
  707. cout << "Disparar: espacio";
  708. _sleep(5000);
  709. }
  710. void menu() {
  711. int n;
  712.  
  713. Console::SetCursorPosition(10, 9);
  714. cout << "*****************************************" << endl;
  715. Console::SetCursorPosition(10, 10);
  716. cout << "*****************************************" << endl;
  717. Console::SetCursorPosition(10, 11);
  718. cout << "* ** ** ***** *** **** ** ** **" << endl;
  719. Console::SetCursorPosition(10, 12);
  720. cout << "* ****** ** ** ***** ** *** ***** ** *** ****** ** **" << endl;
  721. Console::SetCursorPosition(10, 13);
  722. cout << "* ****** ** **** *** **** ** ****** *" << endl;
  723. Console::SetCursorPosition(10, 14);
  724. cout << "* *** ** ** ** **** ** *** ***** ** *** *** ** ** *" << endl;
  725. Console::SetCursorPosition(10, 15);
  726. cout << "* *** ** ** ** **** ** *** ***** ** *** *** ** ** *" << endl;
  727. Console::SetCursorPosition(10, 16);
  728. cout << "* ** ** ** ** ** *** *** ** *** ** ** *" << endl;
  729. Console::SetCursorPosition(10, 17);
  730. cout << "*****************************************" << endl;
  731. Console::SetCursorPosition(10, 18);
  732. cout << "*****************************************" << endl;
  733.  
  734.  
  735. Console::SetCursorPosition(50, 20);
  736. cout << "1.Jugar" << endl;
  737. Console::SetCursorPosition(50, 21);
  738. cout << "0.Salir";
  739. Console::SetCursorPosition(50, 22);
  740. cout << "Digite la opcion:"; cin >> n;
  741.  
  742. switch (n)
  743. {
  744. case 0:break;
  745. case 1:
  746. system("cls");
  747. instrucciones();
  748. system("cls");
  749. jugar();
  750. default:
  751. break;
  752. }
  753.  
  754. }
  755. int main() {
  756. srand(time(NULL));
  757. Console::CursorVisible = false;
  758. menu();
  759. return 0;
  760. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement