/* todo, make look like game */ #include #include #include /* usleep */ #include #include char ch; static int ri; /* pseudo-random generator */ int int_random(int seed) { if (seed!=0) { ri=seed; while ((ri%2==0) || (ri%5==0)) ri++; ri=ri&0xffffff; return ri; } ri*=997; ri&=0xffffff; return ri>>4; } /* clear the screen */ void cls() { printf("%c[2J%c[H\n",27,27); } /* display help */ void help() { cls(); printf("HELP\n"); printf("~~~~\n"); printf(", moves left\n"); printf(". moves right\n"); printf("spacebar shoots\n"); printf("s toggles sound\n"); printf("p pauses\n"); printf("q quits\n"); while(read(0,&ch,1)<0); } int main(int argc, char **argv) { FILE *debug; char j,x=7,keypressed; int i,s=0,sh=5,ra,wait,frames=0,shots=0,sound=1,xb=0,done=0; short missile[8],enemy[8],stars[8],mask; for(i=0;i<8;i++) enemy[i]=missile[i]=stars[i]=0; static struct termios new_tty,old_tty; debug=fopen("bob","w"); /* Setup Term */ tcgetattr(0,&old_tty); new_tty=old_tty; new_tty.c_lflag&=~ICANON; new_tty.c_cc[VMIN]=1; new_tty.c_lflag&=~ECHO; tcsetattr(0,TCSANOW,&new_tty); fcntl(0,F_SETFL,fcntl(0,F_GETFL) | O_NONBLOCK); cls(); /* do the opening */ i=8; while(i>0) { cls(); for(j=0;j13) x=13; ch=0; } /* draw the action */ cls(); for(i=0;i<8;i++) { for(j=0;j<16;j++) { mask=1<0;i--) stars[i]=stars[i-1]; stars[0]=1<<(int_random(0)&0xf); } /* scroll the missiles */ if (frames&1) { for(i=0;i<7;i++) missile[i]=missile[i+1]; missile[7]=0; } /* scroll the enemies */ if ((frames&0x3)==2) { for(i=7;i>0;i--) enemy[i]=enemy[i-1]; enemy[0]=0; } /* delay */ usleep(33000); /* extra beep */ if (xb) { xb--; if (xb==0) if (sound) printf("%c\n",7); } } /* end screen */ cls(); printf("\n\n\nGAME OVER!\n"); printf("SCORE: %i\n",s); if (!shots) printf("HIT RATIO: %i%%\n", s*100/shots); return 0; }