Advertisement
szymski

Untitled

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