PYGAME
Classic pseudo-3D racing road effects
With a bag of 10p pieces in hand, Andrew Smith whisks us back to the classic arcade days to recreate pseudo-3D racing games.
OUR EXPERT
Andrew Smith is a software developer @ NHS Digital, has a Bachelors degree in Software Engineering and an MSc in Computer Networks.
C ue the budget wibbly-wobbly ‘going back in time’ special effects, as for this coding tutorial we’re going to look at some the old-school techniques used in some of the classic racing video games such as Road Rash (1991), Outrun (1986) and Pole Position (1982). Designed to work smoothly on low-powered hardware, these are smart visual tricks that create a fake 3D effect.
What is known as pseudo-3D techniques were used to create a simulated 3D racing effect. The games would often be played by a single player or two players against computer opponents. The Pseudo 3D Road project (created by Ray Tomely) that we will be looking at, even though not a full video game, is a selection of examples of pseudo-3D techniques demonstrating ways to generate the 3D effect. You will see that once the project has been downloaded, these programming techniques are located in different folders that each demonstrate a pseudo-3D effect.
Getting started
To get started we will need a few things: Python, PyGame and the Pseudo 3D road project. To install Python, open a terminal window (Ctrl+Alt+T) and type sudo apt-get python3 followed by sudo apt-get install pip3 . Then install the PyGame module by typing pip3 install pygame .
Finally grab a copy of the Pseudo 3D road project from https://raytomely.itch.io/pseudo-3d-roadcollectionby clicking the Download button on the page. Once downloaded, extract the contents of the pseudo_3d_road_collection.rar file into an accessible location on your system.
As an example, the whole project has been put into a folder called PythonProjects which was created before downloading the project. The source code and project can be retrieved from the LXF281 DVD. This tutorial will focus on the source code located in the folder called simple_road. If you’re not already in that folder, type cd simple_road to get into it.
To edit and view the source code you can either use a default text editor installed on your flavour of Linux (Ubuntu for example) or you could use something more specific such as Notepad++, PyCharm or VS Code. The choice is entirely up to you. For this tutorial, we will be using gedit to view and edit the source files. When using this method to view/edit source files, it maybe helpful to open up two console windows where one will be used for editing/viewing source files and the other is a terminal window for executing the PyGame code.