F1 car racing game written in C using Raylib.
  • C 88.4%
  • C++ 9.5%
  • GLSL 1.3%
  • Python 0.4%
  • Shell 0.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-29 08:32:20 +11:00
assets Initial commit 2026-10-29 08:32:20 +11:00
src Initial commit 2026-10-29 08:32:20 +11:00
tests Initial commit 2026-10-29 08:32:20 +11:00
tools Initial commit 2026-10-29 08:32:20 +11:00
.clang-format Initial commit 2026-10-29 08:32:20 +11:00
.clangd Initial commit 2026-10-29 08:32:20 +11:00
.gitignore Initial commit 2026-10-29 08:32:20 +11:00
build.sh Initial commit 2026-10-29 08:32:20 +11:00
README.md Initial commit 2026-10-29 08:32:20 +11:00
STYLE.md Initial commit 2026-10-29 08:32:20 +11:00

F1 Race

A realistic Formula 1 racing game for Linux x64, written in C23 with raylib. It races at three circuits: Albert Park in Melbourne, Spa-Francorchamps in Belgium and Silverstone in Great Britain.

Building

Requires gcc with C23 support and raylib installed system-wide (tested with raylib 6.2). clang-format is needed for the format targets.

./build.sh            # release build -> build/f1race
./build.sh debug      # with address and undefined-behaviour sanitizers
./build.sh test       # headless tests
./build.sh format     # apply .clang-format
./build.sh check-format  # report files that need formatting
./build.sh clean

The game finds assets/ next to the build/ directory, or in the working directory.

Racing

The title screen leads to the race setup, options, the controls and your records. Use ↑ / ↓ to pick, ← / → to change a setting, Enter to choose and Esc to go back; a gamepad's d-pad, A and B do the same. Race setup sets the circuit, the number of laps (1 to 58), opponents (2 to 11) and their skill (0 to 100; Easy, Medium, Hard or Pro), your grid position (random, or a place from pole to the back), the gearbox (automatic or manual), and traction control and ABS. Changing the circuit loads it at once, with the grid lined up behind the menu. Enter starts the race.

Circuit Length The computer's laps, easiest to hardest
Albert Park, Melbourne 5.30 km about 1:49 to 1:37
Spa-Francorchamps, Belgium 6.99 km about 2:06 to 1:53
Silverstone, Great Britain 5.88 km about 1:51 to 1:39

Albert Park is tight and walled, round the lake in the park, with the city's towers to the north. Spa runs through the Ardennes pine forest: Eau Rouge and Raidillon, the long Kemmel straight, and the long corners at Bruxelles and Pouhon that punish running wide. The tracks are flat, so Eau Rouge is a quick left-right rather than a climb. Silverstone is the old airfield, open and fast, with Copse and the Maggotts and Becketts sweeps.

Each driver has a little more or less skill than the setting, and their form varies from race to race. The grid comes from a qualifying session with some luck in it, so the faster drivers mostly start ahead, but not always. Each driver also has habits for the race: braking a little early or late, a line a little inside or outside, and how keen it is to pass. No two races play out the same.

Five red lights come on a second apart and go out after a random pause. Move before they go out and you're given a 5 s penalty. The race is won by the first car to complete every lap; after that, everyone else finishes as they next cross the line. The results table shows each driver's time or gap to the winner, best lap (the fastest in purple) and penalties.

The computer drivers follow a racing line worked out when the track loads, with a speed for each point of it. Skill sets how much of the tyres' grip they use, how well they hit their braking points and hold the line, and how often they make a mistake; even the best get a corner wrong now and then. A driver running wide at full lock lifts until the front tyres bite again. They pass a slower car on the straights, keep room when following and leave space for a car alongside. Cars can touch, and both are damaged. A car that retires, or is beached and can't drive out, is cleared from the track after a few seconds.

Your best lap, and your best race time for each race length, are kept for each circuit in $XDG_DATA_HOME/f1race/records.txt (or ~/.local/share/f1race/records.txt). The HUD and the results announce a new record. The records page starts at the circuit in the race setup; ← / → show the others.

Controls

Key Action
↑ / ↓ throttle / brake (hold ↓ at a standstill to reverse)
← / → steer
A / S upshift / downshift (manual gearbox)
M toggle automatic / manual gearbox
T toggle traction control
B toggle ABS
C change camera: cockpit, T-cam (on the airbox) or chase
H halo on or off
Esc / P pause: resume, restart, options or quit to the menu
R restart
F12 screenshot (f1race.png)

A gamepad drives with the left stick and the triggers, shifts with the bumpers, changes camera with Y and pauses with Start.

Traction control and ABS start on, unless you switched them off in the race setup. With traction control off, too much throttle spins the rear wheels and can spin the car; with ABS off, a stamp on the brakes locks the wheels and the car won't turn. The tyre diagram next to the speedometer shows each tyre's slip: yellow near the limit, red sliding, blue locked. Under each tyre is its temperature: blue while it's cold, white in its window and red when it overheats. The tyres start the race cold, so they grip a little less for the first part of the lap, and they wear as they slide, so grip fades slowly over a long race; the panel shows the wear of the most worn tyre.

Barriers bite. A hit does damage that grows with the square of how fast the car closed on the barrier, so a scrape costs little and a big head-on hit ends the race. Tyre walls are softer than concrete. The car diagram beside the tyre diagram shows the car's health and each part from green to red. Once a part is a quarter damaged it starts to tell: a bent front wing costs front grip, bent suspension pulls the car to one side, a damaged gearbox loses its top gears and shifts slowly, a damaged engine loses power and smokes, and damaged tyres lose grip and can puncture. If the engine or a suspension fails, or the car's health runs out, the car retires. The results screen offers a restart or the main menu (R restarts at once).

