Vous êtes sur la page 1sur 40

Institute of Information Technology

Jahangirnagar University Bachelor of Information Technology (BIT) 1st Year, 1st Semester Session: 2009-2010 Submission of Semester Project

Shooting Bird
Submitted to: Institute of Information Technology

THANKS TO ALL OF OUR TEACHERS

Abstract:
The game is to shoot birds with gulti and bricks. The game is developed in C programming. The score in the game is incremented by shooting birds gradually. There are three levels in this game. The user is provided only a limited number of bricks and birds for each level. If a player gets a minimum score, he will be eligible for entering in next level, otherwise the game will be over and he will be looser. If the player completed all the levels, he will be winner. This program requires some sub-functions such as void start( ),draw_hunt( ),draw_bird( ),draw_brick( ),draw_gulti( ) and void fly( ) which are performing under some header files such as graphics.h , stdlib.h , dos.h.The game will seem very interesting and easy to play to the player.

Index:

Item 1. Introduction 2. Requirements 3. Analysis of the project 4. Flow chart 5. Screen shot of the output 6. Code description 7. Findings and future plan 8. Conclusion

Page No 1 2 3 5 7 10 34 35

Introduction:
This game is to shoot birds with bricks. There are three levels in this game. The user is provided only a limited number of bricks and birds for each level. There is a gulti. The user will get 20 points by shooting a bird. He can go through one level to another by achieving a perfect score. The point increments by shooting each of the birds. The game finishes when all the birds are shot and the user gets his score.

Requirements:
The game requires some header files with the slandered library file. These are: conio.h graphics.h stdlib.h dos,h

Analysis of The Project:


The game is to shoot bird with gulti. The game has some sub functions which are called in the main( ).This sub functions are performing many important tasks. Void start( ) To write down the welcome screen and the instructions screen of the game. Here we have used sound( ) to create a music. While the user will hit any key on keyboard, then the music will stopped.

We have

used setbkcolor, settextstyle, setcolor, setusercharsize, outtextxy and in last clearviewport for clearing the welcome screen in this function.
Draw_hunt( ) To draw the image of the shot bird. Here we use the line(x1,y1,x2,y2) for drawing the image. Draw_bird( ) To draw the bird using circle( ),arc( ),line( ).we use setcolor( ) to select a colour. Draw_brick( ) To draw the brick using circle( ),

setcolor( ), setlinestyle(

) for setting color;


Draw_gulti( ) This function is used to draw the gulti.

In this, we have

used setcolor, setlinestyle for setting the color and style of the line.
Draw_shoot(int*x,int*y ) To move the position of the bricks. In this function we put the image of the brick on the screen when it desired. After shooting an brick we decrease the number of bricks. Here we also display

the number of remaining bricks. Pointers are used to pass the coordinates by reference. Void fly( int*x,int*y ) This function is used for flying the birds. The birds will fly from lower portion of the screen to upper portion. If one bird crosses the screen or is shot then there is a decrement in number of birds Inttestkey( ) To get the ASCII code and the scan code of the key pressed.

Data Flow Diagram: Void main( )


Declare the calling function and the data type

Void start( )
Write down the welcome screen and the instruction screen rectangle(x1,y1,x2,y2),setbkcolor( ),outtextxy(),setcolor() and clearviewport() to clear the welcome screen. Get the ASCII code and scan code

draw_hunt
Make the image of hunting bird using setlinestyle(), Setcolor(),line(x1,y1,x2,y2).

draw_bird
Draw the bird using circle(), Setcolor(),setlinestyle() , Line(x1,y1,x2,y2) and arc().

draw_brick()
Draw the brick using circle(),

draw_gulti()
Draw the gulti using setcolor(), Setlinestyle().

draw_shoot()
Put the image of the brick on the screen when it desired. After shooting a brick we decrease the number of bricks.

draw_fly()
Darw the image of flying the birds. The birds fly from lower portion of the screen to upper portion. If one bird crosses the screen or is shot then there is a decrement in number of biDisplay the number of remaining

Setcolor(), setlinestyle().

Flow of the output steps: Wellcome sereen

Instractions

1st level

2nd level

Score

3rd level

10

Screen Shot of the Output:

11

12

13

14

