Dora Catch Game Computer Graphics Project in OpenGL Source Code – 18CSL67

 

Dora Catch Game Computer Graphics Project in OpenGL Source Code – 18CSL67

Here you can download the source code of the Dora Catch Game Computer Graphics Project in OpenGL – 18CSL67 for the academic mini-project.

Project Description:

The mini-project, ”Dora Catch”, allows the player to play with the objects. The player is allotted with a basket and with the help of control keys i.e “a |A” for left movement and “d |D” for the right movement, he/she has to move the basket so as to catch the “Dora’s” i.e the falling objects. The player can also make use of the mouse as a controller. Upon catching a Dora, the player gains a point and this is displayed on the scoreboard. The game has three phases, i.e Level 1, Level 2, and Level 3.

Video Demonstration of Dora Catch Game Computer Graphics Mini Project

* Level 1:

At this level, there are three Dora’s which fall at normal speed (Initial speed).

Another Dora called “Buzzy Dora” falls. Upon catching this Buzzy Dora, the player gains reward points.

Upon gaining a total of ten points, the player will switch on to level 2.

If the player misses 10 Dora’s, then the game ends.

*Level 2:

In this level, the complexity of the game increases making the game difficult for the player.

The speed of the Dora’s is comparatively faster in this level.

*Level 3:

This is the final level of the game. In this level, the game becomes even more complex.

The speed of the Dora’s is faster compared to level 2.

Module Description

1. MAIN FUNCTION – In OpenGL, GLUT runs as a console application starting at main. The glutInit() initializes the window system and to enable the single buffered mode glutInitDisplayMode(GLUT_SINGLE) is used.

The size and position of the window is defined using glutInitWindowSize(width,height), glutInitWindowPosition(posX,posY) respectively.

The window is created using glutCreateWindow(“DoraCatch”) and the name of the created window is given in quotes. The following functions are registered to be used in the program :

1. glutReshapeFunc()

2. glutDisplayFunc(display)

3. glutKeyboardFunc()

4. glutTimerFunc()

And finally, glutMainLoop() is used to enter the event processing loop and calls the functions which are registered in the body of the main function.

2. RESHAPE FUNCTION – This Function is called back when the windows are re-sized. It first computes the aspect ratio of the new window then it computes the aspect ratio of the new window and finally it sets the aspect ratio of the clipping area to match the viewport. In this function, the edges are defined and the boundary is set so that the objects can interact within the boundaries.

3. MYDISPLAY FUNCTION – In mydisplay(), four functions have been called. The following is the list of functions :

frontscreen(), instr(), display() and missdisp()

i. frontscreen() – The front screen function displays the information about the project i.e. title of the project, group name, made by, and guided by. It uses a drawstring function to display the information. It is also the beginning phase of the program. Here the player has an option: to start the game press ‘Enter’ which is followed by the instr() window. If the user presses ‘S’ then display() window is called thus allowing the player to interact with the game.

ii. instr() – The instr function displays the instructions of the game which is very helpful to a beginner. This window is displayed when the user presses ‘S’ at the front screen window. It uses a drawstring function to display the string of characters.

iii. display() – The display function registers call back handler for window re-paint. In this function, two functions are being called basket() and disp(). The glClear() API is used to clear the window background and glClearColor() API specifies the RGB and alpha values to clear the color buffers. These APIs are called before calling the functions basket() and disp() and finally glFlush() forces the buffered OpenGL commands to execute.

4. BASKET FUNCTION -This function is used to display the basket. We have used GL_QUADS to draw the basket. The moveright() and moveleft() are used to move the basket to different x positions. The variable xb is used to compute the location of the next refresh whereas yb is kept constant.

5. DISP FUNCTION – In this function star1, star2, star3, scredisp, and missed functions are called. Along with this, we use the following functions:

glPushMatrix(): It pushes the current matrix stack down by one, duplicating the current matrix. That is,  after glPushMatrix call, the matrix on top of the stack is identical to the one below it.

glPopMatrix(): It pops the current matrix stack, replacing the current matrix with the one below it on the stack.

i. STAR1(), STAR2(), and STAR3() – These functions are used to display the stars. We have used a GL_QUADS function to draw the stars. Initially, the color of the stars is set to a specific color using glColor3f() function. s1,s2, and s3 variables are used to decrement the y coordinate of the star1,star2, and star3 respectively which results in the downward movement of the stars.xs1, xs2 and xs3 represent the x coordinates of the star1,star2 and star3 respectively.

* level2() – The level2 function is invoked when the user scores 10 points in level1 with the count of miss less than 10. It is a link between Level 1 and Level 2 where the program asks the user to press ‘l’ to proceed to the next level.

* level3() – The level3 function is invoked when the user scores a total of 20 points in level1 and level2 with the count of miss less than 10. It is a link between Level2 and Level3 where the program asks the user to press  ‘g’ to proceed to the next level.

ii. SCREDISP – This function is used to display the score . The glRasterPos() API is used to set the x and y-axis for the text. The glutBitmapCharacter() API is used to render the character in the named bitmap font. With every click on the ball, the score will be implemented. We have used drawstring() to display the string “SCORE” on the top left corner.

iii. MISSD – This function is used to count the missed catches. If the count of the missis is equal to 10, the game ends.

6. TIMER FUNCTION – The glutTimerFunc() registers a timer callback to be triggered in a specified number of milliseconds. In this glutPostRedisplay is used which posts a paint request to activate display().

7. KEYBOARD FUNCTION – The glutKeyboardFunc() API is used to set the keyboard callback to the current window. Here we have created three cases using a switch statement, the first case is quit which is invoked by pressing the “q|Q” button. The second case is “d|D” which invokes the moveright() function, resulting in the movement of the basket towards the right. And the last case is ‘a’|’A’ which invokes the moveleft() function, resulting in the movement of the basket towards the left.

Flowchart of Dora Catch Game

Dora Catch Game Computer Graphics Project in OpenGL Source Code – 18CSL67

Screenshots of Dora Catch Game

Instruction - Dora Catch Game

Instruction – Dora Catch Game

Level 1 - Dora Catch Game

Level 1 – Dora Catch Game

Level 2 - Dora Catch Game

Level 2 – Dora Catch Game

Level 3 - Dora Catch Game

Level 3 – Dora Catch Game

Subscribe to our YouTube channel for more videos and like the Facebook page for regular updates.

Leave a Comment

Your email address will not be published. Required fields are marked *