Hold ↓ with the car stopped and it engages reverse (the gear shows R): ↓ then drives backwards and ↑ brakes. Press ↑ at a standstill to go forwards again.

The timing panel shows the current lap with its sector splits, then the last and best laps. A split or lap is purple when it's the best so far and amber when it's slower. Once you've set a lap, the live delta beside the clock shows how far ahead (green) or behind (red) of your best lap you are at this point; the steering wheel's screen shows it too, with the gear, the speed and the rev lights. Going the wrong way flashes a warning, and leaving the track with all four wheels counts a track-limits warning, but only if it gained you time: you rejoin having covered that part of the lap about as quickly as the best drivers would on the racing line. Running wide in a slide or spinning onto the grass costs time, so it isn't counted.

In the cockpit your head moves with the g-forces, the view widens with speed, the road buzzes faintly at speed, and kerbs and run-off shake the view and the wheel. The chase camera swings out as the car slides, drops back as it accelerates and closes in under braking. The mirrors show what's behind. The halo is off by default, since its pillar sits in the middle of the view; H or the options page turns it on. Sliding tyres smoke and leave skid marks, the cars throw up dirt and dust off the grass and gravel, and their planks spark at speed over bumps and under heavy braking.

Options and settings

Options sets the master, engine and effects volumes, the window size (or borderless fullscreen), speeds in km/h or mph, the steering sensitivity (how quickly the keys turn the wheel and how much of the stick's travel reaches full lock), the camera, the halo, and the racing line: an assist, off by default, that draws the line on the track in green, amber where it lifts and red where it brakes. Options can also be reached from the pause menu. Changes take effect at once.

Your choices, including the race setup and any gearbox, assist, camera or halo change made while racing, are kept in settings.txt beside the records, as key = value lines. A line that can't be read is skipped with a warning, and a value out of range is brought into it.

Sound

Every sound is synthesised as the game runs; there are no recordings. Your engine's note is a pulse for each cylinder firing, shaped by the exhaust, so it follows the revs exactly. It hardens under load, bounces off the limiter, cuts on an upshift, blips on a downshift and pops on the overrun, with a turbo whistle over the top. The tyres squeal as they pass the limit of grip and screech when a wheel locks; the brakes, the kerbs, gravel, grass and the wind all have their own sound. Impacts sound three ways by how hard they are, and differ for concrete, tyre walls, armco and other cars; a car sliding along a barrier scrapes.

The other cars are heard from where they are: louder and on the side they're on, duller far away or behind you, and higher as they close in and lower as they pull away (Doppler). Start lights beep, the crowd in the grandstands is louder as you pass them, and it cheers the start and your finish. Pause and the race goes quiet, leaving only the crowd. If there is no audio device the game runs silently.

Development

  • F1RACE_AUTOPILOT=1 lets the computer drive the player's car. A value above 1 overdrives it, though it still keeps off the cars ahead. For a quick retirement, add an almost broken engine: F1RACE_AUTOPILOT=12 F1RACE_DAMAGE=0,0,0,0,0.99,0.
  • F1RACE_DAMAGE=<wing,left,right,gearbox,engine,tyres> starts each run with that much damage (0 to 1) in each zone, to look at its effects.
  • F1RACE_SHOT=<seconds> skips the menu, saves f1race.png after that long and quits. It logs the frame rate at that moment and on average over the race. With F1RACE_MENU=<page> it shows a front-end page instead: title, setup, options, controls, records, pause or results.
  • F1RACE_VIEW=<metres> lifts the camera above and behind the car, to look over the world.
  • F1RACE_VOLUME=<master,engine,effects> sets the volumes, each 0 to 1.
  • F1RACE_LOOK=<camera,halo,racing line> sets the camera (0 cockpit, 1 T-cam, 2 chase) and turns the halo and the racing line on or off (1 or 0).
  • F1RACE_CIRCUIT=<id> races at albert_park, spa or silverstone.
  • F1RACE_LAPS, F1RACE_OPPONENTS and F1RACE_SKILL (0 to 100) set up the race. With F1RACE_SHOT they make a quick unattended race: F1RACE_AUTOPILOT=1 F1RACE_LAPS=1 F1RACE_SHOT=128 runs a lap and saves the results screen. Laps driven by the autopilot don't count as records.
  • While any of these is set, the settings aren't saved, so a test run doesn't change them.

Tracks

A track is a plain-text .trk file under assets/tracks/: centreline points with widths, then hand-written sectors, kerbs, gravel traps, barriers, brake boards, grandstands and the pit lane, and what surrounds the circuit: a lake, a city's skyline, and how many trees there are and of what kind. assets/tracks/albert_park.trk describes its format. The circuits the race setup offers are listed in src/app/circuit.c, each by the name of its track file, which also keys its records.

tools/tumftm_to_trk.py converts a centreline from the TUMFTM racetrack-database into point lines, keeping a file's other lines. --smooth N takes out kinks in the mapped centreline; Spa and Silverstone were converted with --smooth 2.

Where a barrier on the inside of a tight corner would fold back across the track, the track pulls it in until it runs forwards everywhere, and a gap never changes faster than the slope of 45 degrees from one sample to the next.

Credits

Third-party assets and their licences are listed in assets/LICENSES.md.