/* ball game v2b ...nithin agnithin@yahoo.com aim of the gam is to stop the ball from hitting the right wall by moving the box. 10 pts r given 4 stopping it once. speed increases as the score increases by 100. */ #include #include #include #include #include int midx, midy,x=22,y=22,sx=1,sy=1,by,scr=0,spd=2,ch=3,b2x; int r = 20,i; /* midx,midy = mid of screen x,y = coordinates of ball (initial pos can be changed) sx,sy = direction for ball to mov (1 for +ve, 0 for -ve) by = location of box b2x = location of box 2 scr = score spd = speed ch = menu choice r = radius of ball i = for internel loops */ void load(); void box(); /*void gamover(); void credit(); */ /*/////////////////////////////ball*/ void ball() { cleardevice(); setcolor(1); /*color 4 border*/ rectangle(0,0,getmaxx(),getmaxy() ); /* border*/ while(1) { if(x>(midx*2-3)-r) { sx=0; printf("\nx_gamover"); //gamover(); /*conditions for*/ sound(100); /* ball to move*/ } if(x<(r+3)) { sx=1; sound(100);} if(y>(midy*2-3)-r) { sy=0; printf("\ny_gamover"); sound(100); } if(y<(r+3)) { sy=1; sound(100); } if(x==getmaxx()-45-r && y>by-20 && y<(by+80)) { sx=0; scr=scr+10; sound(500); if(scr%100==0) /*if score inc by 100*/ { spd++; /*inc speed*/ sound(600); delay(100); nosound(); } } /*/////////////////*/ if(y==getmaxy()-45-r && x>b2x-20 && x<(b2x+80)) { sy=0; scr=scr+10; sound(500); if(scr%100==0) { spd++; sound(600); delay(100); nosound(); } } if(sx==0) x=x-spd; /*ball*/ else x=x+spd; /*movment*/ if(sy==0) y=y-spd; /*ball*/ else y=y+spd; /*movement*/ setcolor(1); /*ball outline color*/ setfillstyle( SOLID_FILL, 3 ); /*ball color*/ fillellipse(x, y, r, r); /*draw ball*/ for(i=0;i<12;i=i+2) arc(x, y, 230+i*6, 40-i*6, r-i); /*for 3d touch*/ nosound(); gotoxy(getmaxx()-60,1); printf("debugging mode "); gotoxy(1,1); printf("#X--->\nY\n|\nV\n"); printf("\nSCORE:%3d\nSPEED:%2d",scr,spd-1); /*disp score*/ printf("\n\n#box1->\nby=%d ",by); printf("\n#box2\\/\nb2x=%d ",b2x); printf("\n\n#ball"); printf("\nx=%d \ny=%d ",x,y); setcolor(7); if(kbhit()) /*if i/p, mov box*/ box(); else /*if no i/p disp in same pos*/ { rectangle(getmaxx()-40,by,getmaxx()-30,by+60); rectangle(b2x,getmaxy()-40,b2x+60,getmaxy()-30); } delay(10); setfillstyle( SOLID_FILL, 8 ); /*clear ball & box*/ setcolor(8); fillellipse(x, y, r, r); rectangle(getmaxx()-40,by,getmaxx()-30,by+60); rectangle(b2x,getmaxy()-40,b2x+60,getmaxy()-30); } } /*///////////////////////////////box*/ void box() { switch(getch()) { case 0x48: /*up key */ if(by<5) break; else by=by-10; /*can be inc further to mov faster*/ break; case 0x50: /*down key*/ if(by>getmaxy()-65) break; else by=by+10; /*can be inc further to mov faster*/ break; case 0x4b://left if(b2x<5) break; else b2x=b2x-10; /*can be inc further to mov faster*/ break; case 0x4d://right */ if(b2x>getmaxx()-70) break; else b2x=b2x+10; /*can be inc further to mov faster*/ break; case 'p': rectangle(getmaxx()-40,by,getmaxx()-30,by+60); /*disp box*/ rectangle(b2x,getmaxy()-40,b2x+60,getmaxy()-30); getch(); break; case 0x1b: /*esc key */ exit(1); } rectangle(getmaxx()-40,by,getmaxx()-30,by+60); /*disp box*/ rectangle(b2x,getmaxy()-40,b2x+60,getmaxy()-30); return; } /*/////////////////////////////load screen*/ /*/////////////////////////////gamover*/ /*/////////////////////////////credits*/ /*/////////////////////////////main()*/ int main(void) { int gdriver = DETECT, gmode, errorcode; initgraph(&gdriver, &gmode, "c:\\tc\\bgi"); /*change this to ur tc dir*/ midx = getmaxx() / 2; midy = getmaxy() / 2; by=getmaxy()-70; b2x=10; setbkcolor(8); // load(); /*disp loading screen*/ setbkcolor(8); /*background color */ ball(); /*main game */ closegraph(); nosound(); return 0; }