Advertisement
Guest User

Untitled

a guest
May 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. using namespace std;
  4. using namespace System;
  5.  
  6. #define UP 72
  7. #define LEFT 75
  8. #define DOWN 80
  9. #define RIGHT 77
  10.  
  11. void dibuja(int x, int y, ConsoleColor color) {
  12.     Console::ForegroundColor = color;
  13.     Console::SetCursorPosition(x, y);
  14.     cout << (char)1;
  15. }
  16.  
  17.  
  18. int main() {
  19.     int c, x=5, y=7;
  20.     dibuja(x, y, ConsoleColor::Yellow);
  21.  
  22.     while (true) {
  23.         if (_kbhit()) {
  24.             c = _getch();
  25.             c = toupper(c);
  26.             switch (c) {
  27.             case 'W':
  28.             case UP:
  29.                 y--;
  30.                 break;
  31.             case 'S':
  32.             case DOWN:
  33.                 y++;
  34.                 break;
  35.             case 'A':
  36.             case LEFT:
  37.                 x--;
  38.                 break;
  39.             case 'D':
  40.             case RIGHT:
  41.                 x++;
  42.                 break;
  43.             }
  44.             Console::Clear();
  45.             dibuja(x, y, ConsoleColor::Yellow);
  46.         }
  47.     }
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement