Advertisement
Guest User

..

a guest
Nov 11th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include<ctype.h>
  6. #define ARRIBA 'W'
  7. #define ABAJO 'S'
  8. #define DERECHA 'D'
  9. #define IZQUIERDA 'A'
  10. using namespace std;
  11. using namespace System;
  12. struct personaje {
  13. short pasos;
  14. short x;
  15. short y;
  16. personaje(short a = 30, short b = 39, short c = 0) {
  17. x = a;
  18. y = b;
  19. pasos = c;
  20. }
  21. void mover(char direccion) {
  22. switch (direccion) {
  23. case ARRIBA: y--; pasos++; break;
  24. case ABAJO: y++; pasos++; break;
  25. case IZQUIERDA: x--; pasos++; break;
  26. case DERECHA: x++; pasos++; break;
  27. }
  28. }
  29. void dibujar() {
  30. Console::SetCursorPosition(x + 1, y);
  31. cout << " 8 ";
  32. Console::SetCursorPosition(x, y + 1);
  33. cout << " V[*]V ";
  34. Console::SetCursorPosition(x, y + 2);
  35. cout << "Vv[*]vV";
  36. }
  37. void borrar() {
  38. Console::SetCursorPosition(x + 1, y);
  39. cout << " ";
  40. Console::SetCursorPosition(x, y + 1);
  41. cout << " ";
  42. Console::SetCursorPosition(x, y + 2);
  43. cout << " ";
  44. }
  45. void animar(char direccion) {
  46. borrar();
  47. mover(direccion);
  48. restriccion();
  49. dibujar();
  50. }
  51. void restriccion() {
  52. if (x == -1) {
  53. x = 0;
  54. }
  55. else if (y == -1) {
  56. y = 0;
  57. }
  58. else if (x == 60) {
  59. x--;
  60. }
  61. else if (y == 40) {
  62. y--;
  63. }
  64. }
  65. };
  66. struct avispa {
  67. short pasos;
  68. short x;
  69. short y;
  70. short mx = 1;
  71. short my = 1;
  72. short t = 0;
  73. avispa(short a = 20, short b = 20, short c = 0) {
  74. x = a;
  75. y = b;
  76. pasos = c;
  77. }
  78. void mover() {
  79. if (x == 0 || x == 60) {
  80. mx *= -1;
  81. }
  82. else if (y == 0 || y == 20) {
  83. my *= -1;
  84. }
  85. x += mx;
  86. y += my;
  87. }
  88. void dibujar() {
  89. Console::SetCursorPosition(x, y);
  90. system("color 0C");
  91. cout << "(8/*/8)";
  92. }
  93. void borrar() {
  94. Console::SetCursorPosition(x, y);
  95. cout << " ";
  96. }
  97. void animar() {
  98. if (t == 1000) {
  99. borrar();
  100. mover();
  101. restriccion();
  102. dibujar();
  103. t = 0;
  104. }
  105. t++;
  106. }
  107. void restriccion() {
  108. if (x == -1) {
  109. x = 0;
  110. }
  111. else if (y == -1) {
  112. y = 0;
  113. }
  114. }
  115. };
  116.  
  117. void juego() {
  118. Console::CursorVisible = false;
  119. Random r;
  120. personaje* p = new personaje[1];
  121. avispa* a = new avispa[4];
  122. for (int i = 0; i < 4; i++) {
  123. a[i].x = r.Next(0, 40);
  124. a[i].y = r.Next(0, 20);
  125. }
  126.  
  127. bool gameover = true;
  128. while (gameover) {
  129. if (toupper(_kbhit())) {
  130. char direccion = _getch();
  131. p[0].animar(direccion);
  132. }
  133. for (int i = 0; i < 4; i++) {
  134. a[i].animar();
  135. }
  136. if (p[0].pasos == 30) {
  137. gameover = false;
  138. }
  139. }
  140. system("pause>0");
  141. delete p, a;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement