Advertisement
dioses1302

Untitled

Nov 21st, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <time.h>
  4. #include <vector>
  5.  
  6. #define IZQUIERDA 75
  7. #define DERECHA 77
  8. #define DISPARO 32
  9. #define ALEATORIO(INI,FIN) rand()% (FIN-INI+1)+INI
  10.  
  11.  
  12. using namespace std;
  13. using namespace System;
  14.  
  15. struct nave {
  16. short x;
  17. short y;
  18. char imagen[2][5] = { { ' ', 'm', 'A', 'm', ' ' },
  19. { 'M', 'A', 'Z', 'A', 'M' } };
  20. short balas;
  21. nave(short _x = 30, short _y = 28, short _balas = 50) {
  22. x = _x;
  23. y = _y;
  24. balas = _balas;
  25. }
  26. void mover(char tecla) {
  27. switch (tecla) {
  28. case IZQUIERDA: if (x>1) x -= 3; break;
  29. case DERECHA: if (x<87) x += 3; break;
  30. }
  31. }
  32. void borrar() {
  33. for (int i = 0; i < 2; i++) {
  34. for (int j = 0; j < 5; j++) {
  35. Console::SetCursorPosition(x + j, y + i);
  36. cout << " ";
  37. }
  38. }
  39. }
  40. void dibujar() {
  41. for (int i = 0; i < 2; i++) {
  42. for (int j = 0; j < 5; j++) {
  43. Console::ForegroundColor = ConsoleColor::Red;
  44. Console::SetCursorPosition(x + j, y + i);
  45. cout << imagen[i][j];
  46. }
  47. }
  48. }
  49. void animar(char _tecla) {
  50.  
  51. borrar();
  52. mover(_tecla);
  53. dibujar();
  54. }
  55. };
  56.  
  57. struct avispa {
  58. int retraso;
  59. short x;
  60. short y;
  61. short balas;
  62. short dx, dy;
  63. avispa(short _x = 10, short _y = 10) {
  64. x = _x;
  65. y = _y;
  66. dx = 1;
  67. dy = 1;
  68. retraso = 0;
  69. }
  70. ~avispa() {
  71. Console::SetCursorPosition(x, y);
  72. cout << " ";
  73. }
  74. void animar() {
  75. if (retraso == 500) {
  76. Borrar();
  77. Mover();
  78. Dibujar();
  79. retraso = 0;
  80. }
  81. retraso++;
  82.  
  83. }
  84. void animar2() {
  85. if (retraso == 500) {
  86. Borrar();
  87. Mover2();
  88. Dibujar();
  89. retraso = 0;
  90. }
  91. retraso++;
  92.  
  93. }
  94.  
  95. void Mover() {
  96. if (x == 0) dx *= -1;
  97. if (x == 21) dx *= -1;
  98. if (y == 5) dy *= -1;
  99. if (y == 18) dy *= -1;
  100.  
  101. x += dx;
  102. y += dy;
  103. }
  104.  
  105. void Mover2() {
  106. if (x == 60) dx *= -1;
  107. if (x == 80) dx *= -1;
  108. if (y == 5) dy *= -1;
  109. if (y == 18) dy *= -1;
  110.  
  111. x += dx;
  112. y += dy;
  113. }
  114.  
  115. void Borrar() {
  116. Console::SetCursorPosition(x, y);
  117. cout << " ";
  118. }
  119.  
  120.  
  121. void Dibujar() {
  122. Console::ForegroundColor = ConsoleColor::Blue;
  123. Console::SetCursorPosition(x, y);
  124. cout << "A";
  125. }
  126. };
  127.  
  128. struct mariposa {
  129. int retraso;
  130. short x;
  131. short y;
  132. short dx, dy;
  133. mariposa(short _x = 10, short _y = 10) {
  134. x = _x;
  135. y = _y;
  136. dx = 1;
  137. dy = 1;
  138. retraso = 0;
  139. }
  140. ~mariposa() {
  141. Console::SetCursorPosition(x, y);
  142. cout << " ";
  143. }
  144. void animar() {
  145. if (retraso == 500) {
  146. Borrar();
  147. Mover();
  148. Dibujar();
  149. retraso = 0;
  150. }
  151. retraso++;
  152. }
  153.  
  154. void Mover() {
  155. if (x == 20 || x == 60) {
  156. dx *= -1;
  157. y += dy;
  158. if (y == 4 || y == 20) { dy *= -1; }
  159. }
  160.  
  161. x += dx;
  162.  
  163. }
  164. void Borrar() {
  165.  
  166. Console::SetCursorPosition(x, y);
  167. cout << " ";
  168. }
  169.  
  170.  
  171. void Dibujar() {
  172. Console::ForegroundColor = ConsoleColor::Cyan;
  173. Console::SetCursorPosition(x, y);
  174. cout << "M";
  175. }
  176. };
  177.  
  178. struct comandante {
  179. int retraso;
  180. short x;
  181. short y;
  182. short dx, dy;
  183. int vidas;
  184. char img;
  185. comandante(short _x = 10, short _y = 10) {
  186. x = _x;
  187. y = _y;
  188. dx = 1;
  189. dy = 1;
  190. vidas = 2;
  191. img = 'C';
  192. retraso = 0;
  193. }
  194. ~comandante() {
  195. Console::SetCursorPosition(x, y);
  196. cout << " ";
  197. }
  198. void animar() {
  199. if (retraso == 500) {
  200. Borrar();
  201. Mover();
  202. Dibujar();
  203. retraso = 0;
  204. }
  205. retraso++;
  206. }
  207.  
  208. void Mover() {
  209. if (x == 20 || x == 60) dx *= -1;
  210.  
  211. x += dx;
  212. }
  213. void Borrar() {
  214. if (vidas == 2) {
  215. Console::SetCursorPosition(x, y);
  216. cout << " ";
  217. }
  218. if (vidas == 1) {
  219. Console::SetCursorPosition(x, y);
  220. cout << " ";
  221. }
  222. }
  223. void Dibujar() {
  224. if (vidas == 2) {
  225. Console::ForegroundColor = ConsoleColor::Green;
  226. Console::SetCursorPosition(x, y);
  227. cout << img;
  228. }
  229. else
  230. {
  231. Console::ForegroundColor = ConsoleColor::DarkMagenta;
  232. Console::SetCursorPosition(x, y);
  233. cout << img;
  234. }
  235.  
  236. }
  237. };
  238.  
  239. struct bala {
  240. int x;
  241. int y;
  242. bala(int _x = 10, int _y = 10) {
  243. x = _x;
  244. y = _y;
  245. }
  246. void dibujar() {
  247. Console::ForegroundColor = ConsoleColor::Red;
  248. Console::SetCursorPosition(x, y);
  249. cout << "*";
  250. }
  251. void borrar() {
  252. Console::SetCursorPosition(x, y);
  253. cout << " ";
  254. }
  255. void mover() {
  256. y--;
  257. }
  258. void morir(vector<comandante*> &comandante1, vector<avispa*> &avispa1, vector<avispa*> &avispa2, vector<mariposa*> &mariposa1, int &puntaje) {
  259. for (int e = 0; e < comandante1.size(); e++) {
  260. if (x == comandante1[e]->x + 1 && y == comandante1[e]->y) {
  261. comandante1[e]->vidas--;
  262. if (comandante1[e]->vidas == 0) {
  263. delete comandante1[e];
  264. comandante1.erase(comandante1.begin() + e);
  265. e--;
  266. puntaje += 400;
  267. }
  268. }
  269. }
  270. for (int e = 0; e < avispa1.size(); e++) {
  271. if (x == avispa1[e]->x + 1 && y == avispa1[e]->y) {
  272. delete avispa1[e];
  273. avispa1.erase(avispa1.begin() + e);
  274. e--;
  275. puntaje += 100;
  276. }
  277. }
  278. for (int e = 0; e < avispa2.size(); e++) {
  279. if (x == avispa2[e]->x + 1 && y == avispa2[e]->y ) {
  280. delete avispa2[e];
  281. avispa2.erase(avispa2.begin() + e);
  282. e--;
  283. puntaje += 100;
  284. }
  285. }
  286. for (int e = 0; e < mariposa1.size(); e++) {
  287. if (x == mariposa1[e]->x + 1 && y == mariposa1[e]->y) {
  288. delete mariposa1[e];
  289. mariposa1.erase(mariposa1.begin() + e);
  290. e--;
  291. puntaje += 160;
  292. }
  293. }
  294. }
  295. void animar(vector<comandante*> &comandante1, vector<avispa*> &avispa1, vector<avispa*> &avispa2, vector<mariposa*> &mariposa1, int &puntaje) {
  296. borrar();
  297. mover();
  298. dibujar();
  299. morir(comandante1, avispa1, avispa2, mariposa1, puntaje);
  300. }
  301. };
  302.  
  303. bool colision(int &xB, int &yB, int x, int y) {
  304. if (xB == x && yB == y) {
  305. return true;
  306. }
  307. else {
  308. return false;
  309. }
  310. }
  311.  
  312. void jugar() {
  313. nave n;
  314. int retraso = 0;
  315. n.dibujar();
  316. vector<bala*> balas;
  317. vector<avispa*> avispa1;
  318. vector<avispa*> avispa2;
  319. vector<mariposa*> mariposa1;
  320. vector<comandante*>comandante1;
  321.  
  322. int cantE = 24;
  323. int puntaje = 0;
  324. bool continuar = true;
  325.  
  326. Console::SetCursorPosition(90, 1);
  327. Console::ForegroundColor = ConsoleColor::White;
  328. cout << "PUNTAJE = " << puntaje;
  329.  
  330.  
  331. for (int i = 0; i < 2; i++) {
  332. int x = ALEATORIO(2, 17);
  333. int y = ALEATORIO(6, 16);
  334.  
  335. avispa1.push_back(new avispa(x, y));
  336.  
  337. }
  338.  
  339. for (int i = 0; i < 2; i++) {
  340. int x = ALEATORIO(65, 76);
  341. int y = ALEATORIO(6, 16);
  342. avispa2.push_back(new avispa(x, y));
  343.  
  344. }
  345.  
  346. for (int i = 0; i < 4; i++) {
  347.  
  348. int x1 = ALEATORIO(22, 56);
  349. int y1 = ALEATORIO(5, 17);
  350.  
  351. mariposa1.push_back(new mariposa(x1, y1));
  352. }
  353. for (int i = 0; i < 4; i++) {
  354.  
  355. int x1 = ALEATORIO(21, 58);
  356. int y1 = ALEATORIO(3, 5);
  357.  
  358. comandante1.push_back(new comandante(x1, y1));
  359. }
  360.  
  361. while (continuar) {
  362. if (kbhit()) {
  363. char tecla = getch();
  364. if (tecla == DISPARO) {
  365. balas.push_back(new bala(n.x + 2, n.y - 1));
  366. }
  367. n.animar(tecla);
  368. }
  369.  
  370. for (int i = 0; i < avispa1.size(); i++) {
  371. avispa1[i]->animar();
  372.  
  373. }
  374. for (int i = 0; i < avispa2.size(); i++) {
  375. avispa2[i]->animar2();
  376.  
  377. }
  378. for (int i = 0; i < mariposa1.size(); i++) {
  379. mariposa1[i]->animar();
  380.  
  381. }
  382. for (int i = 0; i < comandante1.size(); i++) {
  383. comandante1[i]->animar();
  384.  
  385. }
  386.  
  387.  
  388. for (int i = 0; i < balas.size(); i++, retraso++) {
  389. if (retraso == 300) {
  390. if (balas[i]->y != 2) {
  391. balas[i]->animar(comandante1, avispa1, avispa2, mariposa1, puntaje);
  392.  
  393. if (balas[i]->y == 2) {
  394. balas[i]->borrar();
  395. delete balas[i];
  396. balas.erase(balas.begin() + i);
  397. i--;
  398.  
  399. }
  400. retraso = 0;
  401. }
  402. }
  403.  
  404.  
  405.  
  406. }
  407.  
  408. }
  409.  
  410. system("cls");
  411. cout << "NIVEL 2" << endl;
  412. system("pause");
  413. }
  414.  
  415. void hola() {
  416.  
  417.  
  418. for (int i = 20; i > 7; i--) {
  419. Console::SetCursorPosition(10, i);
  420. Console::ForegroundColor = ConsoleColor::Red;
  421. cout << "*";
  422. _sleep(77);
  423. }
  424.  
  425. for (int i = 10; i < 16; i++) {
  426. Console::SetCursorPosition(i, 15);
  427. Console::ForegroundColor = ConsoleColor::Red;
  428. cout << "*";
  429. _sleep(77);
  430. }
  431.  
  432. for (int i = 20; i > 7; i--) {
  433. Console::SetCursorPosition(15, i);
  434. Console::ForegroundColor = ConsoleColor::Red;
  435. cout << "*";
  436. _sleep(77);
  437. }
  438.  
  439. for (int i = 20; i > 12; i--) {
  440. Console::SetCursorPosition(18, i);
  441. Console::ForegroundColor = ConsoleColor::Red;
  442. cout << "*";
  443. _sleep(77);
  444. }
  445.  
  446. Console::SetCursorPosition(25, 10);
  447. Console::ForegroundColor = ConsoleColor::Red;
  448. cout << "HOLA";
  449. _sleep(700);
  450.  
  451. Console::SetCursorPosition(35, 5);
  452. Console::ForegroundColor = ConsoleColor::Red;
  453. cout << "PROFESOR";
  454. _sleep(700);
  455. Console::SetCursorPosition(55, 9);
  456. Console::ForegroundColor = ConsoleColor::Red;
  457. cout << ":D";
  458.  
  459.  
  460.  
  461. _sleep(700);
  462. system("cls");
  463. }
  464.  
  465. int main() {
  466. /*hola();*/
  467.  
  468. srand(time(NULL));
  469. Console::CursorVisible = false;
  470.  
  471. jugar();
  472. getch();
  473. return 0;
  474. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement