#include #include int main() { int gtimer = 0; int aiter = 0; const char pl_img = '╳'; char kstrk = 'r'; int ingame = 1; int opx,opy = 0; double px,py = 2; double pxvel,pyvel = 0; const double gravity = 0.2; int i,j = 0; char map1 [12][32] = { {' ',' ',' ',' ',' ',' ',' ',' ',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ',' ',' ',' ',' ',' ',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ',' ',' ',' ',' ',' ',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ','M','M','M','M','M',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ','M',' ',' ',' ',' ',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ','M',' ',' ',' ',' ',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ','M',' ',' ','M','M','M','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ','M',' ',' ',' ',' ',' ','x',' ',' ',' ','x',' ',' ','x',' ',' ',' ',' ','\0'}, {'M','M','M','M','M','M','M','M','M','M','M','M',' ',' ',' ',' ',' ','M','M','M','M','M','M','M','M','M','M','M','M','M','M','\0'}, {'M','M','M','M','M','M','M','M','M','M','M','M',' ',' ',' ',' ',' ','M','M','M','M','M','M','M','M','M','M','M','M','M','M','\0'}, {'M','M','M','M','M','M','M','M','M','M','M','M',' ',' ',' ',' ',' ','M','M','M','M','M','M','M','M','M','M','M','M','M','M','\0'} }; char map2 [12][32] = { {' ',' ',' ',' ',' ',' ','M','M',' ',' ',' ',' ',' ',' ','x',' ',' ',' ',' ',' ','M','M','M','M','M','M','M','M','M','M','M','\0'}, {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ',' ',' ',' ','M','M',' ',' ',' ',' ',' ',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ',' ',' ',' ','M','M',' ',' ',' ',' ',' ',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {' ',' ','M','M','M',' ',' ',' ',' ',' ',' ',' ',' ',' ','M',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'}, {'M','M','M','M','M','M','M','M','M','M','M','M',' ',' ','M',' ',' ','M',' ',' ','M','M','M','M','M','M','M','M','M','M','M','\0'}, {'M','M','M','M','M','M','M','M','M','M','M','M',' ',' ','M',' ',' ','M',' ',' ','M','M','M','M','M','M','M','M','M','M','M','\0'}, {'M','M','M','M','M','M','M','M','M','M','M','M',' ',' ','M',' ',' ','M',' ',' ','M','M','M','M','M','M','M','M','M','M','M','\0'} }; int mapnum = 1; char tempmap[12][32]; char curmap[12][32]; //sleep(10); for (int i = 0; i < 12; i++) { for (int j = 0; j < 32; j++) { tempmap[i][j] = map1[i][j]; } } while(ingame == 1){ while(aiter > 0){ for (int i = 0; i < 12; i++) { for (int j = 0; j < 32; j++) { if(j > aiter){ tempmap[i][j] = map2[i][j-aiter-1]; } else { tempmap[i][j] = map1[i][j+31-aiter]; } } } aiter--; if(aiter == 0){ ++mapnum; px = 0; for (int i = 0; i < 12; i++) { for (int j = 0; j < 32; j++) { tempmap[i][j] = map2[i][j]; } } } system("clear"); for(i=0;i<12;++i){ printf(" %s\n",tempmap[i]); } sleep(1); } for (i = 0; i < 12; i++) { for (j = 0; j < 32; j++) { if(tempmap[i][j] == 'X'){ tempmap[i][j] = 'x'; } curmap[i][j] = tempmap[i][j]; } } opx = px; opy = py; pyvel+= gravity; if(kstrk=='w'){ pyvel = -1; } if(kstrk=='d'){ pxvel = 1; } if(kstrk=='a'){ pxvel = -1; } kstrk = 'r'; if(curmap[(int)(py)][(int)(px+pxvel)]!='M'){ px += pxvel; } else { pxvel = 0; } if(curmap[(int)(py+pyvel)][(int)(px)]!='M'){ py += pyvel; } else { pyvel = 0; } curmap[(int)py][(int)px] = pl_img; if((int)py > 11 || (int)py < 0){ ingame = 0; } if((int)px >= 31){ aiter = 32; } if(gtimer % 4 == 0){ for (i = 0; i < 12; i++) { for (j = 0; j < 32; j++) { if(tempmap[i][j] == 'x'){ if(px > i && tempmap[i+1][j] == ' '){ tempmap[i][j] = ' '; tempmap[i+1][j] = 'X'; ++i; } else if(tempmap[i-1][j] == ' '){ tempmap[i][j] = ' '; tempmap[i-1][j] = 'X'; --i; } if(py > j && tempmap[i][j+1] == ' '){ tempmap[i][j] = ' '; tempmap[i][j+1] = 'X'; ++j; } else if(tempmap[i][j-1] == ' '){ tempmap[i][j] = ' '; tempmap[i][j-1] = 'X'; --j; } if(curmap[i][j] == pl_img){ ingame = 0; } } } } } system("clear"); printf("\n"); for(i=0;i<12;++i){ printf(" %s\n",curmap[i]); } kstrk = getchar(); gtimer++; sleep(1); } printf("\n _____\n"); printf(" / ____|\n"); printf(" | | __ __ _ _ __ ___ ___ _____ _____ _ __\n"); printf(" | | |_ |/ _` | '_ ` _ | / _ | / _ | | / / _ | '__|\n"); printf(" | |__| | (_| | | | | | | __/ | (_) | V | __| |\n"); printf(" |_____||__,_|_| |_| |_||___| |____/ |_/|____|_|\n"); return 0; }