Code Description:
This is a simple bird shooting game made in C language. In this game, there are number of birds, a gulti and bricks for shooting the birds. The birds rise from the lower portion of the screen. The gulti is put on left side which can move up and down. If player shoot a bird he will get 20 points. There are total three levels in this game. There are 10 birds and 6 bricks in first level. If player get a minimum score of 100, he will be eligible for entering in second level. If he not gets this minimum score, he is not qualified for second level and game will be over and he is the looser. There are 8 birds and 6 bricks in second level. If user gets a minimum score of 180, he will be eligible for entering in third level. In third level there are 6 birds and 6 bricks. If player completed all the three levels, he will be winner. The up and down arrow key are used for positioning the gulti. The right arrow( ) key will be used for shooting. Different Functions used in the project: - void draw_bird(int ,int ): This function is used for drawing a bird. In this function we first use setcolor and setfillstyle which set the color red and also filling style. After this we are using circle( ) for drawing the bird and arc( ) for drawing the wing of the bird. void draw_hunt ( int x, int y ): This function is used for making the image of hunting of bird. void draw_gulti(int x, int y): This function is used for drawing the gulti. In this, we are using setcolor, setlinestyle for setting the color and style of the line. After that we are using line and arc functions for drawing the gulti. void draw_brick(int x, int y): This function is used for drawing the brick. In which we are using circle for drawing the brick by considering the relative position of each circle. void shoot(int *x, int *y): In this function we put the image of the brick on the screen when it desired. After shooting a bird we decrease the number of bricks. Here we also display the number of remaining bricks. Pointers are used to pass the coordinates by reference. void fly(int *x, int *y): This function is used for flying the birds. The birds will fly from lower portion of the screen to upper portion. If one bird crosses the screen or is shot then there is a decrement in number of birds. void start(): This function is used for showing our welcome screen. Here we are using setbkcolor, settextstyle, setcolor, setusercharsize, outtextxy and in last clearviewport for clearing the welcome screen. int testkeys(): This function is used for getting the ascii code and scan code for the key pressed.

15

//Shooting Bird - A Game ( Mini Project )

# include "graphics.h" # include "conio.h" # include "stdio.h" # include "stdlib.h" # include "dos.h" #define BRICK_SIZE 7 #define BIRD_SIZE 3

int flag_brick=0,flag_bird=1,count_brick=6,count_bird=10; void *bird,*gulti,*brick,*hunt; void *clear_bird,*clear_hunt; void draw_bird(int ,int ); void draw_hunt ( int x, int y ); void draw_gulti(int x,int y); void draw_brick(int x, int y); void shoot(int *x, int *y); int testkeys();

16

void fly(int *x, int *y); void start();

