Race around a post-apocalyptic US in our homage to an Ultimate classic. Mark Vanstone has the code
Tranz Am zoomed onto the ZX Spectrum in 1983. Published by Ultimate Play The Game, it saw the player drive around a future version of the United States in search of eight cups. Along the way, the player needed to visit petrol pumps to avoid running out of fuel, and just to make things more difficult, several other cars were racing around, trying to crash into our motor. There were plenty of other obstacles to avoid, too, which made driving at full speed a bad idea.
On the left of the screen, a mini-map of the United States could be found, along with counters showing time elapsed and miles travelled. A speedo, plus fuel and temperature gauges, were also on display so that you could keep an eye on your car’s status. Like most of Ultimate’s games, Tranz Am was well-received in 1983, and was one of the studio’s more arcade-like titles, before it began its cycle of isometric adventures with 1984’s Knight Lore.
Recreate Tranz Am magic
To recreate Tranz Am in Pygame Zero, we need a system that draws a mini-map, which then translates to a much larger map we can drive the car around on. In this case, the car stays in the centre of the play area and the map moves around it, depending on the speed and direction of the vehicle. For our example, we’re going to have the main map 50 times the size of the mini-map, so one pixel on the mini-map will translate to 50 pixels on the main map. To do this, we’ll make an image that will double as our collision and feature map, which will be the same size as the mini-map in the side panel. The main map features dots on the ground which show that it is moving if there are no other features in view, and these dots can be defined on our map image as random noise. We represent our boundary as white pixels, our petrol pumps as green pixels, and our cups as red pixels.
If we control the car’s rotation using the left and right arrow keys, we’ll need a bit of maths to calculate the movement of the map. We need to convert the angle of our car Actor to radians first, and then we can use sin and cos calculations to work out x and y increments based on the car speed (altered by the up and down arrow keys). As the map coordinates move, we redraw the map in a 50×50 pixel grid based on the pixels we read from the collision/features image (noisemap.png).
We need to detect if the car is over the top of a fuel pump, which we can find if the centre pixel we’re reading for our main map is green. If the car’s over a petrol pump, we increase the fuel level; if it’s not, we decrease the fuel level. If the car’s over a cup, we change the colour of the pixel to black and add one to our cups tally. The last thing to check is whether the car’s over a boundary; if it is, the car will turn around 180 degrees.
We need to draw bars on the speedo and fuel and temperature gauges to show their levels and keep a count of time and number of miles travelled. We also need to display the number of cups collected in the left-hand panel. When the temperature goes too high, the speed is reduced until the temperature returns to a suitable level. With all that in the program, you have quite a playable Tranz Am clone. The only things you need to add are a few more obstacles and those pesky computer-controlled cars that try to crash into you. As always, we’ll leave those for you to add in.
Get your copy of Wireframe issue 55
And if you’d like a handy digital version of the magazine, you can also download issue 55 for free in PDF format.