szymski

Untitled

Aug 20th, 2016
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 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', 13);
  68. }
  69.  
  70. int level = 0;
  71.  
  72. int ePos = 0, mv = 0, enemies[15], killed = 0;
  73.  
  74. void reset() {
  75. ePos=0;
  76. mv=0;
  77. killed=0;
  78. ZeroMemory(&enemies,60);
  79. }
  80.  
  81. void drawEnemies() {
  82. if(mv++ % 3 == 0)
  83. ePos++;
  84.  
  85. int xOffset = (ePos / 13) % 2 ? (13 - (ePos % 13)) : ePos % 13;
  86. int yOffset = ePos / 13;
  87.  
  88. for(int i = 0; i < 15; i++) {
  89. if(!enemies[i]) {
  90. attr = i&1 ? 15 : 14;
  91. int x = xOffset + i%5 * 16, y = yOffset + 8 + i/5 * 10;
  92. drawImg(x, y, 0x183C7EDBFF245AA5);
  93. if(bX>x&&bX<x+8&&bY>y-8&&bY<y) {
  94. enemies[i] = 1;
  95. bY=-1;
  96. killed++;
  97. if(killed==15) {
  98. int a=6;
  99. while(a--)
  100. Beep(a&1?200:300, 300);
  101. level++;
  102. reset();
  103. break;
  104. }
  105. }
  106.  
  107. if(y > 62) {
  108. int a=4;
  109. while(a--)
  110. Beep(210+a*10, a?300:1000);
  111. reset();
  112. break;
  113. }
  114. }
  115. }
  116. }
  117.  
  118. void loop() {
  119. l:
  120.  
  121. clearScreen();
  122.  
  123. handleInput();
  124. drawPlayer();
  125.  
  126. drawEnemies();
  127.  
  128. //drawImg(6, 24, 0x66C366FF7EFF66C3);
  129.  
  130.  
  131. toScreen();
  132. Sleep(10 - level*2);
  133.  
  134. goto l;
  135. }
  136.  
  137. int main() {
  138. stdHandle = GetStdHandle(-11);
  139.  
  140. loop();
  141.  
  142. return 0;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment