Advertisement
Guest User

a

a guest
Nov 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4. using namespace System;
  5.  
  6. struct obj {
  7. int x, y;
  8. int dx, dy;
  9. };
  10.  
  11.  
  12.  
  13. int matr[20][20] = { {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
  14. {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  15. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  16. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  17. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  18. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  19. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  20. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  21. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  22. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  23. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  24. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  25. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  26. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  27. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  28. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  29. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  30. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  31. { 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 },
  32. { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 } };
  33.  
  34. void gotoxy(int x, int y ) {
  35. Console::SetCursorPosition(x, y);
  36. }
  37.  
  38. void dibujarObj(obj Persona) {
  39.  
  40.  
  41. Console::BackgroundColor = ConsoleColor::Green;
  42.  
  43. gotoxy(Persona.x+1, Persona.y);
  44. cout << " ";
  45. gotoxy(Persona.x, Persona.y + 1);
  46. cout << " ";
  47. }
  48.  
  49. void borrarObj(obj Persona) {
  50. if (matr[Persona.y][Persona.x] == 1) {
  51. Console::BackgroundColor = ConsoleColor::Red;
  52. }
  53. else {
  54. Console::BackgroundColor = ConsoleColor::White;
  55. }
  56. gotoxy(Persona.x, Persona.y);
  57. cout << " ";
  58. gotoxy(Persona.x, Persona.y + 1);
  59. cout << " ";
  60. }
  61.  
  62.  
  63. void desplazar_fichar(obj Persona) {
  64. for (int i = 0; ; i++) {
  65. if (i % 10000000 == 0) {
  66. if (Persona.dx > 0 && matr[Persona.y][Persona.x + Persona.dx + 2 ] == 1) {
  67. Persona.dx *= -1;
  68. }
  69. else if (Persona.dx < 0 && matr[Persona.y][Persona.x + Persona.dx] == 1) {
  70. Persona.dx *= -1;
  71. }
  72.  
  73. borrarObj(Persona);
  74. Persona.x += Persona.dx;
  75. dibujarObj(Persona);
  76. }
  77. }
  78. }
  79.  
  80. int main() {
  81. obj Personaje;
  82. Personaje.x = 1;
  83. Personaje.y = 1;
  84. Personaje.dx = 1;
  85. for (int i = 0; i < 20; i++) {
  86. for (int j = 0; j < 20; j++) {
  87. if (matr[i][j] == 1) {
  88. Console::BackgroundColor = ConsoleColor::Red;
  89. }
  90. else {
  91. Console::BackgroundColor = ConsoleColor::White;
  92. }
  93. cout << " ";
  94. }
  95. cout << endl;
  96. }
  97. desplazar_fichar(Personaje);
  98.  
  99.  
  100. _getch();
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement