Advertisement
Guest User

crucesita xD

a guest
Oct 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. // ConsoleApplication2.cpp : main project file.
  2. #include <iostream>"
  3. #include "conio.h"
  4. #include "iostream"
  5. #include <Windows.h>
  6.  
  7. using namespace System;
  8. using namespace std;
  9.  
  10. #define WIDTH 80
  11. #define HEIGHT 40
  12. #define DERECHA 77
  13. #define IZQUIERDA 75
  14. #define ARRIBA 72
  15. #define ABAJO 80
  16.  
  17. void ubicacion(int x, int y) { Console::SetCursorPosition(x, y); }
  18. void jugador(int x, int y)
  19. {
  20. cout << " * "; y++; Console::SetCursorPosition(x, y);
  21. cout << "***"; y++; Console::SetCursorPosition(x, y);
  22. cout << " * "; y++;
  23. }
  24.  
  25. void borrar(int x, int y)
  26. {
  27. cout << " " << endl; y++; Console::SetCursorPosition(x, y);
  28. cout << " " << endl; y++; Console::SetCursorPosition(x, y);
  29. cout << " ";
  30. }
  31. //PROGRAMA PRINCIPAL
  32. int main()
  33. {
  34. Console::SetWindowSize(WIDTH, HEIGHT);
  35. int x = WIDTH / 2, y = HEIGHT / 2;
  36. ubicacion(x, y); jugador(x,y);
  37. char tecla;
  38.  
  39. while (1)
  40. {
  41. if (_kbhit())//detecta si se pulsa una tecla
  42. {
  43. tecla = _getch(); //identifica la tecla pulsada
  44.  
  45. //BORRAR
  46. ubicacion(x, y); borrar(x,y);
  47.  
  48. //CAMBIA POSICION
  49. if (x < 77)
  50. {
  51. if (tecla == DERECHA) x++;
  52. }
  53. if (x > 0)
  54. {
  55. if (tecla == IZQUIERDA) x--;
  56. }
  57. if (y>0)
  58. {
  59. if (tecla == ARRIBA) y--;
  60. }
  61. if (y < 38)
  62. {
  63. if (tecla == ABAJO) y++;
  64. }
  65.  
  66. //DIBUJAR
  67. ubicacion(x, y); jugador(x,y);
  68. }
  69. }
  70.  
  71. _getch();
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement