• Advertisement
Sign in to follow this  

Code Snippet Help, Please.

Recommended Posts

This code is from a simple 3D race car game.  When the line : if (I == 400)...  is altered the value is for changing a single house near the road in the x direction.  I was wondering if someone could tell me how this code works.  Mostly, what does line  do and what on earth is i about?  Are these lines of pixels?

 

EDIT : The screen dimensions are : 1024 x 768  and the world is larger, mainly horizontally.

 

    std::vector<Line> lines;

    for(int i=0;i<1600;i++)
     {
       Line line;
       line.z = i*segL;

       if (i>300 && i<700) line.curve=0.5;
       if (i>1100) line.curve=-0.7;

       if (i<300 && i%20==0) {line.spriteX=-2.5; line.sprite=object[5];}
       if (i%17==0)          {line.spriteX=2.0; line.sprite=object[6];}
       if (i>300 && i%20==0) {line.spriteX=-0.7; line.sprite=object[4];}
       if (i>800 && i%20==0) {line.spriteX=-1.2; line.sprite=object[1];}
       if (i==400)           {line.spriteX=-1.2; line.sprite=object[7];}

       if (i>750) line.y = sin(i/30.0)*1500;

       lines.push_back(line);
     }

 

 

Also, if there is anything else interesting I'd like to here it :)

Thanks so much,

Josheir

P.S. Is this a beginner's question?

Edited by Josheir

Share this post


Link to post
Share on other sites
Advertisement
5 hours ago, Josheir said:

Mostly, what does line  do and what on earth is i about?  Are these lines of pixels?

What kind of "3D" does this game show? It remembers me of a method of making racing car games that was popular in the era before GPUs. There is this excellent article that explains the technique in great depth. However, the code snippet alone shows little context, so I may be wrong though. 

If that technique is used here, then the shown code snippet creates the track in advance. That "line.curve = ..." stuff could be the offset that causes the visual bending of the road when rendered. And that "line.sprite ..." stuff looks like placing billboards to decorate the track to its left and right.

Share this post


Link to post
Share on other sites

Thank you for the link haegarr, the code is indeed this sort of game.  I'm having a fun time with the code being so succinct.  I don't know when I'll return to looking at the code, although I will probably have more questions. :)

Sincerely,

Josheir

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Advertisement