Linux Format

CREATING THE ROAD

-

The road is created with a combinatio­n of two images loaded near the beginning of the script, light_road.png and dark_ road.png, and also two colour strips created with light and dark tones for the grass area outside of the road. The colour of the grass is picked from the light and dark images respective­ly for the grass colour. Let’s look at the code that generates the graphics for the road.

if texture_position

screen.blit(dark_road,(curve_ value,i+HALF_SCREEN_ HEIGHT),(0,i,SCREEN_WIDTH,1))

As can be seen, when rendering the road, an if/else statement is used to determine whether to render a dark part of the road or a light part of the road. The grass outside of the road is rendered at the same time the road is. What is also worth pointing out is that when the strips are drawn, they stretch from one side of the window to the other; the road is overlaid on top of the strips to give the illusion the grass is at each side of the road. To help create the curve effect in the road (left-hand bend), only a part of the image for light and dark road are redrawn with an offset x-position by curve_value . Each image segment which is rendered on the screen is incremente­d slightly more than the last to give the road a left-bend.

Newspapers in English

Newspapers from Australia