Advertisement
szymski

Untitled

Aug 20th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. #include <windows.h>
  2. #include <winuser.h>
  3.  
  4. #define set_char(X,Y,C,A) {invisibleBuf[Y][X].Char.AsciiChar=C; invisibleBuf[Y][X].Attributes=A; }
  5.  
  6. #define is_down(K) GetAsyncKeyState(K)&(1<<16)
  7.  
  8. HANDLE stdHandle;
  9. CHAR_INFO invisibleBuf[70][90];
  10.  
  11. void toScreen() {
  12. SMALL_RECT r{0, 0, 90, 70};
  13. WriteConsoleOutput(stdHandle, (const CHAR_INFO*)&invisibleBuf, COORD{90, 70}, COORD{0, 0}, &r);
  14. }
  15.  
  16. int attr = 0;
  17.  
  18. void drawImg(int x, int y, long long img) {
  19. while(img) {
  20. for(int i = 0; i < 8; i++) {
  21. set_char(x, y, ((img) & 1) ? 219 : ' ', attr);
  22. x++;
  23. img>>=1;
  24. }
  25.  
  26. x -= 8;
  27. y--;
  28. }
  29. }
  30.  
  31. void clearScreen() {
  32. for(int i = 0; i < 90 * 70; i++)
  33. set_char(i, 0, 0, 0);
  34. }
  35.  
  36. int pX = 0;
  37.  
  38. int bX, bY = -1;
  39.  
  40. void handleInput() {
  41. if(is_down('A'))
  42. pX--;
  43. if(is_down('D'))
  44. pX++;
  45.  
  46. pX = pX < 0 ? 0 : (pX > 80 ? 80 : pX);
  47.  
  48. if(is_down(32) && bY == -1) {
  49. Beep(500, 30);
  50. bX = pX + 2;
  51. bY = 65 - 3;
  52. }
  53.  
  54.  
  55. if(bY == -1)
  56. bX=-1;
  57. else
  58. bY--;
  59. }
  60.  
  61. void drawPlayer() {
  62. attr = 10;
  63.  
  64. drawImg(pX, 65, 0x40E1F);
  65.  
  66. if(bY>=0)
  67. set_char(bX, bY, 'o', 10);
  68. }
  69.  
  70. int ePos = 0, mv = 0;
  71. //int enemies[] =
  72.  
  73. void drawEnemies() {
  74. if(mv++ % 8 & 1)
  75. ePos++;
  76.  
  77. int xOffset = (ePos / 13) % 2 ? (13 - (ePos % 13)) : ePos % 13;
  78. int yOffset = ePos / 13;
  79.  
  80. for(int i = 0; i < 15; i++) {
  81. attr = i&1 ? 15 : 14;
  82. drawImg(xOffset + i%5 * 16, yOffset + 8 + i/5 * 10, 0x183C7EDBFF245AA5);
  83. }
  84.  
  85. if(yOffset > 35) {
  86. Beep(200, 300);
  87. }
  88. }
  89.  
  90. void loop() {
  91. l:
  92.  
  93. clearScreen();
  94.  
  95. handleInput();
  96. drawPlayer();
  97.  
  98. drawEnemies();
  99.  
  100. //drawImg(6, 24, 0x66C366FF7EFF66C3);
  101.  
  102.  
  103. toScreen();
  104. Sleep(50);
  105.  
  106. goto l;
  107. }
  108.  
  109. int main() {
  110. stdHandle = GetStdHandle(-11);
  111.  
  112. loop();
  113.  
  114. return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement