KeeganT

Moving lil Guy

Nov 17th, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <windows.h>   // WinApi header
  3.  
  4. void drawPixel(int x, int y, int c)
  5. {
  6.     COORD coordinate;
  7.     coordinate.X = x;
  8.     coordinate.Y = y;
  9.     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  10.     SetConsoleTextAttribute(hConsole, c);
  11.     SetConsoleCursorPosition(hConsole, coordinate);
  12.     printf("%c", 219);
  13.     return;
  14. }
  15.  
  16. int main()
  17. {
  18.     system("mode 80, 25");
  19.  
  20.     int playerX = 5;
  21.     int playerY = 5;
  22.  
  23.     int FPS = 30;
  24.  
  25.     while (1)
  26.     {
  27.         if (GetAsyncKeyState(0x25)) playerX--;
  28.         if (GetAsyncKeyState(0x26)) playerY--;
  29.         if (GetAsyncKeyState(0x27)) playerX++;
  30.         if (GetAsyncKeyState(0x28)) playerY++;
  31.  
  32.         system("cls");
  33.         drawPixel(playerX, playerY, 106);
  34.         Sleep(1000/FPS);
  35.     }
  36.  
  37.     getch();
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment