Expand|Select|Wrap|Line Numbers
- #include<graphics.h>
- #include<iostream.h>
- #include<conio.h>
- #include<process.h>
- #include<dos.h>
- #include<math.h>
- #include<stdlib.h>
- int BirdSpeed=0;
- int BirdColor=0;
- int AngleProjection=0;
- int Velocity=0;
- int Power=0;
- int Lives=0;
- int Level=1;
- int Pigs=0;
- int TotalPigs=0;
- int PigCx[5];
- int PigCy[5];
- int PigSz[5];
- void Blast();
- void PlayGame();
- void BirdMenu();
- void GameInput();
- void Scene();
- void MenuChoice();
- void MakeMenu();
- void Pig(int,int,int);
- void Instructions();
- void EndScreen();
- void EndScreen(int x)
- { switch(x)
- {
- case 1:
- cleardevice();
- settextstyle(TRIPLEX_FONT,0,8);
- setcolor(RED);
- outtextxy(240,30," RIP ");
- setcolor(WHITE);
- settextstyle(DEFAULT_FONT,0,1);
- outtextxy(240,200,"\n You Died \n");
- outtextxy(240,240,"\n Level: \n");
- outtextxy(240,280,"\n Pigs Killed: \n");
- char level[10];
- char killedpigs[10];
- int killed=TotalPigs-Pigs;
- itoa(killed,killedpigs,10);
- itoa(Level,level,10);
- outtextxy(310,240,level);
- outtextxy(360,280,killedpigs);
- setcolor(GREEN);
- outtextxy(240,300,"Restart?(Y/N)");
- char ch=getch();
- if(ch=='y')
- BirdMenu();
- else
- exit(0);
- break;
- case 2:
- cleardevice();
- settextstyle(TRIPLEX_FONT,0,8);
- setcolor(RED);
- outtextxy(240,30," Congrats ");
- setcolor(WHITE);
- settextstyle(DEFAULT_FONT,0,1);
- outtextxy(240,200,"\n You Won!!!! \n");
- outtextxy(240,240,"\n Level: \n");
- outtextxy(240,280,"\n Pigs Killed: \n");
- char level2[10];
- char killedpigs2[10];
- int killed2=TotalPigs-Pigs;
- itoa(killed2,killedpigs2,10);
- itoa(Level,level2,10);
- outtextxy(310,240,level2);
- outtextxy(360,280,killedpigs2);
- setcolor(GREEN);
- outtextxy(240,300,"Restart?(Y/N)");
- char ch1=getch();
- if(ch1=='y')
- BirdMenu();
- else
- exit(0);
- break;
- }
- }
- void Blast(int x, int y,int r)
- {
- float i;
- for(i=0;i<=r;i=i+1)
- {
- setcolor(14);
- circle(x,y,i);
- sound(i*100);
- delay(1);
- setcolor(0);
- circle(x,y,i);
- nosound();
- }
- }
- void Collision(int birdcx,int birdcy)
- {
- for(int i=1;i<=TotalPigs;i++)
- {
- if(PigSz[i]==0)
- continue;
- if((birdcx>=(PigCx[i]-PigSz[i]-9)&&birdcx<=(PigCx[i]+PigSz[i]))&&((birdcy>=(PigCy[i]-PigSz[i])-9)&&(birdcy<=(PigCy[i]+PigSz[i]+9))))
- {
- Blast(PigCx[i],PigCy[i],PigSz[i]);
- PigSz[i]=0;
- Pigs--;
- }
- }
- }
- void Level_1_Scene()
- { Lives=2;
- Pigs=TotalPigs=1;
- PigCx[1]=200;PigCy[1]=300;PigSz[1]=10;
- Pig(200,300,10);
- }
- void Level_2_Scene()
- { Lives=3;
- Pigs=TotalPigs=2;
- PigCx[1]=580;PigCy[1]=400;PigSz[1]=10;
- PigCx[2]=540;PigCy[2]=400;PigSz[2]=15;
- int pigs=Pigs;
- while(pigs>0)
- { Pig(PigCx[pigs],PigCy[pigs],PigSz[pigs]);
- pigs--; }
- }
- void Level_3_Scene()
- { Lives=4;
- Pigs=TotalPigs=4;
- PigCx[1]=580;PigCy[1]=400;PigSz[1]=10;
- PigCx[2]=600;PigCy[2]=400;PigSz[2]=10;
- PigCx[3]=620;PigCy[3]=400;PigSz[3]=10;
- PigCx[4]=600;PigCy[4]=350;PigSz[4]=20;
- int pigs=Pigs;
- while(pigs>0)
- { Pig(PigCx[pigs],PigCy[pigs],PigSz[pigs]);
- pigs--; }
- }
- void Pig(int cx,int cy,int sz)
- {
- setcolor(GREEN);
- circle(cx,cy,sz);
- circle(cx,cy+3,sz/3);
- setcolor(WHITE);
- circle(cx+3,cy-3,2);
- circle(cx-3,cy-3,2);
- }
- void Bird(int cx,int cy)
- {
- setlinestyle(0,0,3);
- setcolor(BirdColor);
- circle(cx,cy,10);
- setcolor(WHITE);
- line(cx-8,cy-8,cx-1,cy-1);
- line(cx+8,cy-8,cx+1,cy-1);
- setcolor(YELLOW);
- line(cx-8,cy+3,cx+8,cy+3);
- /*
- line(cx,cy,cx+6,cy+3);
- line(cx+6,cy+3,cx,cy+3);
- line(cx,cy,cx,cy+6);
- */
- }
- void ClrBird(int cx,int cy)
- {
- setlinestyle(0,0,3);
- setcolor(BLACK);
- circle(cx,cy,10);
- line(cx-8,cy-8,cx-1,cy-1);
- line(cx+8,cy-8,cx+1,cy-1);
- line(cx-8,cy+3,cx+8,cy+3);
- }
- void MenuChoice()
- { char choice;
- choice=getch();
- sound(500);
- delay(100);
- nosound();
- switch(choice)
- {
- case 's':
- BirdMenu();
- break;
- case 'e':
- exit(0);
- break;
- default:
- EndScreen(1);
- }
- }
- void MakeMenu()
- {
- cleardevice();
- settextstyle(DEFAULT_FONT,0,6);
- outtextxy(60,110,"ANGRY BIRDS");
- settextstyle(DEFAULT_FONT,0,1);
- setcolor(BLUE+BLINK);
- outtextxy(100,200,"(S)START");
- setcolor(RED+BLINK);
- outtextxy(100,280,"(E)EXIT");
- do
- {int n;
- n=0;
- while( n<30)
- {if(kbhit()!=0)
- goto endanim;
- BirdColor=(n%10)+1;
- Bird(400,300+(5*n));
- BirdColor=(n%10)+2;
- Bird(430,300+(5*n));
- BirdColor=(n%10)+3;
- Bird(450,300+(5*n));
- ClrBird(400,300+(5*n));
- ClrBird(430,300+(5*n));
- ClrBird(450,300+(5*n));
- n++;
- }
- while( n>=30)
- {
- if( kbhit()!=0)
- goto endanim;
- BirdColor=(n%10)+1;
- Bird(400,(5*n)+300);
- BirdColor=(n%10)+2;
- Bird(430,(5*n)+300);
- BirdColor=(n%10)+3;
- Bird(450,(5*n)+300);
- ClrBird(400,(5*n)+300);
- ClrBird(430,(5*n)+300);
- ClrBird(450,(5*n)+300);
- n--;
- }
- } while(1);
- endanim:
- MenuChoice();
- }
- void BirdMenu()
- {
- cleardevice();
- settextstyle(DEFAULT_FONT,0,4);
- setcolor(CYAN);
- outtextxy(20,20,"Choose a bird");
- settextstyle(SMALL_FONT,0,7);
- setcolor(RED);
- outtextxy(40,60,"(R)RED");
- outtextxy(50,80,"Speed:*** \n Luck:***** \n Special Move:DROP");
- setcolor(YELLOW);
- outtextxy(40,120,"(Y)YELLOW");
- outtextxy(50,140,"Speed:***** \n Luck:*** \n Special Move:BOOST");
- setcolor(BLUE);
- outtextxy(40,180,"(B)BLUE");
- outtextxy(50,200,"Speed:**** \n Luck:**** \n Special Move:BOMB");
- setcolor(WHITE);
- outtextxy(40,250,"(E)Exit");
- char inp=getch();
- sound(900);
- delay(100);
- nosound();
- if(inp=='r')
- { BirdSpeed=3;BirdColor=4;}
- if(inp=='y')
- { BirdSpeed=4;BirdColor=14;}
- if(inp=='b')
- { BirdSpeed=4;BirdColor=1;}
- else if(inp=='e')
- { MakeMenu(); }
- Instructions();
- }
- void Instructions()
- {
- cleardevice();
- settextstyle(TRIPLEX_FONT,0,3);
- setcolor(RED);
- outtextxy(20,20,"Instructions");
- setcolor(YELLOW);
- settextstyle(DEFAULT_FONT,0,1);
- outtextxy(20,70,"Press W to increase the power");
- outtextxy(20,90,"Press S to decrease the power");
- outtextxy(20,110,"Press A to increase the angle");
- outtextxy(20,130,"Press D to decrease the angle");
- setcolor(GREEN);
- outtextxy(20,170,"Press Spacebar to launch");
- outtextxy(20,190,"Press N for special move");
- setcolor(WHITE);
- outtextxy(20,230,"Press any key to continue");
- getch();
- sound(800);
- delay(100);
- nosound();
- Scene();
- }
- void Scene()
- {
- cleardevice();
- setcolor(GREEN);
- line(0,420,650,420);
- setlinestyle(SOLID_LINE,1,THICK_WIDTH);
- setfillstyle(HATCH_FILL,RED);
- floodfill(10,455,GREEN);
- setcolor(BROWN);
- line(75,420,75,380);
- line(85,420,85,380);
- line(75,380,65,370);
- line(85,380,95,370);
- setcolor(RED);
- line(65,370,70,370);
- line(85,370,95,370);
- Level_1_Scene();
- {
- while(Lives>=0 && Pigs>0)
- { GameInput(); Lives--;}
- if(Lives>=0)
- { Level++;
- Level_2_Scene();
- while(Lives>=0 && Pigs>0)
- { GameInput(); Lives--;}
- if(Lives>=0)
- {Level++;
- Level_3_Scene();
- while(Lives>=0 && Pigs>0)
- { GameInput(); Lives--;}
- if(Lives>=0)
- EndScreen(2);
- }
- else
- EndScreen(1);
- }
- else
- EndScreen(1);
- }
- }
- void GuideLine(int power,int angle,int color)
- {
- float a_rad=angle*(3.14156/180);
- setcolor(color);
- setlinestyle(DOTTED_LINE,0,3);
- line(80,370,80+(power*cos(a_rad)),370+(power*sin(a_rad)));
- }
- void ClrGuideLine(int power,int angle)
- {
- float a_rad=angle*(3.14156/180);
- setcolor(BLACK);
- setlinestyle(DOTTED_LINE,0,3);
- line(80,370,80+(power*cos(a_rad)),370+(power*sin(a_rad)));
- }
- void GameInput()
- { setfillstyle(SOLID_FILL,BLACK);
- bar(0,0,200,100);
- int color=0;
- AngleProjection=360;
- Power=20;
- GuideLine(20,360,2);
- Bird(80,370);
- char ch;
- setfillstyle(SOLID_FILL,RED);
- outtextxy(50,20,"Lives :");
- bar(120,20,Lives*10+120,25);
- setfillstyle(SOLID_FILL,BLUE);
- outtextxy(50,50,"Pigs Left :");
- bar(150,50,Pigs*10+150,55);
- setfillstyle(SOLID_FILL,YELLOW);
- outtextxy(50,80,"Level :");
- bar(120,80,Level*10+120,85);
- while((ch=getch())!=' ')
- {
- ClrGuideLine(Power,AngleProjection);
- if(ch==97&&AngleProjection>270)
- AngleProjection-=5;
- if(ch==100&&AngleProjection<360)
- AngleProjection+=5;
- if(ch==119&&Power<30)
- Power+=5;
- if(ch==115&&Power>5)
- Power-=5;
- if(Power<=15)
- color=2;
- else if(Power>15&&Power<=20)
- color=14;
- else if(Power>20)
- color=4;
- GuideLine(Power,AngleProjection,color);
- Bird(80,370);
- }
- ClrGuideLine(Power,AngleProjection);
- PlayGame();
- }
- void PlayGame()
- {
- float t,a_rad;
- int x=80,y=370;
- int oldx,oldy;
- a_rad=(360-AngleProjection)*3.141592/180;
- for(t=0;y<=420 &&x<=640 && x>=0;t+=0.02)
- {
- oldx=x;
- oldy=y;
- x+=(Power*BirdSpeed*0.25*cos(a_rad)*t);
- y-=((Power*0.8*sin(a_rad)*t)-(15*t*t));
- if(kbhit()!=0)
- { char ch;
- ch=getch();
- if(ch=='n')
- {if(BirdColor==RED)
- Power=0;
- if(BirdColor==YELLOW)
- Power+=30;
- if(BirdColor==BLUE)
- {int Rand;
- Rand=rand()%10;
- if(Rand%2==0)
- BirdColor=RED;
- else
- BirdColor=YELLOW; }
- }
- }
- Collision(x,y);
- ClrBird(oldx,oldy);
- Bird(x,y);
- }
- getch();
- ClrBird(x,y);
- }
- void main()
- {
- int driver,mode;
- driver=DETECT;
- initgraph(&driver,&mode,"C:\\turboC3\\bgi\\");
- MakeMenu();
- closegraph();
- }