void main() { int gmode = DETECT, gdriver , area ; initgraph ( &gmode, &gdriver, "c:\\TC\\BGI" ) ; setbkcolor(1); start(); int maxx = getmaxx() ; int maxy = getmaxy() ; int p=500,q=100,m=100,n=100,x=m,y=n,key,score=0,finish=0,level=1,l_flag =1; char score1[5],ch,cnt_bird[5],char_level[2]; //int midx=getmaxx()/2 , midy=getmaxy()/2 ; rectangle ( 0, 0, maxx, maxy - 10 ) ;

draw_hunt(200,300); area=imagesize(0,0,32,24); hunt=malloc(area);

17

getimage(200-16,300-12,200+16,300+12,hunt); putimage(200-16,300-12,hunt,XOR_PUT);

draw_bird(p,q);

area=imagesize(p-12*BIRD_SIZE,q12*BIRD_SIZE,p+10*BIRD_SIZE,q+10*BIRD_SIZE); bird=malloc(area);

getimage(p-12*BIRD_SIZE,q12*BIRD_SIZE,p+10*BIRD_SIZE,q+10*BIRD_SIZE,bird); putimage(p-12*BIRD_SIZE, q-12*BIRD_SIZE, bird, COPY_PUT);

draw_brick(x ,y ); area = imagesize(x-10, y-2*BRICK_SIZE, x+(10*BRICK_SIZE), y+3*BRICK_SIZE); brick=malloc(area); getimage(x-10, y-2*BRICK_SIZE, x+(10*BRICK_SIZE), y+3*BRICK_SIZE,brick); putimage(x-10, y-2*BRICK_SIZE,brick,XOR_PUT);

18

draw_gulti(x,y); area=imagesize(x+65,y+10,x+66,y+65); gulti=malloc(area); getimage(x,y-65,x+66,y+65,gulti);

if ( bird == NULL || hunt == NULL || gulti == NULL ) { printf( "Insufficient memory... Press any key " ) ; getch() ; closegraph() ; restorecrtmode() ; exit( 0 ) ; }

while (!finish) { settextstyle(0,0,3); setusercharsize(4,4,3,3); outtextxy(getmaxx()/2-100,5,"LEVEL : ");

19

itoa(level,char_level,10); setfillstyle(0,0); bar(getmaxx()/2+40,15,getmaxx()/2+70,45); setcolor(getmaxcolor()/3.5);

outtextxy(getmaxx()/2+50,5,char_level);

rectangle(5,360,250,460);

if( flag_bird && count_bird>0 ) fly( &p, &q ); else { q = 400; flag_bird = 1; }

if( kbhit() ) { key = testkeys();

20

if(key==77) flag_brick = 1; }

if( key == 27 ) break; if (key == 80 &&!flag_brick) { x=125; putimage(x,y-65,gulti,XOR_PUT); if(y<300) y+=25; putimage(x,y-65,gulti,XOR_PUT); draw_gulti(x-25,y); key=0; } if (key == 72 &&!flag_brick) { x=125; putimage(x,y-65,gulti,XOR_PUT);

21

if(y>70) y-=25; putimage(x,y-65,gulti,XOR_PUT); draw_gulti(x-25,y); key=0; } if(count_brick > 0 && count_bird > 0) { if(score==100 && l_flag==1) { level=2; count_bird=8; count_brick=6; l_flag=2; } if(score==180 && l_flag==2) { level=3; count_bird=6; count_brick=6;

22

l_flag=0; } if( key == 77 || flag_brick) { shoot(&x,&y); draw_gulti(m,y); if(x>(p-12) && x<(p+12) && y>(q-15) && y<(q+25)) { putimage(p-16,q-12,hunt,COPY_PUT); sound(1500); delay(800); nosound(); putimage(p-16,q-12,hunt,XOR_PUT); count_bird--; settextstyle(10,0,1); setusercharsize(30,70,20,70); outtextxy(20,380,"BIRDS LEFT:"); setfillstyle(0,0); bar(200,370,230,400); itoa(count_bird,cnt_bird,10);

23

outtextxy(200,380,cnt_bird); flag_bird=0; score+=20; itoa(score,score1,10); setfillstyle(0,0); bar(190,getmaxy()-50,230,getmaxy()-30); setcolor(RED); outtextxy(20,getmaxy()-50,"SCORE outtextxy(190,getmaxy()-50,score1); } : ");

key=0; } } else { clearviewport(); setbkcolor(14); setcolor(RED); settextstyle(4,0,7);

24

setusercharsize(120,50,120,40); outtextxy(getmaxx()/2-220,getmaxy()/2-180,"GAME OVER");

settextstyle(8,0,1); setusercharsize(50,60,40,50); if(count_brick<=0) outtextxy(getmaxx()/2-100,getmaxy()/2-70,"NO MORE BRICKS");

if(count_bird<=0) outtextxy(getmaxx()/2-120,getmaxy()/2-70,"NO MORE BIRDS");

outtextxy(getmaxx()/2-120,getmaxy()/2-20,"YOUR SCORE IS : "); itoa(score,score1,10); outtextxy(getmaxx()/2+150,getmaxy()/2-20,score1);

if(level==1) outtextxy(getmaxx()/2-220,getmaxy()/2+20,"YOU REQUIRE TO PRACTICE MORE"); if(level==2) outtextxy(getmaxx()/2-70,getmaxy()/2+20,"WELL PLAYED"); if(level==3)

25

outtextxy(getmaxx()/2-220,getmaxy()/2+20,"YOU ARE AN EFFICIENT SHOOTER");

outtextxy(getmaxx()/2-30,getmaxy()/2+50,"(Q)UIT");

settextstyle(1,0,1); setusercharsize(30,65,30,60); while( getch() != 'q'); finish=1; break; } } free(gulti); free(brick); free(bird); closegraph(); }

void draw_bird(int x,int y) { setcolor(RED);

26

setlinestyle(0,0,3); circle(x,y,5); circle(x,y,4.9); circle(x,y,4.8); circle(x,y,4.2); circle(x,y,4.1); circle(x,y,4); circle(x,y,3.95); circle(x,y,2.6); setcolor(BLUE); circle(x+10,y+10,10); circle(x+10,y+10,9.5); circle(x+10,y+10,8.5); circle(x+10,y+10,5.5); circle(x+10,y+10,5); circle(x+10,y+10,4.5); circle(x+10,y+10,3); circle(x+10,y+10,2.5); circle(x+10,y+10,2); circle(x+10,y+10,.95);

27

setlinestyle(0,0,2); line ( x-5, y ,x-18,y); line ( x-5, y-4 ,x-18,y); setlinestyle(0,0,3); setcolor(YELLOW); line (x-2, y-2 ,x-2,y-2); setlinestyle(0,0,2); setcolor(RED); arc(x-7,y-10,300,360,5); arc(x-5,y-15,300,360,10); setcolor(BLUE); arc(x+16,y-5,300,360,10); arc(x+13,y-6,300,360,10); arc(x+10,y-7,300,360,10); arc(x+7,y-8,300,360,10); setcolor(8); arc(x+1,y+19,300,360,8); arc(x-3,y+19,300,360,8); }

28

void draw_hunt ( int x, int y ) { setcolor(4); setlinestyle(0,0,3); line ( x - 16, y - 12, x - 10, y - 2 ) ; line ( x - 10, y - 2, x - 16, y ) ; line ( x - 16, y, x - 10, y + 2 ) ; line ( x - 10, y + 2, x - 16, y + 12 ) ;

line ( x - 16, y + 12, x - 6, y + 2 ) ; line ( x - 6, y + 2, x, y + 12 ) ; line ( x, y + 12, x + 6, y + 2 ) ; line ( x + 6, y + 2, x + 16, y + 12 ) ;

line ( x - 16, y - 12, x - 6, y - 2 ) ; line ( x - 6, y - 2, x, y - 12 ) ; line ( x, y - 12, x + 6, y - 2 ) ; line ( x + 6, y - 2, x + 16, y - 12 ) ;

line ( x + 16, y - 12, x + 10, y - 2 ) ;

29

line ( x + 10, y - 2, x + 16, y ) ; line ( x + 16, y, x + 10, y + 2 ) ; line ( x + 10, y + 2, x + 16, y + 12 ) ;

void draw_gulti(int x,int y) { setcolor(4); setlinestyle(0,0,3); setfillstyle(EMPTY_FILL, getmaxcolor()); pieslice(getmaxx()/4.5, getmaxy()/2.5, 80, 130, 100); } void shoot(int *x, int *y) { char cnt_brick[5]; putimage(*x, *y-BRICK_SIZE, brick, COPY_PUT); delay(3); putimage(*x, *y-BRICK_SIZE, brick, XOR_PUT); *x+=BRICK_SIZE;

30

if (*x>590) { *x=155; flag_brick=0; count_brick--; settextstyle(10,0,1); setusercharsize(30,70,20,70); outtextxy(20,400,"BRICKS LEFT :"); setfillstyle(0,WHITE); bar(200,400,220,425); itoa(count_brick,cnt_brick,10); outtextxy(200,400,cnt_brick); }

} void draw_brick(int x, int y) { setlinestyle(0,0,3); setcolor(4);

31

circle(x-5,y,4); circle(x-5,y,3.9); circle(x-5,y,2.1); circle(x-5,y,2); circle(x-5,y,1.9); circle(x-5,y,1.8); circle(x-5,y,1); }

int testkeys() { union REGS ii, oo ; ii.h.ah = 0 ; int86 ( 22, &ii, &oo ) ; /* if ascii code is not 0 */ if ( oo.h.al ) return ( oo.h.al ) ; /* return ascii code */ else return ( oo.h.ah ) ; /* return scan code */ }

32

void fly(int *x, int *y) { int x1; putimage(*x-4*BIRD_SIZE, *y-5*BIRD_SIZE, bird, COPY_PUT); delay(20); char cnt_bird[5]; putimage(*x-4*BIRD_SIZE, *y-5*BIRD_SIZE, bird, XOR_PUT); *y-=BIRD_SIZE;

if(*y<= 20) { *y=400; x1=450+rand()%150; *x=x1; count_bird--; settextstyle(10,0,1); setusercharsize(30,70,20,70); outtextxy(20,380,"BIRDS LEFT:"); setfillstyle(0,0);

33

bar(200,370,230,400); itoa(count_bird,cnt_bird,10); outtextxy(200,380,cnt_bird); } }

void start() { setbkcolor(0); settextstyle(7,0,2); outtextxy(10,400," PRESS ANY KEY TO CONTINUE. . . . . . . . . . ."); settextstyle(2,0,0); outtextxy(400,350," CREATED BY ANURADHA,ALEMA & LINA "); settextstyle(0,0,8); setcolor(15); setusercharsize(45,95,40,36); outtextxy(80,110,"SHOOTING"); outtextxy(200,230,"BIRD"); setcolor(1); setusercharsize(45,95,40,36);

34

outtextxy(82,112,"SHOOTING"); outtextxy(202,232,"BIRD"); float octave[7] = { 130.81, 146.83, 164.81, 174.61, 196, 220, 246.94 }; while( !kbhit() ) { sound( octave[ random(7) ]*4 ); delay(300); } nosound(); getch(); clearviewport(); setcolor(6); rectangle(1,1,638,478); rectangle(1,4,638,474); rectangle(1,7,638,470); settextstyle(7,0,1); setusercharsize(50,30,50,30); setcolor(11); rectangle(4,80,600,429);

35

rectangle(8,84,604,425); rectangle(12,88,608,421); rectangle(16,92,612,417); setcolor(12); outtextxy(150,10,"INSTRUCTIONS"); setbkcolor(0); settextstyle(0,0,1); setusercharsize(10,70,5,5); setcolor(15); outtextxy(40,107,"1. You can play three levels."); setcolor(12); outtextxy(41,108,"1. You can play three levels."); setcolor(15); outtextxy(40,137,"2. You can move the bow UP and DOWN with the help of arrow keys."); setcolor(14); outtextxy(41,138,"2. You can move the bow UP and DOWN with the help of arrow keys."); setcolor(15); outtextxy(40,167,"3. Press right arrow key to shoot the brick."); setcolor(11);

36

outtextxy(41,168,"3. Press right arrow key to shoot the brick."); setcolor(15); outtextxy(40,197,"4. You score 20 points every time you shoot the bird."); setcolor(6); outtextxy(41,198,"4. You score 20 points every time you shoot the bird."); setcolor(15); outtextxy(40,227,"5. First level has 6 bricks and 10 birds."); setcolor(14); outtextxy(41,228,"5. First level has 6 bricks and 10 birds."); setcolor(15); outtextxy(40,257,"6. You require to score 100 points to enter the second level."); setcolor(12); outtextxy(41,258,"6. You require to score 100 points to enter the second level."); setcolor(15); outtextxy(40,287,"7. Second level has 6 bricks and 8 birds."); setcolor(11); outtextxy(41,288,"7. Second level has 6 bricks and 8 birds."); setcolor(15);

37

outtextxy(40,317,"8. You require to score 200 points to enter the third level."); setcolor(6); outtextxy(41,318,"8. You require to score 200 points to enter the third level."); setcolor(15); outtextxy(40,347,"9. Third level has 6 bricks and 6 birds."); setcolor(12); outtextxy(41,348,"9. Third level has 6 bricks and 6 birds."); settextstyle(7,0,1); setcolor(15); outtextxy(150,430,"PRESS ANY KEY TO CONITINUE");

getch(); setusercharsize(1,1,1,1); settextstyle(0,0,0); setbkcolor(11); clearviewport(); }

38

Findings and Future Plan:

1. The game will have resume option. Then the player can restart the game. 2. There will have user choice option Do you want to play again (Yes/No). 3. The graphical design will be more attractive. 4. The game will have a help option where the player will get a picture of the game. 5. The player can select a mode from EASY, MEDIUM and HARD. 6. The user will have some options like SOUND OFF/ON, HINT OFF/ON and DATA RESET (YES/NO). 7. The game will have an option of speed. Here the user will be provided three options like FAST, MEDIUM and SLOW. 8. There will have a time selection option. The player will have to finish the each level of the game within the selective time otherwise the game will be exit.

39

Conclusion:
Shooting bird is an interesting game of our country. Children of rural areas play this game. In C programming we have made this game .The player is provided a gulti, a numbers of birds and bricks. He has to shoot birds with bricks using gulti. The player could play three levels if he has a perfect score in each level. The player will get much pleasure in this game.

40

Vous aimerez peut-être aussi