Advertisement
Guest User

Untitled

a guest
Sep 6th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <conio.h>
  4.  
  5. using namespace std;
  6.  
  7. //Declare the player's position
  8. int nPlayerX=4, nPlayerY=4;
  9. //Colour
  10. HANDLE colour = GetStdHandle(STD_OUTPUT_HANDLE);
  11.  
  12. void gotoxy(int x, int y)
  13. {
  14. COORD c;
  15. c.X=x;
  16. c.Y=y;
  17. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
  18. }
  19.  
  20. int main()
  21. {
  22. while(true)
  23. {
  24. //Map drawing
  25. system("cls");
  26.  
  27. //Draw the player to the screen
  28. gotoxy( nPlayerX, nPlayerY);
  29. SetConsoleTextAttribute(colour, 14);
  30. cout<<"@"<<"("<<nPlayerX<<","<<nPlayerY<<")";
  31. SetConsoleTextAttribute(colour, 15);
  32.  
  33. //Input
  34. char input = getch();
  35.  
  36. //Processing
  37.  
  38. int nDeltaX;
  39. int nDeltaY;
  40.  
  41. switch(input)
  42. {
  43. //Move up
  44. case 'w':
  45. nDeltaX = 0;
  46. nDeltaY = -1;
  47. break;
  48.  
  49. //Move left
  50. case 'a':
  51. nDeltaX = -1;
  52. nDeltaY = 0;
  53. break;
  54.  
  55. //Mode down
  56. case 's':
  57. nDeltaX = 0;
  58. nDeltaY = 1;
  59. break;
  60.  
  61. //Move right
  62. case 'd':
  63. nDeltaX = 1;
  64. nDeltaY = 0;
  65. break;
  66.  
  67. //Ignore
  68. default:
  69. break;
  70. }
  71. //Check and see if we're allowed to move in the specified direction
  72. // ( irrelevant, deleted for now)
  73. nPlayerX += nDeltaX;
  74. nPlayerY += nDeltaY;
  75.  
  76. }
  77.  
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement