//***************************************************************************** //##########################- BOTTLE SHOOTER -############################# //****************************************************************************** #include #include #include #include 2 #include #include #include #include #include //****************************************************************************** // DEFINING OBJECT SIZES //****************************************************************************** #define gun_size 978 //defining GUN size #define bult_size 50 //defining BULLET size #define botl_size 978 //defining BOTTLE size //#define ball_size 990 //defining BALL size //****************************************************************************** // FUCTION PROTOTYPES //****************************************************************************** int get_arrow_key(); // get keystroke void header(); void draw_gun(int,int,int,int); // draw GUN on screen void mov_gun_left(); // left movement of GUN void mov_gun_right(); // right movement of GUN void draw_bullet(int, int, int, int); // draw BULLET on screen void bult_mov(); // firing of BULLET void draw_botl(); // draw BOTTLES void roll_ball(); // roll BALLS //****************************************************************************** // VARIABLE DECLARATIONS //****************************************************************************** int gleft,gright,gtop,gbotom; // defining GUN int bleft,bright,btop,bbotom; // defining BULLET int tleft,tright,ttop,tbotom; // defining BOTTLE int lleft,ltop,lright,lbottom; int key = 0; int radius = 10; int x0=580,y0=160, x1=480,y1=65, x2=450,y2=270, x3=350,y3=200;// BALL int x4=300,y4=98, x5=260,y5=295, x6=170,y6=210, x7=87,y7=100;//VARIABLES int x8=10,y8=275; // void *gun_buf = malloc(gun_size); // BUFFER to hold GUN image void *bult_buf = malloc(bult_size); // BUFFER to hold BULLET image void *botl_buf = malloc(botl_size); // BUFFER to hold BOTTLE image void *ball_buf = malloc(100);//ball_size); // BUFFER to hold BALL image int bullet_drawn = 0, ball_drawn = 0; int start, end; // TIME variables int total_time = 50; // defining TIME SLICE int bult_no = 90; // defining BULLET COUNT //****************************************************************************** // MAIN FUNCTION //****************************************************************************** main(void) { int gdriver,gmode; char int_str[5]; gdriver = DETECT; initgraph(&gdriver,&gmode,"c:\\tc\\bgi"); header(); getche(); cleardevice(); // drawing GAME SCREEN setbkcolor(WHITE); setfillstyle(SOLID_FILL,RED); bar(0,420,639,479); setfillstyle(SOLID_FILL,YELLOW); // drawing BULLET bar bar(20,430,80,470); itoa(bult_no,int_str,10); // drawing BULLET display settextstyle(1,HORIZ_DIR,4); setfillstyle(SOLID_FILL,GREEN); outtextxy(30,430,int_str); setfillstyle(SOLID_FILL,YELLOW); // drawing CLOCK display bar(559,430,620,470); // gleft = 299; // gright = 319; // setting GUN position gtop = 340; // gbotom = 419; // lleft = x0-radius; ltop = y0-radius; lright = x0+radius; lbottom = y0+radius; // int a=x0-15, b=radius-15, c=radius+15, d=radius+15 int size=imagesize(lleft,ltop,lright,lbottom);//a,b,c,d);*/ void *ball_buf = malloc(size); // BUFFER to hold BALL image draw_gun(gleft,gtop,gright,gbotom); // drawing GUN getimage(gleft,gtop,gright,gbotom,gun_buf); draw_botl(); // drawing BOTTLES free(botl_buf); roll_ball(); struct time t; struct time t1; int end2 = 0; gettime(&t); start = (t.ti_hour*3600) + (t.ti_min*60) + t.ti_sec; start += total_time; // setting TIME SLICE to 30 sec gettime(&t1); end = (t1.ti_hour*3600) + (t1.ti_min*60) + t1.ti_sec; itoa(start-end,int_str,10); // roll_ball(); // setfillstyle(SOLID_FILL,YELLOW); // bar(559,430,620,470); // update CLOCK display // setfillstyle(SOLID_FILL,GREEN); // settextstyle(1,HORIZ_DIR,4); // outtextxy(570,430,int_str); // while(/*(start>=end)&&*/(key!=1)/*&&(bult_no>0)*/) { roll_ball(); gettime(&t1); end2 = end; end = (t1.ti_hour*3600) + (t1.ti_min*60) + t1.ti_sec; if(end-end2>=1) { itoa(start-end,int_str,10); // roll_ball(); // settextstyle(1,HORIZ_DIR,4); // setfillstyle(SOLID_FILL,YELLOW); // updating CLOCK display bar(559,430,620,470); // setfillstyle(SOLID_FILL,GREEN); // outtextxy(570,430,int_str); // } // roll_ball(); while(kbhit()) // checking for KEY STROKES { roll_ball(); key = get_arrow_key(); gettime(&t1); end2 = end; end = (t1.ti_hour*3600) + (t1.ti_min*60) + t1.ti_sec; if(end-end2>=1) { // roll_ball(); itoa(start-end,int_str,10); // settextstyle(1,HORIZ_DIR,4); // setfillstyle(SOLID_FILL,YELLOW); // updating CLOCK display bar(559,430,620,470); // setfillstyle(SOLID_FILL,GREEN); // outtextxy(570,430,int_str); // } // roll_ball(); switch(key) // checking for KEY STROKES { case 75 : if(gleft>0) // <----- mov_gun_left(); // roll_ball(); break; case 77 : if(gright<639) // -----> mov_gun_right(); // roll_ball(); break; case 57 : if(!(--bult_no>=0)) // decreasing BULLET COUNT break; setfillstyle(SOLID_FILL,YELLOW); // bar(20,430,80,470); // itoa(bult_no,int_str,10); // updating BULLET settextstyle(1,HORIZ_DIR,4); // display setfillstyle(SOLID_FILL,GREEN); // outtextxy(30,430,int_str); // roll_ball(); bult_mov(); // BULLET fired break; default : break; } roll_ball(); } } // if(bottle_no = 0) win screen; // if(bult_no = 0)||(start<=end) lose screen; // roll_ball(); free(bult_buf); // free BUFFER free(gun_buf); // SPACE // free(ball_buf); closegraph(); return 0; } // main ends //**************************************************************************** // DRAW GUN //****************************************************************************** void draw_gun(int gleft,int gtop,int gright,int gbotom) { setfillstyle(SOLID_FILL,LIGHTGRAY); bar( gleft+5, gtop, gright-5, gbotom-40); bar( gleft, gtop+40, gright, gbotom); setcolor(DARKGRAY); setfillstyle(SOLID_FILL,DARKGRAY); for(int i=1 ; i<4 ; i++) line( gleft+i*5, gtop+45, gleft+i*5, gbotom-5); return; } //***************************************************************************** // LEFT MOVEMENT OF GUN //****************************************************************************** void mov_gun_left() { setfillstyle(SOLID_FILL,WHITE); bar(gleft,gtop,gright,gbotom); if(gleft ==19) { gleft -=19; gright-=19; } else { gleft -=20; gright-=20; } putimage(gleft,gtop,gun_buf,COPY_PUT); return; } //***************************************************************************** // RIGHT MOVEMENT OF GUN //****************************************************************************** void mov_gun_right() { setfillstyle(SOLID_FILL,WHITE); bar(gleft,gtop,gright,gbotom); if(gright == 620) { gleft +=19; gright+=19; } else { gleft +=20; gright+=20; } putimage(gleft,gtop,gun_buf,COPY_PUT); return; } //***************************************************************************** // DRAW BULLET //****************************************************************************** void draw_bullet(int bleft, int btop, int bright, int bbotom) { setfillstyle(SOLID_FILL,BLUE); bar(bleft,btop,bright,bbotom); return; } //***************************************************************************** // BULLET MOVEMENT //****************************************************************************** void bult_mov() { roll_ball(); bleft = gleft+7; //set bullet position btop = gtop-10; bright = gright-7; bbotom = gtop; unsigned color = WHITE; sound(2000); //firing sound delay(50); sound(500) ; delay(50); if(!bullet_drawn) { draw_bullet(bleft,btop,bright,bbotom); roll_ball(); getimage(bleft,btop,bright,bbotom,bult_buf); bullet_drawn = 1; } if(bullet_drawn) { roll_ball(); putimage(bleft,btop,bult_buf,COPY_PUT); } nosound(); int LEFT=1; while((bbotom>0)&&((color!=2)&&(color!=4))) // untill GREEN or RED { // object is hit delay(10); setfillstyle(SOLID_FILL,WHITE); bar(bleft,btop,bright,bbotom); btop -=7; bbotom-=7; setfillstyle(SOLID_FILL,BLUE); putimage(bleft,btop,bult_buf,COPY_PUT); color = getpixel(bleft,btop-1); LEFT = 1; if((color!=2)&&(color!=4)) { color = getpixel(bright,btop-1); LEFT =0; } setfillstyle(SOLID_FILL,WHITE); bar(bleft,btop,bright,bbotom); if(color==4) //if hits ball { sound(1200); delay(50); roll_ball(); } if(color==2) // if hits bottle { if(LEFT) bar(bleft-20,btop-40,bleft+5,bbotom); else bar(bright-5,btop-40,bright+20,bbotom); sound(3500); delay(100); sound(2500); delay(100); sound(1200); delay(50); roll_ball(); } } nosound(); return; } //***************************************************************************** // SCAN THE KEY STROKE //****************************************************************************** int get_arrow_key() { int scan_code; union REGS inregs,outregs; inregs.h.ah = 0; int86(22,&inregs,&outregs); scan_code = outregs.h.ah; // roll_ball(); return(scan_code); } //***************************************************************************** // BOTTLE DRAW //****************************************************************************** void draw_botl() { tleft = 10; tright = tleft+20; // 20 pixels wide ttop = 10; tbotom = ttop+40; // 40 pixels long setcolor(GREEN); setfillstyle(SOLID_FILL,GREEN); arc(tleft-10,ttop+11,312,43,17); arc(tright+10,ttop+11,135,228,17); line(tleft+5,ttop,tleft+15,ttop); circle(tleft+10,ttop+30,10); floodfill(tleft+10,ttop+2,GREEN); fillellipse(tleft+10,ttop+30,10,10); getimage(tleft,ttop,tright,tbotom,botl_buf); for(int count=0 ; count<16 ; count++) { putimage(tleft,ttop,botl_buf,COPY_PUT); tleft += 40; tright+= 40; } return; } //****************************************************************************** // ROLLING OF BALLS //***************************************************************************** void roll_ball() { if(!ball_drawn) { setcolor(RED); circle(x0,y0,radius); setfillstyle(SOLID_FILL,RED); fillellipse(x0,y0,20,20); x0 = lleft; y0 = ltop; getimage(lleft,ltop,lright,lbottom,ball_buf); putimage(lleft,ltop,ball_buf,COPY_PUT); putimage(x1,y1,ball_buf,COPY_PUT); putimage(x2,y2,ball_buf,COPY_PUT); putimage(x3,y3,ball_buf,COPY_PUT); putimage(x4,y4,ball_buf,COPY_PUT); putimage(x5,y5,ball_buf,COPY_PUT); putimage(x6,y6,ball_buf,COPY_PUT); putimage(x7,y7,ball_buf,COPY_PUT); putimage(x8,y8,ball_buf,COPY_PUT); ball_drawn = 1; } else { setcolor(WHITE); putimage(x0,y0,ball_buf,1); putimage(x1,y1,ball_buf,1); putimage(x2,y2,ball_buf,1); putimage(x3,y3,ball_buf,1); putimage(x4,y4,ball_buf,1); putimage(x5,y5,ball_buf,1); putimage(x6,y6,ball_buf,1); putimage(x7,y7,ball_buf,1); putimage(x8,y8,ball_buf,1); x0+=10; if(x0>640) x0 = 0; x1+=10; if(x1>640) x1 = 0; x2+=10; if(x2>640) x2 = 0; x3+=10; if(x3>640) x3 = 0; x4+=10; if(x4>640) x4 = 0; x5+=10; if(x5>640) x5 = 0; x6+=10; if(x6>640) x6 = 0; x7+=10; if(x7>640) x7 = 0; x8+=10; if(x8>640) x8 = 0; setcolor(RED); putimage(x0,y0,ball_buf,COPY_PUT); putimage(x1,y1,ball_buf,COPY_PUT); putimage(x2,y2,ball_buf,COPY_PUT); putimage(x3,y3,ball_buf,COPY_PUT); putimage(x4,y4,ball_buf,COPY_PUT); putimage(x5,y5,ball_buf,COPY_PUT); putimage(x6,y6,ball_buf,COPY_PUT); putimage(x7,y7,ball_buf,COPY_PUT); putimage(x8,y8,ball_buf,COPY_PUT); } } void header() { int x1,sqx,y1,sqy,x2,y2; sqx=((getmaxx()+1)/21); sqy=((getmaxy()+1)/16); x1=(getmaxx()-(15*sqx+2))/2; y1=(getmaxy()-(15*sqy+2))/2; x2=x1+15*sqx+1; y2=y1+15*sqy+1; setbkcolor(BLACK); delay(500); rectangle(x1,y1,x2,y2); delay(500); rectangle(x1+20,y1+20,x2-20,y2-20); delay(500); floodfill(x1+17,y1+17,WHITE); setfillstyle(SOLID_FILL,RED); delay(500); floodfill(x1+25,y1+25,WHITE); setcolor(WHITE); settextstyle(GOTHIC_FONT,0,4); delay(500); outtextxy(x1+125,y1+60," "); setcolor(BLUE); delay(500); line(x1+230,y1+150,x1+330,y1+350); delay(500); line(x1+230,y1+150,x1+130,y1+350); delay(500); line(x1+130,y1+350,x1+330,y1+350); delay(500); setfillstyle(SOLID_FILL,BLUE); delay(500); floodfill(x1+250,y1+210,BLUE); setfillstyle(SOLID_FILL,LIGHTMAGENTA); setcolor(LIGHTGREEN); delay(500); circle(x1+230,y1+250,100); delay(500); circle(x1+230,y1+250,80); delay(500); circle(x1+230,y1+250,60); delay(500); floodfill(x1+230,y1+250,LIGHTGREEN); setcolor(YELLOW); settextstyle(TRIPLEX_FONT,0,7); delay(500); outtextxy(x1+50,y1+220," GAME5"); getch(); setcolor(WHITE); setbkcolor(BLACK); cleardevice(); delay(500); rectangle(x1,y1,x2,y2); delay(500); rectangle(x1+20,y1+20,x2-20,y2-20); delay(500); floodfill(x1+17,y1+17,WHITE); setfillstyle(SOLID_FILL,GREEN); delay(1000); floodfill(x1+25,y1+25,WHITE); setcolor(BLUE); settextstyle(GOTHIC_FONT,0,4); delay(500); outtextxy(x1+110,y1+95,"DESIGNED BY"); delay(1000); setcolor(BLACK); settextstyle(TRIPLEX_FONT,0,5); outtextxy(x1+45,y1+188,"MEHRULLAH KALWAR"); delay(500); outtextxy(x1+100,y1+278,""); getch(); }