Advertisement
Guest User

Galaga v0.9

a guest
Oct 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6. using namespace System;
  7.  
  8. #define ARRIBA 72
  9. #define IZQUIERDA 75
  10. #define ABAJO 80
  11. #define DERECHA 77
  12.  
  13. typedef struct personaje {
  14. short x;
  15. short y;
  16. char imagen;
  17. personaje(short _x = 10, short _y = 10, char _imagen = '*') {
  18. x = _x;
  19. y = _y;
  20. imagen = _imagen;
  21. }
  22. void animar(short direccion) {
  23. borrar();
  24. mover(direccion);
  25. dibujar();
  26. }
  27. void borrar() {
  28. Console::SetCursorPosition(x, y);
  29. cout << " ";
  30. }
  31. void mover(short direccion) {
  32. switch (direccion) {
  33. case ARRIBA : y--; break;
  34. case ABAJO : y++; break;
  35. case IZQUIERDA: x--; break;
  36. case DERECHA : x++; break;
  37. }
  38. }
  39. void dibujar() {
  40. Console::SetCursorPosition(x, y);
  41. cout << imagen;
  42. }
  43. };
  44. typedef struct enemigo {
  45. short x;
  46. short y;
  47. short dx;
  48. char imagen;
  49. enemigo(short _x = 10, short _y = 10, char _imagen = '*') {
  50. x = _x;
  51. y = _y;
  52. dx = 1;
  53. imagen = _imagen;
  54. }
  55. void animar() {
  56. borrar();
  57. mover();
  58. dibujar();
  59. }
  60. void borrar() {
  61. Console::SetCursorPosition(x, y);
  62. cout << " ";
  63. }
  64. void mover() {
  65. if (x == 0 || x == 40) {
  66. dx *= -1;
  67. y++;
  68. }
  69. x += dx;
  70. }
  71. void dibujar() {
  72. Console::SetCursorPosition(x, y);
  73. cout << imagen;
  74. }
  75. };
  76.  
  77. void jugar() {
  78. personaje p1;
  79. short n;
  80. cout << "Ingrese la cantidad de enemigos: ";
  81. cin >> n;
  82. enemigo* enemigos = new enemigo[n];
  83. for (short i = 0; i < n; i++) {
  84. short x = Random::Random().Next(0, 40);
  85. short y = Random::Random().Next(0, 5);
  86. enemigos[i].x = x;
  87. enemigos[i].y = y;
  88. _sleep(250);
  89. }
  90. while (true) {
  91. if (kbhit()) {
  92. short direccion = getch();
  93. p1.animar(direccion);
  94. }
  95. for (short i = 0; i < n; i++)
  96. enemigos[i].animar();
  97. _sleep(250);
  98. }
  99. }
  100. int main() {
  101. Console::CursorVisible = false;
  102. jugar();
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement