Search Projects

Friday, March 27, 2015

2d Car Racing Game OpenGL Projects with Source Code


We all Like Games and most engineers are used to play games on PC not because they want to play but they want other to play it as well. Bike or Car Racing games are one of favorite of every engineers. I might think most of you also like playing those racing games. In my days of college I had my hands on "Needs for Speed". I had played it several times alone and with my friends. In our College we had competition for it, do this happens in you college also? Tell us in your comments.

You all might thinking why I talking about it?

Well Today's projects is about Car Racing Game we are going to develop a 2d Car Racing Game in OpenGL.  We had already seen formula one car racing opengl game project in our previous post. Though compare to that project this is little easy to do as well as has less no of lines of code.  In that project we have different angle of views but here we don't have. Also there track were as in real formula one race with turning while in this, we have simple road. This project has one advantage that there is scoring system in it. You will find this more adorable, enjoyable and sophisticated.


 Different Options for 2d Car Racing Game OpenGL Projects

View the following Code  OpenGL C++ Program executed in Visual Studio. 

void Specialkey(int key, int x, int y)
{
switch(key)
{
case GLUT_KEY_UP: 
for(i = 0; i <4; i++)
             {
              ovehicleY[i] = ovehicleY[i] - 10;  
             }
             movd = movd - 20;
             break;
case GLUT_KEY_DOWN: 
for(i = 0; i <4; i++)
             {
              ovehicleY[i] = ovehicleY[i] + 10;  
             }
             movd = movd + 20;
             break;
case GLUT_KEY_LEFT:vehicleX = 200;
             break;
case GLUT_KEY_RIGHT:vehicleX = 300;
             break;
}

glutPostRedisplay();
}

It is special key function,which allows us to activate the navigation key for the 2d Car Racing Game OpenGL Projects, helps in moving the car left to right and vice-versa along with speed up and down. We don't have the ASCII code for navigation key which can be viewed in Wikipedia. In the glut.h these special function defined for the arrow key or navigation keys.

Color of the car can be easily changeable, set the RGB value and see yourself. Same is true with the screen or road side but road should be either change to black and stip mark in white color to make it real or default as set in the program. ESC key press at any time quit the program.

Most of the objects drawn in this race game opengl program are either rectangle or quadrilateral, mean purely the primitive objects. Code is easy t understand as comments are there. Hope you enjoy this C++ graphics program.

7 comments:

  1. i cant see the area to enter the captcha . So i'm unable to download any file.

    ReplyDelete
  2. I can't download it sir.

    ReplyDelete
  3. void play1(){

    glPushMatrix();

    if(h<0.6){

    glTranslatef(g,h,0);}

    else

    {

    glTranslatef(g,1.2-h,0);

    }

    fish11();

    glPopMatrix();

    }

    sir can u pls explain why are we using g n h parameters in the translate function??

    ReplyDelete
  4. Sumanth Bellam HemanthMay 19, 2015 at 8:01 PM

    Rajeev, Can you please tell me how to increase the speed of fish movement?

    ReplyDelete
  5. zemenfes hailemariamJune 18, 2015 at 11:25 PM

    it says to me:the tower of hanoi (Step by Step)
    warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|

    ReplyDelete
  6. zemenfes hailemariamJune 19, 2015 at 11:42 PM

    can u send me this game that can be played by human????

    ReplyDelete