Linux Format

ASTEROIDS GAME IN C

-

There are about 2,200 lines of C in four source files and three headers. The code compiles and runs on an x86 Linux or Raspberry Pi. Note there is some Pi-specific code but that is only enabled when running on a Pi system and not called on other Linux boxes.

First get the source code and files from GitHub (https://bit.ly/lxf314astr­o). Create a folder called asteroids and fetch everything from the GitHub asteroids folder. You’ll also need the VS Code ZIP (https://github.com/David-HBolton/Projects/blob/main/vscode.zip) file. Download and unzip the .vscode folder into the asteroids folder. First make sure you have the dev SDL libraries installed. Run these four commands in a terminal: $ sudo apt install libsdl2-dev $ sudo apt install libsdl2-image-dev $ sudo apt install libsdl2-mixer-dev $ sudo apt install libsdl2-ttf-dev

To compile asteroids.c,GCC or Clang will do. There is a supplied tasks.json to simplify things but it is preconfigu­red for Clang 14. If your Clang version is different, edit tasks.json and change the args command to your version: “command”: “/usr/bin/clang-14”, The folders images, masks and sounds must be located in the asteroids folder. In Visual Studio Code, the asteroids folder should be the Work folder you select when you click on the Explorer tab. The .vscode folder should be under the asteroids folder as well.

After compiling, the game is started by double-clicking the compiled asteroids executable or with the command: ./asteroids in a terminal.

The keys are q and w to rotate the ship, Space to fire the gun, with a maximum of 16 bullets on screen at once. The s key puts up a shield but this counts down as long as s is pressed, and j does a hyperspace jump. You can’t jump again for a couple of seconds after.

Newspapers in English

Newspapers from Australia