├── README.md └── HELI_C-1.CPP /README.md: -------------------------------------------------------------------------------- 1 | # Helicopter-Game 2 | A 2-D Helicopter game in C++ with gameplay similar to the popular android game : "Flappy Bird". 3 | In this game, We have to cross various challenging levels without colliding our helicopter with the obstacles.The controls are similar to the game : "Flappy Bird" whereby if u keep pressing the key, the helicopter goes UP and releasing the key makes the helicopter come DOWN. 4 | -------------------------------------------------------------------------------- /HELI_C-1.CPP: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | int j=1; 11 | int left=200,top=200,radx=30,rady=15; 12 | int py1,py2,py3,py4,ran; 13 | long score=0; 14 | char ch; 15 | int t,l; 16 | int px; 17 | void downheli(); 18 | void upheli(); 19 | void chk_pipe(); 20 | void heli_dam(); 21 | void bk_m(int level); 22 | void dance_pipe(int px,int py); 23 | 24 | void main(); 25 | void play(); 26 | void drawMenu ( int selected , int defCol , int selCol ) ; 27 | void start(int i); 28 | int main_menu(); 29 | 30 | 31 | void level_page(); 32 | void level_draw(int lx,int ly); 33 | 34 | 35 | 36 | int level=1; 37 | 38 | 39 | void d_score(long sc) 40 | { 41 | 42 | 43 | setfillstyle(SOLID_FILL,BLACK); 44 | bar(0,getmaxy()-50,getmaxx(),getmaxy()); 45 | 46 | setcolor(15); 47 | settextstyle(2,0,5); 48 | outtextxy(400,getmaxy()-40," SCORE :"); 49 | char s[10]; 50 | sprintf(s,"%ld",sc); 51 | setfillstyle(SOLID_FILL,0); 52 | outtextxy(500,getmaxy()-40,s); 53 | 54 | setcolor(BLACK); 55 | 56 | 57 | } 58 | void draw_heli() 59 | { 60 | setcolor(BLACK); 61 | setfillstyle(LINE_FILL,CYAN); 62 | fillellipse(left,top-rady,radx+10,rady-5); //top fan 63 | setfillstyle(SOLID_FILL,CYAN); 64 | fillellipse(left-63,top-9,10,4); //small fan 65 | fillellipse(left,top,radx,rady); 66 | setfillstyle(SOLID_FILL,WHITE); 67 | bar(left,top-3,left-65,top+3); 68 | sector(left,top,90,270,radx,rady); 69 | bar(left-65,top-3,left-62,top-8); 70 | 71 | } 72 | void ulta_heli() 73 | { 74 | setfillstyle(LINE_FILL,CYAN); 75 | fillellipse(left,top+rady,radx+10,rady-5); //top fan 76 | setfillstyle(SOLID_FILL,CYAN); 77 | fillellipse(left-63,top+9,10,4); //small fan 78 | fillellipse(left,top,radx,rady); 79 | setfillstyle(SOLID_FILL,WHITE); 80 | bar(left,top-3,left-65,top+3); 81 | sector(left,top,90,270,radx,rady); 82 | bar(left-65,top+3,left-62,top+8); 83 | delay(20); 84 | setfillstyle(SOLID_FILL,BLACK); 85 | fillellipse(left,top+rady,radx+10,rady-5); //top fan 86 | fillellipse(left-63,top+9,10,4); //small fan 87 | fillellipse(left,top,radx,rady); 88 | bar(left,top-3,left-65,top+3); 89 | sector(left,top,90,270,radx,rady); 90 | bar(left-65,top+3,left-62,top+8); 91 | 92 | setcolor(BLACK); 93 | 94 | 95 | } 96 | void rem_heli() 97 | { 98 | setcolor(BLACK); 99 | setfillstyle(SOLID_FILL,BLACK); 100 | fillellipse(left,top-rady,radx+10,rady-5); 101 | fillellipse(left-63,top-9,10,4); 102 | fillellipse(left,top,radx,rady); 103 | bar(left,top-3,left-65,top+3); 104 | sector(left,top,90,270,radx,rady); 105 | bar(left-65,top-3,left-62,top-8); 106 | 107 | } 108 | 109 | void drawpipe(int px,int py) 110 | { 111 | setfillstyle(1,GREEN); 112 | //up pipes 113 | bar(px,py,px+60,py+200); 114 | bar(px-15,py+200,px+75,py+220); 115 | 116 | ///down pipes 117 | 118 | bar(px-40,py+400,px+20,getmaxy()-50); 119 | bar(px-55,py+380,px+35,py+400); 120 | chk_pipe(); 121 | 122 | d_score(++score); 123 | } 124 | 125 | 126 | 127 | void removepipe(int px,int py) 128 | { 129 | 130 | setfillstyle(1,BLACK); 131 | //up pipes 132 | bar(px,py,px+60,py+200); 133 | bar(px-15,py+200,px+75,py+220); 134 | 135 | 136 | //down pipes 137 | bar(px-40,py+400,px+20,getmaxy()-50); 138 | bar(px-55,py+380,px+35,py+400); 139 | 140 | 141 | } 142 | void draw_wall(int px,int py) 143 | { 144 | setfillstyle(INTERLEAVE_FILL,BROWN); 145 | bar(0,0,getmaxx(),15); 146 | bar(0,getmaxy()-55,getmaxx(),getmaxy()-50); 147 | bar(px,py+250,px+40,py+250+ran); 148 | bar(px-50,py+350,px-20,py+350+ran); 149 | chk_pipe(); 150 | d_score(++score); 151 | } 152 | void rem_wall(int px,int py) 153 | { 154 | setfillstyle(SOLID_FILL,BLACK); 155 | bar(px,py+250,px+40,py+250+ran); 156 | bar(px-50,py+350,px-20,py+350+ran); 157 | 158 | //bar(px,py+300,px+30,py+ran); 159 | //bar(px-30,py+400,px,getmaxy()-ran) ; 160 | } 161 | 162 | 163 | 164 | void dance_pipe(int px,int py) 165 | { 166 | 167 | setfillstyle(1,GREEN); 168 | //up pipes 169 | bar(px,py,px+60,py+100); 170 | bar(px-15,py+100,px+75,py+120); 171 | 172 | ///down pipes 173 | 174 | bar(px-40,py+450,px+20,getmaxy()-50); 175 | bar(px-55,py+430,px+35,py+450); 176 | chk_pipe(); 177 | 178 | d_score(++score); 179 | } 180 | 181 | 182 | 183 | void dance_remove(int px,int py) 184 | { 185 | 186 | setfillstyle(1,BLACK); 187 | //up pipes 188 | bar(px,py,px+60,py+100); 189 | bar(px-15,py+100,px+75,py+120); 190 | 191 | ///down pipes 192 | 193 | bar(px-40,py+450,px+20,getmaxy()-50); 194 | bar(px-55,py+430,px+35,py+450); 195 | 196 | } 197 | 198 | 199 | 200 | 201 | 202 | void ball(int px,int py) 203 | { 204 | setfillstyle(SOLID_FILL,RED); 205 | // fillellipse(px,0,abs(py),ran); 206 | // fillellipse(px+ran,0,abs(py),ran); 207 | 208 | sector(px,0,180,360,75,(py+250)/2); 209 | sector(px,getmaxy()-50,0,180,75,(py+200)/2); 210 | 211 | 212 | setfillstyle(5,RED); 213 | fillellipse(px,py+ran+250,30,30) ; 214 | 215 | chk_pipe(); 216 | d_score(++score); 217 | } 218 | void rem_ball(int px,int py) 219 | { 220 | setfillstyle(SOLID_FILL,BLACK); 221 | 222 | // fillellipse(px,0,abs(py),ran); 223 | // fillellipse(px+ran,0,abs(py),ran); 224 | 225 | sector(px,0,180,360,75,(py+250)/2); 226 | sector(px,getmaxy()-50,0,180,75,(py+200)/2); 227 | fillellipse(px,py+ran+250,30,30) ; 228 | 229 | } 230 | 231 | 232 | 233 | void bkg() 234 | { 235 | setcolor(BLACK); 236 | 237 | randomize(); 238 | 239 | 240 | ran=random(80); 241 | 242 | py1=random(-200); 243 | 244 | A: 245 | py2=random(-200); 246 | if( abs(py1-py2)>100 ) 247 | goto A; 248 | 249 | B: 250 | py3=random(-200); 251 | if(abs(py2-py3)>100) 252 | goto B; 253 | 254 | 255 | C: 256 | py4=random(-200); 257 | if(abs(py3-py4)>100) 258 | goto C; 259 | 260 | 261 | 262 | } 263 | 264 | void bk_m(int level) 265 | { 266 | switch(level) 267 | { 268 | case 1:drawpipe(px,py1); 269 | drawpipe(px+160,py2); 270 | drawpipe(px+320,py3); 271 | drawpipe(px+480,py4); 272 | delay(1); 273 | removepipe(px,py1); 274 | removepipe(px+160,py2); 275 | removepipe(px+320,py3); 276 | removepipe(px+480,py4); 277 | break; 278 | 279 | case 2: 280 | draw_wall(px,py1); 281 | draw_wall(px+160,py2); 282 | draw_wall(px+320,py3); 283 | draw_wall(px+480,py4); 284 | delay(5); 285 | rem_wall(px,py1); 286 | rem_wall(px+160,py2); 287 | rem_wall(px+320,py3); 288 | rem_wall(px+480,py4); 289 | 290 | 291 | break; 292 | 293 | case 3: 294 | dance_pipe(px,py1); 295 | dance_pipe(px+160,py2); 296 | dance_pipe(px+320,py3); 297 | dance_pipe(px+480,py4); 298 | delay(1); 299 | dance_remove(px,py1); 300 | dance_remove(px+160,py2); 301 | dance_remove(px+320,py3); 302 | dance_remove(px+480,py4); 303 | bkg(); 304 | 305 | break; 306 | 307 | 308 | 309 | case 4:ball(px,py1); 310 | ball(px+150,py2); 311 | ball(px+300,py3); 312 | ball(px+450,py4); 313 | delay(1); 314 | rem_ball(px,py1); 315 | rem_ball(px+150,py2); 316 | rem_ball(px+300,py3); 317 | rem_ball(px+450,py4); 318 | break; 319 | } 320 | px=px-10; 321 | if(j==120 ) 322 | { 323 | px=getmaxx(); 324 | bkg(); 325 | j=1; 326 | } 327 | //if(level==3) 328 | //{ 329 | 330 | // bkg(); 331 | 332 | // } 333 | } 334 | 335 | void chk_pipe() 336 | { 337 | int yt=top-(rady-5),yb=top+rady+5; 338 | int clash=0; 339 | 340 | for(int x=left-66;x<=(left+radx+10);x++) //chk for up obstacle 341 | { 342 | if(getpixel(x,yt-1)==(GREEN) || getpixel(x,yb+1)==(GREEN ) ||getpixel(x,yt-1)==BROWN || getpixel(x,yb+1)==BROWN || (yt-1)<0 || (yb+1) >getmaxy() || getpixel(x,yt-1)==RED || getpixel(x,yb+1)==RED ) 343 | { 344 | clash=1; 345 | rem_heli(); 346 | } 347 | } 348 | if(getpixel(x,yb)==(GREEN) || getpixel(x,yt)==(GREEN)|| getpixel(x,yb)==BROWN || getpixel(x,yt)==BROWN||getpixel(x,yb)==(RED) || getpixel(x,yt)==(RED)) //chk for front obstacle 349 | { 350 | clash=1; 351 | rem_heli(); 352 | } 353 | if(clash==1) 354 | { 355 | while(top<=getmaxy()) 356 | { 357 | ulta_heli(); 358 | top=top+10; 359 | } 360 | 361 | cleardevice(); 362 | start(390); 363 | setfillstyle(SOLID_FILL,BLACK); 364 | bar(61,getmaxy()-394,539,getmaxy()-291); 365 | settextstyle(10,0,5); 366 | setcolor(WHITE); 367 | outtextxy(90,getmaxy()-390,"GAME OVER"); 368 | settextstyle(3,0,4); 369 | setcolor(LIGHTRED) ; 370 | outtextxy(150,getmaxy()-206,"SCORE :"); 371 | gotoxy(40,19); 372 | cout<= TotalOptions ? 1 : selected + 1; 415 | drawMenu ( selected , WHITE , RED ); 416 | } 417 | else if ( ch == 72 ) 418 | { 419 | selected = selected < 2 ? TotalOptions : selected - 1; 420 | drawMenu ( selected , WHITE , RED ); 421 | } 422 | 423 | }while ( ch != 13 ); 424 | 425 | return selected; 426 | } 427 | 428 | void drawMenu ( int selected , int defCol , int selCol ) 429 | { 430 | 431 | int x = 220; 432 | int y = 250; 433 | 434 | int h = 30; 435 | int i; 436 | int TotalOptions = 4; 437 | char menu_option[4][14]= { 438 | " PLAY ", 439 | " LEVELS ", 440 | " ABOUT ", 441 | " EXIT " 442 | }; 443 | 444 | cleardevice(); 445 | 446 | start(390); 447 | 448 | 449 | 450 | setlinestyle(0,0,1); 451 | 452 | for ( i = 1; i <= TotalOptions; i++ ) 453 | { 454 | if ( i == selected ) 455 | { 456 | 457 | setcolor ( selCol ); 458 | setfillstyle(INTERLEAVE_FILL,selCol); 459 | 460 | } 461 | else 462 | { 463 | setfillstyle(SOLID_FILL,0); 464 | bar(x,y,x+15,y+40); 465 | setcolor ( defCol ); 466 | setfillstyle(EMPTY_FILL,defCol); 467 | } 468 | 469 | fillellipse(x+7,y+25,7,7); 470 | settextstyle(3,0,3); 471 | outtextxy ( x + 20 , y + 10 , menu_option[i - 1] ); 472 | y = y + h + 15; 473 | 474 | delay(20); 475 | 476 | 477 | } 478 | } 479 | 480 | 481 | void start(int i) 482 | { 483 | setcolor(WHITE); 484 | setlinestyle(0,0,1); 485 | settextstyle(10,0,5); 486 | outtextxy(80,getmaxy()-i,"HELI"); 487 | outtextxy(330,getmaxy()-i,"OPTER"); 488 | settextstyle(3,0,4); 489 | outtextxy(280,getmaxy()-i+30,"Z"); 490 | setcolor(WHITE); 491 | rectangle(230,getmaxy()-i,310,getmaxy()-i+80); 492 | rectangle(237,getmaxy()-i+7,303,getmaxy()-i+73); 493 | 494 | setfillstyle(SOLID_FILL,RED); 495 | bar(60,getmaxy()-i-25,70,getmaxy()-i-45); 496 | bar(540,getmaxy()-i-25,530,getmaxy()-i-45); 497 | 498 | 499 | top=getmaxy()-i-55; 500 | left=65; 501 | draw_heli(); 502 | left=535; 503 | draw_heli(); 504 | 505 | 506 | setcolor(RED); 507 | rectangle(50,getmaxy()-i-25,550,getmaxy()-i+115); 508 | setlinestyle(3,0,2); 509 | rectangle(60,getmaxy()-i-5,540,getmaxy()-i+100); 510 | 511 | delay(20); 512 | 513 | } 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | void level_page() 527 | { 528 | int lx,ly; 529 | lx=150; 530 | ly=150; 531 | level_draw(lx,ly); 532 | char ch; 533 | again: 534 | ch=getch(); 535 | 536 | while(ch!=13) 537 | { 538 | if(ch==77) 539 | { 540 | if(level==4) 541 | goto again; 542 | ++level; 543 | //if(level>4) 544 | //level=1; 545 | lx=lx-325; 546 | level_draw(lx,ly); 547 | } 548 | else if(ch==75) 549 | { 550 | if(level==1) 551 | goto again; 552 | --level; 553 | //if(level<1) 554 | ///level=4; 555 | lx=lx+325; 556 | level_draw(lx,ly); 557 | } 558 | 559 | ch=getch(); 560 | } 561 | 562 | } 563 | 564 | 565 | 566 | 567 | ////////////////////////////////////////////////////////////////// 568 | 569 | void level_draw(int lx,int ly) 570 | { 571 | cleardevice(); 572 | setfillstyle(SOLID_FILL,LIGHTRED); 573 | 574 | //main boxes 575 | bar(lx,ly,lx+300,ly+260); 576 | bar(lx+350,ly,lx+650,ly+260); 577 | bar(lx+700,ly,lx+1000,ly+260); 578 | bar(lx+1050,ly,lx+1350,ly+260); 579 | 580 | 581 | //chotu boxes 582 | bar(getmaxx()/2-50,getmaxy()-50,getmaxx()/2-40,getmaxy()-40); 583 | bar(getmaxx()/2-20,getmaxy()-50,getmaxx()/2-10,getmaxy()-40); 584 | bar(getmaxx()/2+10,getmaxy()-50,getmaxx()/2+20,getmaxy()-40); 585 | bar(getmaxx()/2+40,getmaxy()-50,getmaxx()/2+50,getmaxy()-40); 586 | setfillstyle(SOLID_FILL,GREEN); 587 | 588 | 589 | switch(level) 590 | { 591 | case 1: bar(lx,ly,lx+300,ly+260); 592 | bar(getmaxx()/2-50,getmaxy()-50,getmaxx()/2-40,getmaxy()-40); 593 | break; 594 | case 2: 595 | bar(lx+350,ly,lx+650,ly+260); 596 | bar(getmaxx()/2-20,getmaxy()-50,getmaxx()/2-10,getmaxy()-40); 597 | break; 598 | case 3: 599 | bar(lx+700,ly,lx+1000,ly+260); 600 | bar(getmaxx()/2+10,getmaxy()-50,getmaxx()/2+20,getmaxy()-40); 601 | 602 | break; 603 | case 4: 604 | bar(lx+1050,ly,lx+1350,ly+260); 605 | bar(getmaxx()/2+40,getmaxy()-50,getmaxx()/2+50,getmaxy()-40); 606 | 607 | 608 | break; 609 | default : cout<<"\n\nThere is some error in the game....CONTACT DEVELOPERS (Karan Khanna and Ayushi Jain)"; 610 | } 611 | 612 | 613 | 614 | //setcolor(BLACK); 615 | setfillstyle(1,LIGHTGRAY); 616 | bar(lx+60,ly,lx+80,ly+100); 617 | bar(lx+140,ly,lx+160,ly+100); 618 | bar(lx+230,ly,lx+250,ly+100); 619 | bar(lx+30,ly+160,lx+50,ly+260); 620 | bar(lx+110,ly+160,lx+130,ly+260); 621 | bar(lx+260,ly+160,lx+280,ly+260); 622 | setcolor(WHITE); 623 | settextstyle(10,0,1); 624 | outtextxy(lx+115,ly+110,"PIPES"); 625 | 626 | outtextxy(lx+460,ly+20,"BRICKS"); 627 | 628 | setfillstyle(LINE_FILL,RED); 629 | bar(lx+400,ly+80,lx+430,ly+110); 630 | bar(lx+500,ly+120,lx+530,ly+150); 631 | bar(lx+600,ly+130,lx+630,ly+160); 632 | bar(lx+450,ly+200,lx+480,ly+230); 633 | bar(lx+580,ly+70,lx+610,ly+100); 634 | bar(lx+550,ly+220,lx+580,ly+250); 635 | bar(lx+390,ly+170,lx+420,ly+200); 636 | 637 | 638 | setfillstyle(1,LIGHTGRAY); 639 | bar(lx+750,ly,lx+770,ly+100); 640 | bar(lx+800,ly,lx+820,ly+50); 641 | bar(lx+880,ly,lx+900,ly+80); 642 | bar(lx+950,ly,lx+970,ly+90); 643 | bar(lx+790,ly+200,lx+810,ly+260); 644 | bar(lx+850,ly+150,lx+870,ly+260); 645 | bar(lx+730,ly+220,lx+750,ly+260); 646 | bar(lx+940,ly+190,lx+960,ly+260); 647 | setcolor(WHITE); 648 | settextstyle(10,0,1); 649 | outtextxy(lx+745,ly+110,"DANCING PIPES"); 650 | 651 | 652 | 653 | 654 | 655 | 656 | outtextxy(lx+1120,ly+110,"ROUND HILLS"); 657 | 658 | 659 | settextstyle(9,0,4); 660 | outtextxy(100,50,"SELECT LEVEL"); 661 | settextstyle(6,0,1); 662 | outtextxy(470,85,"and press enter.."); 663 | 664 | } 665 | 666 | 667 | 668 | 669 | void play() 670 | { 671 | top=200; 672 | left=200; 673 | cleardevice(); 674 | px=getmaxx(); 675 | bkg(); 676 | A: 677 | 678 | while(!kbhit()) 679 | { 680 | bk_m(level); 681 | downheli(); 682 | 683 | ch='/0'; 684 | ++j; 685 | } 686 | 687 | if(kbhit()) 688 | { 689 | 690 | ch=getch(); 691 | if(ch=='z') 692 | { 693 | bk_m(level); 694 | upheli(); 695 | ++j; 696 | goto A; 697 | } 698 | } 699 | 700 | 701 | 702 | } 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | void main() 728 | { 729 | char ch; 730 | int gm,gd=DETECT; 731 | initgraph(&gd,&gm,"c:\\turboc3\\bgi"); 732 | cleardevice(); 733 | 734 | for(int i=0;i<400;i=i+10) 735 | { 736 | cleardevice(); 737 | start(i); 738 | } 739 | 740 | left=200; 741 | 742 | a: 743 | 744 | int selected =main_menu(); 745 | 746 | switch(selected) 747 | { 748 | case 1: cleardevice(); 749 | play(); 750 | goto a; 751 | break; 752 | case 2: cleardevice(); 753 | level_page(); 754 | goto a; 755 | break; 756 | 757 | case 3 : cleardevice(); 758 | start(390); 759 | bar(0,getmaxy()-50,getmaxx(),getmaxy()); 760 | settextstyle(7,0,5); 761 | outtextxy(220,getmaxy()-50,"ABOUT"); 762 | setcolor(WHITE); 763 | settextstyle(7,0,3); 764 | 765 | outtextxy(80,getmaxy()/2,"KARAN KHANNA"); 766 | 767 | outtextxy(300,getmaxy()/2+40,"&"); 768 | outtextxy(350,getmaxy()/2+70,"AYUSHI JAIN"); 769 | settextstyle(2,0,5); 770 | setcolor(RED); 771 | outtextxy(360,390,"Press any key to continue....."); 772 | 773 | getch(); 774 | goto a; 775 | case 4: 776 | cleardevice(); 777 | 778 | gotoxy(25,15); 779 | cout<<" HOPE YOU ENJOYED.... :-) "; 780 | delay(1000); 781 | closegraph(); 782 | exit(0); 783 | break; 784 | 785 | default:goto a; 786 | break; 787 | } 788 | 789 | 790 | 791 | getch(); 792 | cleardevice(); 793 | closegraph(); 794 | } --------------------------------------------------------------------------------