Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <winuser.h>
- #define S(X,Y,C,A) {b[Y][X].Char.AsciiChar=C; b[Y][X].Attributes=A; }
- #define is_down(K) GetAsyncKeyState(K)&(1<<16)
- HANDLE h;
- CHAR_INFO b[70][90];
- int x;
- void toScreen() {
- SMALL_RECT r{0, 0, 90, 70};
- WriteConsoleOutput(h, (const CHAR_INFO*)&b, COORD{90, 70}, COORD{0, 0}, &r);
- }
- int a = 0;
- void drawImg(int x, int y, INT64 g) {
- while(g) {
- for(int i = 0; i < 8; i++) {
- S(x, y, ((g) & 1) ? 219 : ' ', a);
- x++;
- g>>=1;
- }
- x -= 8;
- y--;
- }
- }
- void clearScreen() {
- x=6300;
- while(x--)
- S(x, 0, 0, 0);
- }
- int pX = 0;
- int bX, bY = -1;
- void handleInput() {
- if(is_down(65))
- pX--;
- if(is_down(68))
- pX++;
- pX = pX < 0 ? 0 : (pX > 80 ? 80 : pX);
- if(is_down(32) && bY == -1) {
- Beep(500, 30);
- bX = pX + 2;
- bY = 65 - 3;
- }
- if(bY == -1)
- bX=-1;
- else
- bY--;
- }
- void drawPlayer() {
- a = 10;
- drawImg(pX, 65, 0x40E1F);
- if(bY>=0)
- S(bX, bY, 64, 13);
- }
- int level = 0;
- int ePos = 0, mv = 0, enemies[15], killed = 0;
- void reset() {
- ePos=0;
- mv=0;
- killed=0;
- ZeroMemory(&enemies,60);
- }
- void drawEnemies() {
- if(mv++ % 3 == 0)
- ePos++;
- int xOffset = (ePos / 13) % 2 ? (13 - (ePos % 13)) : ePos % 13;
- int yOffset = ePos / 13;
- for(int i = 0; i < 15; i++) {
- if(!enemies[i]) {
- a = i&1 ? 15 : 14;
- int x = xOffset + i%5 * 16, y = yOffset + 8 + i/5 * 10;
- drawImg(x, y, 0x183C7EDBFF245AA5);
- if(bX>x&&bX<x+8&&bY>y-8&&bY<y) {
- enemies[i] = 1;
- bY=-1;
- killed++;
- if(killed==15) {
- int a=6;
- while(a--)
- Beep(a&1?200:300, 300);
- level++;
- reset();
- break;
- }
- }
- if(y > 62) {
- int a=4;
- while(a--)
- Beep(210+a*10, a?300:1000);
- reset();
- break;
- }
- }
- }
- }
- void loop() {
- l:
- clearScreen();
- handleInput();
- drawPlayer();
- drawEnemies();
- toScreen();
- Sleep(10 - level*2);
- goto l;
- }
- int main() {
- h = GetStdHandle(-11);
- loop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement