Advertisement
Guest User

ASDSS

a guest
Apr 22nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1.  
  2.  
  3. #include<iostream>
  4. #include<Windows.h>
  5. #include<conio.h>
  6. #include<time.h>
  7. #include<time.h>
  8. //C:\Program Files(x86)\Windows Kits\10\References
  9.  
  10. using namespace std;
  11.  
  12.  
  13. enum terreno{camino,pared};
  14.  
  15. #define COLUMNAS 20
  16. #define FILAS 20
  17.  
  18. int matriz[FILAS][COLUMNAS] = {
  19. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  20. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  21. {1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1},
  22. {1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1},
  23. {1,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1},
  24. {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
  25. {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
  26. {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
  27. {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
  28. {1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1},
  29. {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
  30. {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
  31. {1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1},
  32. {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
  33. {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
  34. {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
  35. {1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1},
  36. {1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1},
  37. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  38. {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  39. };
  40.  
  41. class mapa {//////////////////////////////
  42.  
  43.  
  44.  
  45. public:
  46.  
  47. void dibujo() {
  48. for (int i = 0; i < FILAS; i++) {
  49. for (int j = 0; j < COLUMNAS; j++) {
  50. if (matriz[i][j] == 1) {
  51. cout << char(219);
  52.  
  53. }
  54. if (matriz[i][j] == 0) {
  55. cout << " ";
  56.  
  57.  
  58. }
  59.  
  60. }
  61. cout << endl;
  62. }
  63. }
  64.  
  65.  
  66. };
  67.  
  68. #define up 72
  69. #define down 80
  70. #define right 77
  71. #define left 75
  72.  
  73.  
  74. void gotoxy(int x, int y) {
  75.  
  76.  
  77. HANDLE hCon;
  78. hCon = GetStdHandle(STD_OUTPUT_HANDLE);
  79. COORD dwPos;
  80. dwPos.Y = y;
  81. dwPos.X = x;
  82.  
  83.  
  84. SetConsoleCursorPosition(hCon, dwPos);
  85. }
  86.  
  87. class juego {
  88. // ejes de bala
  89. int upp=0, aux = 1;
  90.  
  91.  
  92. int xx=7, yy=8;
  93. int x = 6, y = 6;
  94. int bx, by;
  95.  
  96. public:
  97. mapa* map;
  98. void mover(char tecla);
  99. void borrar();
  100. void mover_enemigo();
  101. void colision();
  102. void balas();
  103.  
  104.  
  105. };
  106.  
  107.  
  108. void juego::balas() {
  109.  
  110. char tecla;
  111.  
  112.  
  113. if (_kbhit())
  114. {
  115. tecla = _getch();
  116.  
  117. if (tecla == up) {
  118. bx = x; by = y;
  119. upp = 0;
  120. }
  121.  
  122. }
  123.  
  124. if (upp < 15-by) {
  125. if (matriz[by-aux ][bx] == camino) {
  126. cout << "@";
  127. gotoxy(bx - aux, by );
  128. cout << ".";
  129.  
  130. upp++;
  131. aux++;
  132. }
  133. }
  134. }
  135. void juego::colision() {
  136. if (xx == x && yy == y) {
  137. gotoxy(5, 5);
  138. cout << "COLISION-COLISION-COLISION-COLISION-COLISION-COLISION-COLISION";
  139. cout << "COLISION-COLISION-COLISION-COLISION-COLISION-COLISION-COLISION";
  140. system("pause>0");
  141. system("cls");
  142. map->dibujo();
  143. }
  144. }
  145.  
  146.  
  147. void juego::mover_enemigo() {
  148. short a;
  149. a = rand() % 5;
  150.  
  151.  
  152.  
  153. if (a == 0) {
  154. if (matriz[yy][xx + 2] == camino) {
  155. gotoxy(xx, yy);
  156. cout << " ";
  157. xx += 2;
  158. gotoxy(xx, yy);
  159. cout << char(999);
  160. }
  161. }
  162. if (a == 1) {
  163. if (matriz[yy][xx - 2] == camino) {
  164. gotoxy(xx, yy);
  165. cout << " ";
  166. xx -= 2;
  167. gotoxy(xx, yy);
  168. cout << char(999);
  169. }
  170. }
  171. if (a == 2) {
  172. if (matriz[yy + 2][xx] == camino) {
  173. gotoxy(xx, yy);
  174. cout << " ";
  175. yy += 2;
  176. gotoxy(xx, yy);
  177. cout << char(999);
  178. }
  179. }
  180. if (a == 3) {
  181. if (matriz[yy - 2][xx] == camino) {
  182. gotoxy(xx, yy);
  183. cout << " ";
  184. yy -= 2;
  185. gotoxy(xx, yy);
  186. cout << char(999);
  187. }
  188. }
  189.  
  190. }
  191.  
  192. void juego::borrar() {
  193.  
  194.  
  195. gotoxy(x, y);
  196. cout << " ";
  197.  
  198. }
  199.  
  200. void juego::mover(char tecla) {
  201.  
  202.  
  203. if (tecla == 'w') {
  204. borrar();
  205.  
  206. if (matriz[y - 1][x] == camino) {
  207.  
  208. y--;
  209. gotoxy(x, y);
  210. cout << "@";
  211.  
  212. }else {
  213. gotoxy(x, y);
  214. cout << "@";
  215.  
  216. }
  217. }
  218. else if (tecla == 's') {
  219. borrar();
  220.  
  221.  
  222. if (matriz[y + 1][x] == camino) {
  223. y++;
  224. gotoxy(x, y);
  225. cout << "@";
  226.  
  227. }else {
  228. gotoxy(x, y);
  229. cout << "@";
  230. }
  231. }
  232.  
  233. else if (tecla == 'a') {
  234. borrar();
  235.  
  236. if (matriz[y][x-1] == camino) {
  237. x--;
  238. gotoxy(x, y);
  239. cout << "@";
  240. }
  241. else {
  242. gotoxy(x, y);
  243. cout << "@";
  244. }
  245. }
  246.  
  247. else if (tecla == 'd') {
  248. borrar();
  249.  
  250. if (matriz[y][x+1] == camino) {
  251. x++;
  252. gotoxy(x, y);
  253. cout << "@";
  254. }
  255.  
  256. else {
  257.  
  258. gotoxy(x, y);
  259. cout << "@";
  260. }
  261. }
  262. else {
  263.  
  264. }
  265.  
  266.  
  267. }
  268.  
  269.  
  270. int main() {
  271.  
  272. srand(time(NULL));
  273. juego _juego;
  274. char tecla;
  275.  
  276.  
  277. mapa map;
  278. map.dibujo();
  279. while (1) {
  280.  
  281. if (_kbhit())
  282. {
  283. tecla = _getch();
  284. _juego.mover(tecla);
  285.  
  286. }
  287. _juego.balas();
  288. //_juego.mover_enemigo();
  289. //_juego.colision();
  290. Sleep(100);
  291. }
  292. system("pause");
  293. return 0;
  294. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement