• Advertisement

Archived

This topic is now archived and is closed to further replies.

2D scrolling road... HELP!

This topic is 5496 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Help me... I''ve made this prog that I want to draw a scrolling road, but ive kinda got stuck. Here is what Ive got... #include <iostream> #include <cmath> #include <CMUgraphics.h> using namespace std; window testWindow(640, 480, 5, 5); struct game { int myCenterLine; int myStopLine; int myStartLine; int myCurrentLine; int myCurrentCenterLine; int myRoadWidth; double myRatioRoad; double myRatioMedian; int myLeftJustify; int myRightJustify; double myTest; int myMedianOn; double myCounter; double myX; game(); void drawRoad(); }; game::game() { testWindow.ChangeTitle("Scolling Road"); testWindow.SetBuffering(true); myCenterLine = 320; myStopLine = 240; myStartLine = 480; myCurrentLine = 480; myCurrentCenterLine=320; myRoadWidth = 50; myRatioRoad = 4; myRatioMedian = 1.75; myLeftJustify = myCurrentCenterLine - myRoadWidth; myRightJustify = myCurrentCenterLine + myRoadWidth; myTest = 0.01; myMedianOn = 0; myCounter = .03; myX = 0; } void game::drawRoad() { testWindow.UpdateBuffer(); while(myCurrentLine >= myStopLine) { //Grass. testWindow.SetPen(0.2, 0.6, 0.2, 1); testWindow.DrawLine(0, myCurrentLine, 640, myCurrentLine); //Edge of Road. testWindow.SetPen(0.5, 0.5, 0.5, 1); testWindow.DrawLine(myCurrentCenterLine-myRoadWidth*myRatioRoad-5, myCurrentLine, myCurrentCenterLine+myRoadWidth*myRatioRoad+5, myCurrentLine); //Main Portion of Road testWindow.SetPen(0.36,0.36, 0.36/*myTest*/, 1); testWindow.DrawLine(myCurrentCenterLine-myRoadWidth*myRatioRoad, myCurrentLine, myCurrentCenterLine+myRoadWidth*myRatioRoad, myCurrentLine); //Median Line if(myMedianOn <= 50) { testWindow.SetPen(1.0, 1.0, 1.0, 1); testWindow.DrawLine(myCurrentCenterLine-myRoadWidth*myRatioMedian+48, myCurrentLine, myCurrentCenterLine+myRoadWidth*myRatioMedian-48, myCurrentLine); } myMedianOn++; if(myMedianOn == 100) myMedianOn = 0; myCurrentCenterLine = 320 - 200*(sin(myX)); myX-=.008; myRatioRoad -= .015; // Make Road smaller as it gets to the top myRatioMedian -= .003; // Make Median smaller as it gets to the top myCurrentLine --; // Up one line myTest -= .001; // Color gradient thingy myCounter += .002; } if(myCurrentLine <= 240) { testWindow.UpdateBuffer(); myCurrentLine = 480; //Reset myRatioRoad = 4; myRatioMedian = 1.75; //Reset myMedianOn = 0; myCounter = .03; myX=0; } } Sorry about the formating - doesn''t fit well in the window. Anyway, my question is - am I doing this the right way? How should I make the horrizon go up and down?

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement